treat empty list as null

This commit is contained in:
Reinhard Pointner 2017-03-27 18:07:41 +08:00
parent 52ef8e5b5b
commit fb81a895b8
2 changed files with 24 additions and 3 deletions

View File

@ -4,6 +4,7 @@ import static net.filebot.util.ExceptionUtilities.*;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.AbstractMap; import java.util.AbstractMap;
import java.util.Collection;
import java.util.HashSet; import java.util.HashSet;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
@ -42,10 +43,21 @@ public class ExpressionBindings extends AbstractMap<String, Object> implements B
} }
protected boolean isUndefined(Object value) { protected boolean isUndefined(Object value) {
if (value instanceof CharSequence) { if (value == null) {
return ((CharSequence) value).length() <= 0; return true;
} }
return value == null;
// treat empty string as null
if (value instanceof CharSequence && value.toString().isEmpty()) {
return true;
}
// treat empty list as null
if (value instanceof Collection && ((Collection) value).isEmpty()) {
return true;
}
return false;
} }
public Object getBindingBean() { public Object getBindingBean() {

View File

@ -7,6 +7,7 @@ import static net.filebot.util.RegularExpressions.*;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.Collection;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -38,9 +39,17 @@ public class ExpressionFormatFunctions {
return null; return null;
} }
} }
// treat empty string as null
if (object instanceof CharSequence && object.toString().isEmpty()) { if (object instanceof CharSequence && object.toString().isEmpty()) {
return null; return null;
} }
// treat empty list as null
if (object instanceof Collection && ((Collection) object).isEmpty()) {
return null;
}
return object; return object;
} }