From 8b79c595f3db31729e40a89c1bd6729d97f2827e Mon Sep 17 00:00:00 2001 From: Reinhard Pointner Date: Sun, 26 Feb 2017 21:25:11 +0800 Subject: [PATCH] Throw exception and unwind expression if ASO property is undefined --- .../format/AssociativeScriptObject.java | 25 ++++++++----------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/source/net/filebot/format/AssociativeScriptObject.java b/source/net/filebot/format/AssociativeScriptObject.java index 2c836f67..0272482b 100644 --- a/source/net/filebot/format/AssociativeScriptObject.java +++ b/source/net/filebot/format/AssociativeScriptObject.java @@ -5,12 +5,11 @@ import static net.filebot.util.RegularExpressions.*; import java.util.AbstractMap; import java.util.AbstractSet; -import java.util.HashMap; import java.util.Iterator; +import java.util.LinkedHashMap; import java.util.Map; import java.util.Map.Entry; import java.util.Set; -import java.util.TreeSet; import groovy.lang.GroovyObjectSupport; @@ -22,22 +21,20 @@ public class AssociativeScriptObject extends GroovyObjectSupport implements Iter this.properties = new LenientLookup(properties); } - /** - * Get the property with the given name. - * - * @param name - * the property name - * @param start - * the object where the lookup began - */ @Override public Object getProperty(String name) { - return properties.get(name); + Object value = properties.get(name); + + if (value != null) { + return value; + } + + return super.getProperty(name); } @Override public void setProperty(String name, Object value) { - // ignore, object is immutable + throw new UnsupportedOperationException(); } @Override @@ -48,7 +45,7 @@ public class AssociativeScriptObject extends GroovyObjectSupport implements Iter @Override public String toString() { // all the properties in alphabetic order - return new TreeSet(properties.keySet()).toString(); + return properties.keySet().toString(); } /** @@ -57,7 +54,7 @@ public class AssociativeScriptObject extends GroovyObjectSupport implements Iter */ private static class LenientLookup extends AbstractMap { - private final Map> lookup = new HashMap>(); + private final Map> lookup = new LinkedHashMap>(); public LenientLookup(Map source) { // populate lookup map