diff --git a/src/main/config/checkstyle.xml b/src/main/config/checkstyle.xml index efb5738b4..8f367cc6e 100644 --- a/src/main/config/checkstyle.xml +++ b/src/main/config/checkstyle.xml @@ -50,7 +50,7 @@ limitations under the License. - + diff --git a/src/main/java/org/apache/commons/jexl3/JexlArithmetic.java b/src/main/java/org/apache/commons/jexl3/JexlArithmetic.java index 1cd787520..5ed7a4240 100644 --- a/src/main/java/org/apache/commons/jexl3/JexlArithmetic.java +++ b/src/main/java/org/apache/commons/jexl3/JexlArithmetic.java @@ -322,7 +322,7 @@ public interface SetBuilder { * @param extended whether the set is extended or not * @return the array builder */ - public SetBuilder setBuilder(final int size, boolean extended) { + public SetBuilder setBuilder(final int size, final boolean extended) { return new org.apache.commons.jexl3.internal.SetBuilder(size); } @Deprecated @@ -361,7 +361,7 @@ public interface MapBuilder { * @param extended whether the map is extended or not * @return the map builder */ - public MapBuilder mapBuilder(final int size, boolean extended) { + public MapBuilder mapBuilder(final int size, final boolean extended) { return new org.apache.commons.jexl3.internal.MapBuilder(size); } @Deprecated @@ -371,7 +371,7 @@ public MapBuilder mapBuilder(final int size, boolean extended) { public MapBuilder mapBuilder(final int size) { return mapBuilder(size, false); } - + /** * Creates a literal range. *

The default implementation only accepts integers and longs.

@@ -384,8 +384,8 @@ public MapBuilder mapBuilder(final int size) { public Iterable createRange(final Object from, final Object to) throws ArithmeticException { final long lfrom = toLong(from); final long lto = toLong(to); - if ((lfrom >= Integer.MIN_VALUE && lfrom <= Integer.MAX_VALUE) - && (lto >= Integer.MIN_VALUE && lto <= Integer.MAX_VALUE)) { + if (lfrom >= Integer.MIN_VALUE && lfrom <= Integer.MAX_VALUE + && lto >= Integer.MIN_VALUE && lto <= Integer.MAX_VALUE) { return org.apache.commons.jexl3.internal.IntegerRange.create((int) lfrom, (int) lto); } return org.apache.commons.jexl3.internal.LongRange.create(lfrom, lto); @@ -456,7 +456,7 @@ protected boolean toBoolean(final boolean strict, final Object val) { */ public boolean toBoolean(final Object val) { if (val instanceof Boolean) { - return ((Boolean) val); + return (Boolean) val; } if (val instanceof Number) { final double number = toDouble(strict, val); @@ -512,13 +512,13 @@ public int toInteger(final Object val) { return parseInteger((String) val); } if (val instanceof Boolean) { - return ((Boolean) val) ? 1 : 0; + return (Boolean) val ? 1 : 0; } if (val instanceof AtomicBoolean) { return ((AtomicBoolean) val).get() ? 1 : 0; } if (val instanceof Character) { - return ((Character) val); + return (Character) val; } if (val == null) { return controlNullOperand(strict, 0); @@ -563,13 +563,13 @@ public long toLong(final Object val) { return parseLong((String) val); } if (val instanceof Boolean) { - return ((Boolean) val) ? 1L : 0L; + return (Boolean) val ? 1L : 0L; } if (val instanceof AtomicBoolean) { return ((AtomicBoolean) val).get() ? 1L : 0L; } if (val instanceof Character) { - return ((Character) val); + return (Character) val; } if (val == null) { return controlNullOperand(strict, 0L); @@ -620,7 +620,7 @@ public BigInteger toBigInteger(final Object val) { return BigInteger.valueOf(((Number) val).longValue()); } if (val instanceof Boolean) { - return BigInteger.valueOf(((Boolean) val) ? 1L : 0L); + return BigInteger.valueOf((Boolean) val ? 1L : 0L); } if (val instanceof AtomicBoolean) { return BigInteger.valueOf(((AtomicBoolean) val).get() ? 1L : 0L); @@ -629,7 +629,7 @@ public BigInteger toBigInteger(final Object val) { return parseBigInteger((String) val); } if (val instanceof Character) { - final int i = ((Character) val); + final int i = (Character) val; return BigInteger.valueOf(i); } if (val == null) { @@ -668,7 +668,7 @@ public BigDecimal toBigDecimal(final Object val) { return roundBigDecimal((BigDecimal) val); } if (val instanceof Double) { - if (Double.isNaN(((Double) val))) { + if (Double.isNaN((Double) val)) { return BigDecimal.ZERO; } return roundBigDecimal(new BigDecimal(val.toString(), getMathContext())); @@ -677,7 +677,7 @@ public BigDecimal toBigDecimal(final Object val) { return roundBigDecimal(new BigDecimal(val.toString(), getMathContext())); } if (val instanceof Boolean) { - return BigDecimal.valueOf(((Boolean) val) ? 1. : 0.); + return BigDecimal.valueOf((Boolean) val ? 1. : 0.); } if (val instanceof AtomicBoolean) { return BigDecimal.valueOf(((AtomicBoolean) val).get() ? 1L : 0L); @@ -690,7 +690,7 @@ public BigDecimal toBigDecimal(final Object val) { return roundBigDecimal(new BigDecimal(string, getMathContext())); } if (val instanceof Character) { - final int i = ((Character) val); + final int i = (Character) val; return new BigDecimal(i); } if (val == null) { @@ -726,7 +726,7 @@ protected double toDouble(final boolean strict, final Object val) { */ public double toDouble(final Object val) { if (val instanceof Double) { - return ((Double) val); + return (Double) val; } if (val instanceof Number) { //The below construct is used rather than ((Number)val).doubleValue() to ensure @@ -734,7 +734,7 @@ public double toDouble(final Object val) { return Double.parseDouble(String.valueOf(val)); } if (val instanceof Boolean) { - return ((Boolean) val) ? 1. : 0.; + return (Boolean) val ? 1. : 0.; } if (val instanceof AtomicBoolean) { return ((AtomicBoolean) val).get() ? 1. : 0.; @@ -743,7 +743,7 @@ public double toDouble(final Object val) { return parseDouble((String) val); } if (val instanceof Character) { - return ((Character) val); + return (Character) val; } if (val == null) { return controlNullOperand(strict, 0.d); @@ -1186,13 +1186,13 @@ protected Object increment(final Object val, final int incr) { return incr; } if (val instanceof Integer) { - return ((Integer) val) + incr; + return (Integer) val + incr; } if (val instanceof Double) { - return ((Double) val) + incr; + return (Double) val + incr; } if (val instanceof Long) { - return ((Long) val) + incr; + return (Long) val + incr; } if (val instanceof BigDecimal) { final BigDecimal bd = (BigDecimal) val; @@ -1203,13 +1203,13 @@ protected Object increment(final Object val, final int incr) { return bi.add(BigInteger.valueOf(incr)); } if (val instanceof Float) { - return ((Float) val) + incr; + return (Float) val + incr; } if (val instanceof Short) { - return (short) (((Short) val) + incr); + return (short) ((Short) val + incr); } if (val instanceof Byte) { - return (byte) (((Byte) val) + incr); + return (byte) ((Byte) val + incr); } throw new ArithmeticException("Object "+(incr < 0? "decrement":"increment")+":(" + val + ")"); } @@ -1393,9 +1393,9 @@ public Object mod(final Object left, final Object right) { protected static boolean isMultiplyExact(final long x, final long y, final long r) { final long ax = Math.abs(x); final long ay = Math.abs(y); - return !(((ax | ay) >>> (Integer.SIZE - 1) != 0) - && (((y != 0) && (r / y != x)) - || (x == Long.MIN_VALUE && y == -1))); + return !((ax | ay) >>> Integer.SIZE - 1 != 0 + && (y != 0 && r / y != x + || x == Long.MIN_VALUE && y == -1)); } /** @@ -1686,7 +1686,7 @@ public Boolean endsWith(final Object left, final Object right) { return false; } if (left instanceof CharSequence) { - return (toString(left)).endsWith(toString(right)); + return toString(left).endsWith(toString(right)); } return null; } @@ -1708,7 +1708,7 @@ public Boolean startsWith(final Object left, final Object right) { return false; } if (left instanceof CharSequence) { - return (toString(left)).startsWith(toString(right)); + return toString(left).startsWith(toString(right)); } return null; } @@ -1928,11 +1928,11 @@ private static boolean computeCompare321(final JexlArithmetic arithmetic) { Class arithmeticClass = arithmetic.getClass(); while(arithmeticClass != JexlArithmetic.class) { try { - Method cmp = arithmeticClass.getDeclaredMethod("compare", Object.class, Object.class, String.class); + final Method cmp = arithmeticClass.getDeclaredMethod("compare", Object.class, Object.class, String.class); if (cmp.getDeclaringClass() != JexlArithmetic.class) { return true; } - } catch (NoSuchMethodException xany) { + } catch (final NoSuchMethodException xany) { arithmeticClass = arithmeticClass.getSuperclass(); } } @@ -2041,7 +2041,7 @@ public boolean equals(final Object left, final Object right) { * @return the test result */ public boolean lessThan(final Object left, final Object right) { - if ((left == right) || (left == null) || (right == null)) { + if (left == right || left == null || right == null) { return false; } return compare(left, right, JexlOperator.LT) < 0; @@ -2056,7 +2056,7 @@ public boolean lessThan(final Object left, final Object right) { * @return the test result */ public boolean greaterThan(final Object left, final Object right) { - if ((left == right) || left == null || right == null) { + if (left == right || left == null || right == null) { return false; } return compare(left, right, JexlOperator.GT) > 0; diff --git a/src/main/java/org/apache/commons/jexl3/JexlFeatures.java b/src/main/java/org/apache/commons/jexl3/JexlFeatures.java index b7bd6a4b7..8f643c67e 100644 --- a/src/main/java/org/apache/commons/jexl3/JexlFeatures.java +++ b/src/main/java/org/apache/commons/jexl3/JexlFeatures.java @@ -122,23 +122,23 @@ public final class JexlFeatures { * The default features flag mask. */ private static final long DEFAULT_FEATURES = - (1L << LOCAL_VAR) - | (1L << SIDE_EFFECT) - | (1L << SIDE_EFFECT_GLOBAL) - | (1L << ARRAY_REF_EXPR) - | (1L << NEW_INSTANCE) - | (1L << LOOP) - | (1L << LAMBDA) - | (1L << METHOD_CALL) - | (1L << STRUCTURED_LITERAL) - | (1L << PRAGMA) - | (1L << ANNOTATION) - | (1L << SCRIPT) - | (1L << THIN_ARROW) - | (1L << NS_PRAGMA) - | (1L << IMPORT_PRAGMA) - | (1L << COMPARATOR_NAMES) - | (1L << PRAGMA_ANYWHERE); + 1L << LOCAL_VAR + | 1L << SIDE_EFFECT + | 1L << SIDE_EFFECT_GLOBAL + | 1L << ARRAY_REF_EXPR + | 1L << NEW_INSTANCE + | 1L << LOOP + | 1L << LAMBDA + | 1L << METHOD_CALL + | 1L << STRUCTURED_LITERAL + | 1L << PRAGMA + | 1L << ANNOTATION + | 1L << SCRIPT + | 1L << THIN_ARROW + | 1L << NS_PRAGMA + | 1L << IMPORT_PRAGMA + | 1L << COMPARATOR_NAMES + | 1L << PRAGMA_ANYWHERE; /** * Creates an all-features-enabled instance. @@ -162,7 +162,7 @@ public JexlFeatures(final JexlFeatures features) { @Override public int hashCode() { //CSOFF: MagicNumber int hash = 3; - hash = 53 * hash + (int) (this.flags ^ (this.flags >>> 32)); + hash = 53 * hash + (int) (this.flags ^ this.flags >>> 32); hash = 53 * hash + (this.reservedNames != null ? this.reservedNames.hashCode() : 0); return hash; } @@ -252,7 +252,7 @@ public Predicate namespaceTest() { */ private void setFeature(final int feature, final boolean flag) { if (flag) { - flags |= (1L << feature); + flags |= 1L << feature; } else { flags &= ~(1L << feature); } @@ -264,7 +264,7 @@ private void setFeature(final int feature, final boolean flag) { * @return true if on, false if off */ private boolean getFeature(final int feature) { - return (flags & (1L << feature)) != 0L; + return (flags & 1L << feature) != 0L; } /** diff --git a/src/main/java/org/apache/commons/jexl3/JexlOptions.java b/src/main/java/org/apache/commons/jexl3/JexlOptions.java index ac24a672a..83f561041 100644 --- a/src/main/java/org/apache/commons/jexl3/JexlOptions.java +++ b/src/main/java/org/apache/commons/jexl3/JexlOptions.java @@ -85,7 +85,7 @@ public final class JexlOptions { * @return the new flags mask value */ private static int set(final int ordinal, final int mask, final boolean value) { - return value? mask | (1 << ordinal) : mask & ~(1 << ordinal); + return value? mask | 1 << ordinal : mask & ~(1 << ordinal); } /** @@ -146,7 +146,7 @@ public static int parseFlags(final int initial, final String... flags) { for (int f = 0; f < NAMES.length; ++f) { if (NAMES[f].equals(name)) { if (b) { - mask |= (1 << f); + mask |= 1 << f; } else { mask &= ~(1 << f); } @@ -444,7 +444,7 @@ public JexlOptions copy() { if (i > 0) { strb.append(' '); } - strb.append((flags & (1 << i)) != 0? '+':'-'); + strb.append((flags & 1 << i) != 0? '+':'-'); strb.append(NAMES[i]); } return strb.toString(); diff --git a/src/main/java/org/apache/commons/jexl3/internal/ArrayBuilder.java b/src/main/java/org/apache/commons/jexl3/internal/ArrayBuilder.java index 099fb024a..74a535177 100644 --- a/src/main/java/org/apache/commons/jexl3/internal/ArrayBuilder.java +++ b/src/main/java/org/apache/commons/jexl3/internal/ArrayBuilder.java @@ -131,7 +131,7 @@ public Object create(final boolean e) { return list; } // convert untyped array to the common class if not Object.class - if ((commonClass == null) || Object.class.equals(commonClass)) { + if (commonClass == null || Object.class.equals(commonClass)) { return untyped.clone(); } final int size = added; diff --git a/src/main/java/org/apache/commons/jexl3/internal/Closure.java b/src/main/java/org/apache/commons/jexl3/internal/Closure.java index ef70ad7fc..2056b19e0 100644 --- a/src/main/java/org/apache/commons/jexl3/internal/Closure.java +++ b/src/main/java/org/apache/commons/jexl3/internal/Closure.java @@ -51,7 +51,7 @@ protected Closure(final Interpreter theCaller, final ASTJexlLambda lambda) { */ protected Closure(final Script base, final Object[] args) { super(base.jexl, base.source, base.script); - final Frame sf = (base instanceof Closure) ? ((Closure) base).frame : null; + final Frame sf = base instanceof Closure ? ((Closure) base).frame : null; frame = sf == null ? script.createFrame(args) : sf.assign(args); @@ -113,8 +113,8 @@ public String[] getUnboundParameters() { */ void captureSelfIfRecursive(final Frame parentFrame, final int symbol) { if (script instanceof ASTJexlLambda) { - Scope parentScope = parentFrame != null ? parentFrame.getScope() : null; - Scope localScope = frame != null ? frame.getScope() : null; + final Scope parentScope = parentFrame != null ? parentFrame.getScope() : null; + final Scope localScope = frame != null ? frame.getScope() : null; if (parentScope != null && localScope != null && parentScope == localScope.getParent()) { final Integer reg = localScope.getCaptured(symbol); if (reg != null) { diff --git a/src/main/java/org/apache/commons/jexl3/internal/Engine.java b/src/main/java/org/apache/commons/jexl3/internal/Engine.java index 12cfee5d0..4cae6e548 100644 --- a/src/main/java/org/apache/commons/jexl3/internal/Engine.java +++ b/src/main/java/org/apache/commons/jexl3/internal/Engine.java @@ -312,7 +312,7 @@ public void setClassLoader(final ClassLoader loader) { for(final String name : names) { final Object functor = functions.get(name); if (functor instanceof Class) { - final Class fclass = ((Class) functor); + final Class fclass = (Class) functor; try { final Class nclass = loader.loadClass(fclass.getName()); if (nclass != fclass) { @@ -339,7 +339,7 @@ public Charset getCharset() { * @param name the namespoce name * @return the object associated */ - final Object getNamespace(String name) { + final Object getNamespace(final String name) { return functions.get(name); } @@ -446,7 +446,7 @@ protected void processPragmas(final ASTJexlScript script, final JexlContext cont } else if (PRAGMA_IMPORT.equals(key)) { // jexl.import, may use a set final Set is = new LinkedHashSet<>(); - withValueSet(value, (o)->{ + withValueSet(value, o -> { if (o instanceof String) { is.add(o.toString()); } @@ -484,7 +484,7 @@ protected void processPragmas(final ASTJexlScript script, final JexlContext cont * @param value the value or the set * @param consumer the consumer of values */ - private void withValueSet(Object value, Consumer consumer) { + private void withValueSet(final Object value, final Consumer consumer) { final Set values = value instanceof Set ? (Set) value : Collections.singleton(value); @@ -499,7 +499,7 @@ private void withValueSet(Object value, Consumer consumer) { * @param key the key * @param value the value, ie the class */ - private void processPragmaNamespace(Map ns, String key, Object value) { + private void processPragmaNamespace(final Map ns, final String key, final Object value) { if (value instanceof String) { // jexl.namespace.*** final String nsname = key.substring(PRAGMA_JEXLNS.length()); @@ -519,6 +519,7 @@ private void processPragmaNamespace(Map ns, String key, Object v /** * Processes jexl.module.ns pragma. + * *

If the value is empty, the namespace will be cleared which may be useful to debug and force unload * the object bound to the namespace.

* @param ns the namespace map @@ -527,13 +528,14 @@ private void processPragmaNamespace(Map ns, String key, Object v * @param info the expression info * @param context the value-as-expression evaluation context */ - private void processPragmaModule(Map ns, String key, Object value, JexlInfo info, JexlContext context) { + private void processPragmaModule(final Map ns, final String key, final Object value, final JexlInfo info, + final JexlContext context) { // jexl.module.*** final String module = key.substring(PRAGMA_MODULE.length()); if (module.isEmpty()) { logger.warn(module + ": invalid module declaration"); } else { - withValueSet(value, (o)->{ + withValueSet(value, o -> { if (!(o instanceof CharSequence)) { logger.warn(module + ": unable to define module from " + value); } else { @@ -544,9 +546,7 @@ private void processPragmaModule(Map ns, String key, Object valu functor = processor.processModule(this, info, module, moduleSrc); } else { final Object moduleObject = createExpression(info, moduleSrc).evaluate(context); - functor = moduleObject instanceof Script - ? ((Script) moduleObject).execute(context) - : moduleObject; + functor = moduleObject instanceof Script ? ((Script) moduleObject).execute(context) : moduleObject; } if (functor != null) { ns.put(module, functor); @@ -919,7 +919,7 @@ protected void getVariables(final ASTJexlScript script, final JexlNode node, fin if (collecting && child.isConstant()) { // collect all constants or only string and number literals final boolean collect = collector.mode > 1 - || (child instanceof ASTStringLiteral || child instanceof ASTNumberLiteral); + || child instanceof ASTStringLiteral || child instanceof ASTNumberLiteral; if (collect) { final String image = child.toString(); collector.add(image); @@ -996,7 +996,7 @@ protected ASTJexlScript parse(final JexlInfo info, final JexlFeatures parsingf, script = cache.get(source); if (script != null) { final Scope f = script.getScope(); - if ((f == null && scope == null) || (f != null && f.equals(scope))) { + if (f == null && scope == null || f != null && f.equals(scope)) { return script; } } diff --git a/src/main/java/org/apache/commons/jexl3/internal/Engine32.java b/src/main/java/org/apache/commons/jexl3/internal/Engine32.java index 45a1dff9b..8391a2e7f 100644 --- a/src/main/java/org/apache/commons/jexl3/internal/Engine32.java +++ b/src/main/java/org/apache/commons/jexl3/internal/Engine32.java @@ -89,10 +89,10 @@ static Object getVariable(final Interpreter ii, final Frame frame, final Lexical final String name = identifier.getName(); final Object value = ii.context.get(name); if (value == null && !ii.context.has(name)) { - final boolean ignore = (ii.isSafe() + final boolean ignore = ii.isSafe() && (symbol >= 0 - || identifier.jjtGetParent() instanceof ASTAssignment)) - || (identifier.jjtGetParent() instanceof ASTReference); + || identifier.jjtGetParent() instanceof ASTAssignment) + || identifier.jjtGetParent() instanceof ASTReference; if (!ignore) { return ii.unsolvableVariable(identifier, name, true); // undefined } diff --git a/src/main/java/org/apache/commons/jexl3/internal/Frame.java b/src/main/java/org/apache/commons/jexl3/internal/Frame.java index f34ef2a3e..7be128a28 100644 --- a/src/main/java/org/apache/commons/jexl3/internal/Frame.java +++ b/src/main/java/org/apache/commons/jexl3/internal/Frame.java @@ -49,7 +49,7 @@ public final class Frame { * @param closure the owning closure * @return the cleaned-up stack or the stack itself (most of the time) */ - Object[] nocycleStack(Closure closure) { + Object[] nocycleStack(final Closure closure) { Object[] ns = stack; for(int i = 0; i < stack.length; ++i) { if (stack[i] == closure) { diff --git a/src/main/java/org/apache/commons/jexl3/internal/Interpreter.java b/src/main/java/org/apache/commons/jexl3/internal/Interpreter.java index dffae1ea3..f11b50cf8 100644 --- a/src/main/java/org/apache/commons/jexl3/internal/Interpreter.java +++ b/src/main/java/org/apache/commons/jexl3/internal/Interpreter.java @@ -530,7 +530,7 @@ protected Object visit(final ASTIfStatement node, final Object data) { try { Object result = null; // pairs of { conditions , 'then' statement } - for(int ifElse = 0; ifElse < (numChildren - 1); ifElse += 2) { + for(int ifElse = 0; ifElse < numChildren - 1; ifElse += 2) { final JexlNode testNode = node.jjtGetChild(ifElse); final Object condition = testNode.jjtAccept(this, null); if (testPredicate(testNode, condition)) { @@ -1428,7 +1428,7 @@ protected Object executeAssign(final JexlNode node, final JexlOperator assignop, if (assignop == null) { // make the closure accessible to itself, ie capture the currently set variable after frame creation if (right instanceof Closure) { - Closure closure = (Closure) right; + final Closure closure = (Closure) right; // the variable scope must be the parent of the lambdas closure.captureSelfIfRecursive(frame, symbol); } @@ -1485,7 +1485,7 @@ protected Object executeAssign(final JexlNode node, final JexlOperator assignop, final ASTIdentifier firstId = first instanceof ASTIdentifier ? (ASTIdentifier) first : null; - if ((firstId == null) || (firstId.getSymbol() >= 0)) { + if (firstId == null || firstId.getSymbol() >= 0) { // ant remains null, object is null, stop solving antish = false; break main; @@ -1499,7 +1499,7 @@ protected Object executeAssign(final JexlNode node, final JexlOperator assignop, ? (ASTIdentifierAccess) child : null; // remain antish only if unsafe navigation - if ((aid == null) || aid.isSafe() || aid.isExpression()) { + if (aid == null || aid.isSafe() || aid.isExpression()) { antish = false; break main; } @@ -1642,7 +1642,7 @@ private Object visit(final ASTMethodNode node, final Object antish, final Object protected Object visit(final ASTFunctionNode node, final Object data) { final ASTIdentifier functionNode = (ASTIdentifier) node.jjtGetChild(0); final String nsid = functionNode.getNamespace(); - final Object namespace = (nsid != null)? resolveNamespace(nsid, node) : context; + final Object namespace = nsid != null? resolveNamespace(nsid, node) : context; final ASTArguments argNode = (ASTArguments) node.jjtGetChild(1); return call(node, namespace, functionNode, argNode); } @@ -1899,7 +1899,7 @@ protected Object visit(final ASTConstructorNode node, final Object data) { @Override protected Object visit(final ASTJxltLiteral node, final Object data) { - Object cache = node.getExpression(); + final Object cache = node.getExpression(); TemplateEngine.TemplateExpression tp; if (cache instanceof TemplateEngine.TemplateExpression) { tp = (TemplateEngine.TemplateExpression) cache; diff --git a/src/main/java/org/apache/commons/jexl3/internal/InterpreterBase.java b/src/main/java/org/apache/commons/jexl3/internal/InterpreterBase.java index 950bee0f3..e587b1e59 100644 --- a/src/main/java/org/apache/commons/jexl3/internal/InterpreterBase.java +++ b/src/main/java/org/apache/commons/jexl3/internal/InterpreterBase.java @@ -105,7 +105,7 @@ protected InterpreterBase(final Engine engine, final JexlOptions opts, final Jex ); } if (this.context instanceof JexlContext.NamespaceResolver) { - ns = ((JexlContext.NamespaceResolver) context); + ns = (JexlContext.NamespaceResolver) context; } else { ns = JexlEngine.EMPTY_NS; } @@ -358,7 +358,7 @@ protected Object getVariable(final Frame frame, final LexicalScope block, final if (!context.has(name)) { // not defined, ignore in some cases... final boolean ignore = identifier.jjtGetParent() instanceof ASTReference - || (isSafe() && (symbol >= 0 || identifier.jjtGetParent() instanceof ASTAssignment)); + || isSafe() && (symbol >= 0 || identifier.jjtGetParent() instanceof ASTAssignment); if (!ignore) { return undefinedVariable(identifier, name); // undefined } @@ -1014,7 +1014,7 @@ protected Object getAttribute(final Object object, final Object attribute, final + ", property: " + attribute; throw new UnsupportedOperationException(error, xcause); } - final boolean safe = (node instanceof ASTIdentifierAccess) && ((ASTIdentifierAccess) node).isSafe(); + final boolean safe = node instanceof ASTIdentifierAccess && ((ASTIdentifierAccess) node).isSafe(); if (safe) { return null; } diff --git a/src/main/java/org/apache/commons/jexl3/internal/LexicalScope.java b/src/main/java/org/apache/commons/jexl3/internal/LexicalScope.java index ea5bb31c7..e798c51a4 100644 --- a/src/main/java/org/apache/commons/jexl3/internal/LexicalScope.java +++ b/src/main/java/org/apache/commons/jexl3/internal/LexicalScope.java @@ -41,7 +41,7 @@ public class LexicalScope { /** * Bitmask for symbols. */ - protected static final long SYMBOL_MASK = (1L << (BITS_PER_SYMBOL - 1)) - 1; // 3, as 1+2, 2 bits + protected static final long SYMBOL_MASK = (1L << BITS_PER_SYMBOL - 1) - 1; // 3, as 1+2, 2 bits /** * Number of symbols. */ @@ -90,7 +90,7 @@ private BitSet moreBits() { */ private boolean isSet(final int bit) { if (bit < BITS_PER_LONG) { - return (symbols & (1L << bit)) != 0L; + return (symbols & 1L << bit) != 0L; } return moreSymbols != null && moreSymbols.get(bit - BITS_PER_LONG); } @@ -102,10 +102,10 @@ private boolean isSet(final int bit) { */ private boolean set(final int bit) { if (bit < BITS_PER_LONG) { - if ((symbols & (1L << bit)) != 0L) { + if ((symbols & 1L << bit) != 0L) { return false; } - symbols |= (1L << bit); + symbols |= 1L << bit; } else { final int bit64 = bit - BITS_PER_LONG; final BitSet ms = moreBits(); @@ -135,7 +135,7 @@ public boolean hasSymbol(final int symbol) { * @return true if declared as constant, false otherwise */ public boolean isConstant(final int symbol) { - final int bit = (symbol << SYMBOL_SHIFT) | 1; + final int bit = symbol << SYMBOL_SHIFT | 1; return isSet(bit); } @@ -146,7 +146,7 @@ public boolean isConstant(final int symbol) { * @return true if registered, false if symbol was already registered */ public boolean addSymbol(final int symbol) { - final int bit = (symbol << SYMBOL_SHIFT) ; + final int bit = symbol << SYMBOL_SHIFT ; if (set(bit)) { count += 1; return true; @@ -161,11 +161,11 @@ public boolean addSymbol(final int symbol) { * @return true if registered, false if symbol was already registered */ public boolean addConstant(final int symbol) { - final int letb = (symbol << SYMBOL_SHIFT) ; + final int letb = symbol << SYMBOL_SHIFT ; if (!isSet(letb)) { throw new IllegalStateException("const not declared as symbol " + symbol); } - final int bit = (symbol << SYMBOL_SHIFT) | 1; + final int bit = symbol << SYMBOL_SHIFT | 1; return set(bit); } @@ -188,7 +188,7 @@ public final void clearSymbols(final java.util.function.IntConsumer cleanSymbol) // step by bits per symbol int bit = moreSymbols != null ? moreSymbols.nextSetBit(0) : -1; while (bit >= 0) { - final int s = (bit + BITS_PER_LONG) >> SYMBOL_SHIFT; + final int s = bit + BITS_PER_LONG >> SYMBOL_SHIFT; cleanSymbol.accept(s); bit = moreSymbols.nextSetBit(bit + BITS_PER_SYMBOL); } diff --git a/src/main/java/org/apache/commons/jexl3/internal/LongRange.java b/src/main/java/org/apache/commons/jexl3/internal/LongRange.java index ebd9707ca..9c736d086 100644 --- a/src/main/java/org/apache/commons/jexl3/internal/LongRange.java +++ b/src/main/java/org/apache/commons/jexl3/internal/LongRange.java @@ -75,8 +75,8 @@ public long getMax() { public int hashCode() { int hash = getClass().hashCode(); //CSOFF: MagicNumber - hash = 13 * hash + (int) (this.min ^ (this.min >>> 32)); - hash = 13 * hash + (int) (this.max ^ (this.max >>> 32)); + hash = 13 * hash + (int) (this.min ^ this.min >>> 32); + hash = 13 * hash + (int) (this.max ^ this.max >>> 32); //CSON: MagicNumber return hash; } diff --git a/src/main/java/org/apache/commons/jexl3/internal/Scope.java b/src/main/java/org/apache/commons/jexl3/internal/Scope.java index 3d7028a05..dd88ce9a1 100644 --- a/src/main/java/org/apache/commons/jexl3/internal/Scope.java +++ b/src/main/java/org/apache/commons/jexl3/internal/Scope.java @@ -261,7 +261,7 @@ public Integer getCaptured(final int symbol) { * @return the source symbol index or -1 if the symbol is not captured */ public int getCaptureDeclaration(final int symbol) { - Integer declared = capturedVariables != null ? capturedVariables.get(symbol) : null; + final Integer declared = capturedVariables != null ? capturedVariables.get(symbol) : null; return declared != null ? declared.intValue() : -1; } @@ -317,7 +317,7 @@ public String[] getParameters() { */ String[] getParameters(final int bound) { final int unbound = parms - bound; - if ((namedVariables == null) || (unbound <= 0)) { + if (namedVariables == null || unbound <= 0) { return EMPTY_STRS; } final String[] pa = new String[unbound]; @@ -336,7 +336,7 @@ String[] getParameters(final int bound) { * @return the local variable names */ public String[] getLocalVariables() { - if ((namedVariables == null) || (vars <= 0)) { + if (namedVariables == null || vars <= 0) { return EMPTY_STRS; } final List locals = new ArrayList<>(vars); diff --git a/src/main/java/org/apache/commons/jexl3/internal/TemplateEngine.java b/src/main/java/org/apache/commons/jexl3/internal/TemplateEngine.java index 5bd196f0b..b1267a3f5 100644 --- a/src/main/java/org/apache/commons/jexl3/internal/TemplateEngine.java +++ b/src/main/java/org/apache/commons/jexl3/internal/TemplateEngine.java @@ -1082,7 +1082,7 @@ protected int startsWith(final CharSequence sequence, final CharSequence pattern while (s < length && Character.isSpaceChar(sequence.charAt(s))) { s += 1; } - if (s < length && pattern.length() <= (length - s)) { + if (s < length && pattern.length() <= length - s) { final CharSequence subSequence = sequence.subSequence(s, length); if (subSequence.subSequence(0, pattern.length()).equals(pattern)) { return s + pattern.length(); diff --git a/src/main/java/org/apache/commons/jexl3/internal/introspection/AbstractExecutor.java b/src/main/java/org/apache/commons/jexl3/internal/introspection/AbstractExecutor.java index cc0453122..fcb43d81e 100644 --- a/src/main/java/org/apache/commons/jexl3/internal/introspection/AbstractExecutor.java +++ b/src/main/java/org/apache/commons/jexl3/internal/introspection/AbstractExecutor.java @@ -100,7 +100,7 @@ protected AbstractExecutor(final Class theClass, final java.lang.reflect.Meth @Override public boolean equals(final Object obj) { - return this == obj || (obj instanceof AbstractExecutor && equals((AbstractExecutor) obj)); + return this == obj || obj instanceof AbstractExecutor && equals((AbstractExecutor) obj); } @Override @@ -143,7 +143,7 @@ public boolean equals(final AbstractExecutor arg) { * @return boolean Whether the executor is alive. */ public final boolean isAlive() { - return (method != null); + return method != null; } /** diff --git a/src/main/java/org/apache/commons/jexl3/internal/introspection/ArrayIterator.java b/src/main/java/org/apache/commons/jexl3/internal/introspection/ArrayIterator.java index d86d43a27..3cb09e4f8 100644 --- a/src/main/java/org/apache/commons/jexl3/internal/introspection/ArrayIterator.java +++ b/src/main/java/org/apache/commons/jexl3/internal/introspection/ArrayIterator.java @@ -85,7 +85,7 @@ public Object next() { */ @Override public boolean hasNext() { - return (pos < size); + return pos < size; } /** diff --git a/src/main/java/org/apache/commons/jexl3/internal/introspection/DuckGetExecutor.java b/src/main/java/org/apache/commons/jexl3/internal/introspection/DuckGetExecutor.java index f86f6b004..746c185af 100644 --- a/src/main/java/org/apache/commons/jexl3/internal/introspection/DuckGetExecutor.java +++ b/src/main/java/org/apache/commons/jexl3/internal/introspection/DuckGetExecutor.java @@ -74,8 +74,8 @@ public Object tryInvoke(final Object obj, final Object key) { && objectClass.equals(obj.getClass()) // ensure method name matches the property name && method != null - && ((property == null && key == null) - || (property != null && property.equals(key)))) { + && (property == null && key == null + || property != null && property.equals(key))) { try { final Object[] args = {property}; return method.invoke(obj, args); diff --git a/src/main/java/org/apache/commons/jexl3/internal/introspection/DuckSetExecutor.java b/src/main/java/org/apache/commons/jexl3/internal/introspection/DuckSetExecutor.java index dd8de4965..578f4275c 100644 --- a/src/main/java/org/apache/commons/jexl3/internal/introspection/DuckSetExecutor.java +++ b/src/main/java/org/apache/commons/jexl3/internal/introspection/DuckSetExecutor.java @@ -91,8 +91,8 @@ public Object tryInvoke(final Object obj, final Object key, final Object value) if (obj != null && objectClass.equals(obj.getClass()) && method != null - && ((property != null && property.equals(key)) - || (property == null && key == null)) + && (property != null && property.equals(key) + || property == null && key == null) && valueClass.equals(classOf(value))) { try { final Object[] args = {property, value}; diff --git a/src/main/java/org/apache/commons/jexl3/internal/introspection/MapGetExecutor.java b/src/main/java/org/apache/commons/jexl3/internal/introspection/MapGetExecutor.java index c620100f0..6cf0dfc71 100644 --- a/src/main/java/org/apache/commons/jexl3/internal/introspection/MapGetExecutor.java +++ b/src/main/java/org/apache/commons/jexl3/internal/introspection/MapGetExecutor.java @@ -74,8 +74,8 @@ public Object tryInvoke(final Object obj, final Object key) { if (obj != null && method != null && objectClass.equals(obj.getClass()) - && ((property == null && key == null) - || (property != null && key != null && property.getClass().equals(key.getClass())))) { + && (property == null && key == null + || property != null && key != null && property.getClass().equals(key.getClass()))) { @SuppressWarnings("unchecked") // ctor only allows Map instances - see discover() method final Map map = (Map) obj; return map.get(key); diff --git a/src/main/java/org/apache/commons/jexl3/internal/introspection/MapSetExecutor.java b/src/main/java/org/apache/commons/jexl3/internal/introspection/MapSetExecutor.java index 27b80bc71..40bb88afb 100644 --- a/src/main/java/org/apache/commons/jexl3/internal/introspection/MapSetExecutor.java +++ b/src/main/java/org/apache/commons/jexl3/internal/introspection/MapSetExecutor.java @@ -71,7 +71,7 @@ public Object getTargetProperty() { @Override public Object invoke(final Object obj, final Object value) { @SuppressWarnings("unchecked") // ctor only allows Map instances - see discover() method - final Map map = ((Map) obj); + final Map map = (Map) obj; map.put(property, value); return value; } @@ -81,11 +81,11 @@ public Object tryInvoke(final Object obj, final Object key, final Object value) if (obj != null && method != null && objectClass.equals(obj.getClass()) - && ((property == null && key == null) - || (property != null && key != null && property.getClass().equals(key.getClass()))) + && (property == null && key == null + || property != null && key != null && property.getClass().equals(key.getClass())) && valueClass.equals(classOf(value))) { @SuppressWarnings("unchecked") // ctor only allows Map instances - see discover() method - final Map map = ((Map) obj); + final Map map = (Map) obj; map.put(key, value); return value; } diff --git a/src/main/java/org/apache/commons/jexl3/internal/introspection/MethodKey.java b/src/main/java/org/apache/commons/jexl3/internal/introspection/MethodKey.java index 0dcd79030..d30d87269 100644 --- a/src/main/java/org/apache/commons/jexl3/internal/introspection/MethodKey.java +++ b/src/main/java/org/apache/commons/jexl3/internal/introspection/MethodKey.java @@ -77,7 +77,7 @@ public MethodKey(final String aMethod, final Object[] args) { final Object arg = args[p]; // null arguments use void as Void.class as marker final Class parm = arg == null ? Void.class : arg.getClass(); - hash = (HASH * hash) + parm.hashCode(); + hash = HASH * hash + parm.hashCode(); this.params[p] = parm; } } else { @@ -109,7 +109,7 @@ public MethodKey(final String aMethod, final Object[] args) { this.params = new Class[size]; for (int p = 0; p < size; ++p) { final Class parm = primitiveClass(args[p]); - hash = (HASH * hash) + parm.hashCode(); + hash = HASH * hash + parm.hashCode(); this.params[p] = parm; } } else { @@ -544,7 +544,7 @@ AmbiguousException ambiguousException(final Class[] classes, final Iterable[] parmClasses = app.getParameterTypes(); final Class parmClass = parmClasses[c]; - if (Object.class.equals(parmClass) && (objectParmCount++ == 2)) { + if (Object.class.equals(parmClass) && objectParmCount++ == 2) { severe = true; break; } @@ -588,7 +588,7 @@ private static int moreSpecific(final Class[] a, final Class[] c1, final C // ok, move on and compare those of equal lengths for (int i = 0; i < length; ++i) { if (c1[i] != c2[i]) { - final boolean last = (i == ultimate); + final boolean last = i == ultimate; // argument is null, prefer an Object param if (a[i] == Void.class) { if (c1[i] == Object.class && c2[i] != Object.class) { @@ -602,7 +602,7 @@ private static int moreSpecific(final Class[] a, final Class[] c1, final C boolean c1s = isPrimitive(c1[i], last); boolean c2s = isPrimitive(c2[i], last); if (c1s != c2s) { - return (c1s == (a[i] != Void.class)) ? MORE_SPECIFIC : LESS_SPECIFIC; + return c1s == (a[i] != Void.class) ? MORE_SPECIFIC : LESS_SPECIFIC; } // if c2 can be converted to c1 but not the opposite, // c1 is more specific than c2 diff --git a/src/main/java/org/apache/commons/jexl3/internal/introspection/PermissionsParser.java b/src/main/java/org/apache/commons/jexl3/internal/introspection/PermissionsParser.java index d17dfbf57..7341ee15f 100644 --- a/src/main/java/org/apache/commons/jexl3/internal/introspection/PermissionsParser.java +++ b/src/main/java/org/apache/commons/jexl3/internal/introspection/PermissionsParser.java @@ -90,7 +90,8 @@ public Permissions parse(final String... srcs) { * @param srcs the sources * @return the permissions map */ - synchronized Permissions parse(Set wildcards, Map packages, final String... srcs) { + synchronized Permissions parse(final Set wildcards, final Map packages, + final String... srcs) { try { if (srcs == null || srcs.length == 0) { return Permissions.UNRESTRICTED; @@ -322,7 +323,7 @@ private int readClass(final Permissions.NoJexlPackage njpackage, final String ou // parse a class: if (njclass == null) { // we must have read the class ('identifier {'...) - if ((identifier == null) || (c != '{')) { + if (identifier == null || c != '{') { throw new IllegalStateException(unexpected(c, i)); } // if we have a class, it has a name diff --git a/src/main/java/org/apache/commons/jexl3/internal/introspection/PropertySetExecutor.java b/src/main/java/org/apache/commons/jexl3/internal/introspection/PropertySetExecutor.java index addbf7c3e..0eb4ac45f 100644 --- a/src/main/java/org/apache/commons/jexl3/internal/introspection/PropertySetExecutor.java +++ b/src/main/java/org/apache/commons/jexl3/internal/introspection/PropertySetExecutor.java @@ -118,7 +118,7 @@ public Object tryInvoke(final Object o, final Object identifier, final Object va * @return true if arg is an empty array */ private static boolean isEmptyArray(final Object arg) { - return (arg != null && arg.getClass().isArray() && Array.getLength(arg) == 0); + return arg != null && arg.getClass().isArray() && Array.getLength(arg) == 0; } /** diff --git a/src/main/java/org/apache/commons/jexl3/internal/introspection/SandboxUberspect.java b/src/main/java/org/apache/commons/jexl3/internal/introspection/SandboxUberspect.java index 5a9754f1a..3a8e36991 100644 --- a/src/main/java/org/apache/commons/jexl3/internal/introspection/SandboxUberspect.java +++ b/src/main/java/org/apache/commons/jexl3/internal/introspection/SandboxUberspect.java @@ -89,7 +89,7 @@ public JexlMethod getConstructor(final Object ctorHandle, final Object... args) @Override public JexlMethod getMethod(final Object obj, final String method, final Object... args) { if (obj != null && method != null) { - final Class clazz = (obj instanceof Class) ? (Class) obj : obj.getClass(); + final Class clazz = obj instanceof Class ? (Class) obj : obj.getClass(); final String actual = sandbox.execute(clazz, method); if (actual != null && actual != JexlSandbox.NULL) { return uberspect.getMethod(obj, actual, args); diff --git a/src/main/java/org/apache/commons/jexl3/internal/introspection/Uberspect.java b/src/main/java/org/apache/commons/jexl3/internal/introspection/Uberspect.java index 57dc7ad3e..03b84b1fb 100644 --- a/src/main/java/org/apache/commons/jexl3/internal/introspection/Uberspect.java +++ b/src/main/java/org/apache/commons/jexl3/internal/introspection/Uberspect.java @@ -376,7 +376,7 @@ public Iterator getIterator(final Object obj) { return null; } if (obj instanceof Iterator) { - return ((Iterator) obj); + return (Iterator) obj; } if (obj.getClass().isArray()) { return new ArrayIterator(obj); @@ -448,8 +448,8 @@ public JexlArithmetic.Uberspect getArithmetic(final JexlArithmetic arithmetic) { JexlArithmetic.Uberspect jau = null; if (arithmetic != null) { final Class aclass = arithmetic.getClass(); - Set ops = operatorMap.computeIfAbsent(aclass, k -> { - Set newOps = EnumSet.noneOf(JexlOperator.class); + final Set ops = operatorMap.computeIfAbsent(aclass, k -> { + final Set newOps = EnumSet.noneOf(JexlOperator.class); // deal only with derived classes if (!JexlArithmetic.class.equals(aclass)) { for (final JexlOperator op : JexlOperator.values()) { diff --git a/src/main/java/org/apache/commons/jexl3/introspection/JexlPermissions.java b/src/main/java/org/apache/commons/jexl3/introspection/JexlPermissions.java index bf781fe29..276533b35 100644 --- a/src/main/java/org/apache/commons/jexl3/introspection/JexlPermissions.java +++ b/src/main/java/org/apache/commons/jexl3/introspection/JexlPermissions.java @@ -343,37 +343,37 @@ class Delegate implements JexlPermissions { /** The permissions we delegate to. */ protected final JexlPermissions base; - protected Delegate(JexlPermissions delegate) { + protected Delegate(final JexlPermissions delegate) { base = delegate; } @Override - public boolean allow(Package pack) { + public boolean allow(final Package pack) { return base.allow(pack); } @Override - public boolean allow(Class clazz) { + public boolean allow(final Class clazz) { return base.allow(clazz); } @Override - public boolean allow(Constructor ctor) { + public boolean allow(final Constructor ctor) { return base.allow(ctor); } @Override - public boolean allow(Method method) { + public boolean allow(final Method method) { return base.allow(method); } @Override - public boolean allow(Field field) { + public boolean allow(final Field field) { return base.allow(field); } @Override - public JexlPermissions compose(String... src) { + public JexlPermissions compose(final String... src) { return new Delegate(base.compose(src)); } } @@ -392,7 +392,7 @@ class ClassPermissions extends JexlPermissions.Delegate { * Creates permissions based on the RESTRICTED set but allowing an explicit set. * @param allow the set of allowed classes */ - public ClassPermissions(Class... allow) { + public ClassPermissions(final Class... allow) { this(JexlPermissions.RESTRICTED, Arrays.asList(Objects.requireNonNull(allow)) .stream().map(Class::getCanonicalName).collect(Collectors.toList())); @@ -403,32 +403,32 @@ public ClassPermissions(Class... allow) { * @param delegate the base to delegate to * @param allow the list of class canonical names */ - public ClassPermissions(JexlPermissions delegate, Collection allow) { + public ClassPermissions(final JexlPermissions delegate, final Collection allow) { super(Objects.requireNonNull(delegate)); allowedClasses = new HashSet<>(Objects.requireNonNull(allow)); } - private boolean isClassAllowed(Class clazz) { + private boolean isClassAllowed(final Class clazz) { return allowedClasses.contains(clazz.getCanonicalName()); } @Override - public boolean allow(Class clazz) { - return (validate(clazz) && isClassAllowed(clazz)) || super.allow(clazz); + public boolean allow(final Class clazz) { + return validate(clazz) && isClassAllowed(clazz) || super.allow(clazz); } @Override - public boolean allow(Method method) { - return (validate(method) && isClassAllowed(method.getDeclaringClass())) || super.allow(method); + public boolean allow(final Method method) { + return validate(method) && isClassAllowed(method.getDeclaringClass()) || super.allow(method); } @Override - public boolean allow(Constructor constructor) { - return (validate(constructor) && isClassAllowed(constructor.getDeclaringClass())) || super.allow(constructor); + public boolean allow(final Constructor constructor) { + return validate(constructor) && isClassAllowed(constructor.getDeclaringClass()) || super.allow(constructor); } @Override - public JexlPermissions compose(String... src) { + public JexlPermissions compose(final String... src) { return new ClassPermissions(base.compose(src), allowedClasses); } } diff --git a/src/main/java/org/apache/commons/jexl3/parser/ASTArrayAccess.java b/src/main/java/org/apache/commons/jexl3/parser/ASTArrayAccess.java index 8cac2993e..cbcb84e1d 100644 --- a/src/main/java/org/apache/commons/jexl3/parser/ASTArrayAccess.java +++ b/src/main/java/org/apache/commons/jexl3/parser/ASTArrayAccess.java @@ -36,12 +36,12 @@ public ASTArrayAccess(final Parser p, final int id) { super(p, id); } - void setSafe(long s) { + void setSafe(final long s) { this.safe = s; } - public boolean isSafeChild(int c) { - return (safe & (1L << c)) != 0; + public boolean isSafeChild(final int c) { + return (safe & 1L << c) != 0; } @Override diff --git a/src/main/java/org/apache/commons/jexl3/parser/ASTIdentifier.java b/src/main/java/org/apache/commons/jexl3/parser/ASTIdentifier.java index acd85150f..46ca88bc8 100644 --- a/src/main/java/org/apache/commons/jexl3/parser/ASTIdentifier.java +++ b/src/main/java/org/apache/commons/jexl3/parser/ASTIdentifier.java @@ -76,7 +76,7 @@ public int getSymbol() { * @return the new flags mask value */ private static int set(final int ordinal, final int mask, final boolean value) { - return value? mask | (1 << ordinal) : mask & ~(1 << ordinal); + return value? mask | 1 << ordinal : mask & ~(1 << ordinal); } /** diff --git a/src/main/java/org/apache/commons/jexl3/parser/ASTIdentifierAccess.java b/src/main/java/org/apache/commons/jexl3/parser/ASTIdentifierAccess.java index c9a41e4a5..334ad2884 100644 --- a/src/main/java/org/apache/commons/jexl3/parser/ASTIdentifierAccess.java +++ b/src/main/java/org/apache/commons/jexl3/parser/ASTIdentifierAccess.java @@ -88,7 +88,7 @@ else if (c < '0' || c > '9') { return null; } val *= 10; - val += (c - '0'); + val += c - '0'; } return val; } diff --git a/src/main/java/org/apache/commons/jexl3/parser/ASTJxltLiteral.java b/src/main/java/org/apache/commons/jexl3/parser/ASTJxltLiteral.java index 3ba760179..f4a3c8dd6 100644 --- a/src/main/java/org/apache/commons/jexl3/parser/ASTJxltLiteral.java +++ b/src/main/java/org/apache/commons/jexl3/parser/ASTJxltLiteral.java @@ -38,7 +38,7 @@ void setLiteral(final String literal) { this.literal = literal; } - public void setExpression(JxltEngine.Expression e) { + public void setExpression(final JxltEngine.Expression e) { this.jxltExpression = e; } diff --git a/src/main/java/org/apache/commons/jexl3/parser/ExtensibleNode.java b/src/main/java/org/apache/commons/jexl3/parser/ExtensibleNode.java index a9ce4b750..beb340393 100644 --- a/src/main/java/org/apache/commons/jexl3/parser/ExtensibleNode.java +++ b/src/main/java/org/apache/commons/jexl3/parser/ExtensibleNode.java @@ -29,15 +29,15 @@ public class ExtensibleNode extends JexlNode { /** Whether this array/set/map is extended or not. */ private boolean extended = false; - public ExtensibleNode(int id) { + public ExtensibleNode(final int id) { super(id); } - public ExtensibleNode(Parser p, int id) { + public ExtensibleNode(final Parser p, final int id) { super(p, id); } - public void setExtended(boolean e) { + public void setExtended(final boolean e) { this.extended = e; } diff --git a/src/main/java/org/apache/commons/jexl3/parser/FeatureController.java b/src/main/java/org/apache/commons/jexl3/parser/FeatureController.java index 2e0b14e23..73d1c3b12 100644 --- a/src/main/java/org/apache/commons/jexl3/parser/FeatureController.java +++ b/src/main/java/org/apache/commons/jexl3/parser/FeatureController.java @@ -74,8 +74,8 @@ protected Object visitNode(final JexlNode node, final Object data) { */ public void throwFeatureException(final int feature, final JexlNode node) { final JexlInfo dbgInfo = node.jexlInfo(); - Debugger dbg = new Debugger().depth(1); - String msg = dbg.data(node); + final Debugger dbg = new Debugger().depth(1); + final String msg = dbg.data(node); throw new JexlException.Feature(dbgInfo, feature, msg); } diff --git a/src/main/java/org/apache/commons/jexl3/parser/JexlNode.java b/src/main/java/org/apache/commons/jexl3/parser/JexlNode.java index 96be271b8..e52d223b4 100644 --- a/src/main/java/org/apache/commons/jexl3/parser/JexlNode.java +++ b/src/main/java/org/apache/commons/jexl3/parser/JexlNode.java @@ -54,7 +54,7 @@ public JexlNode(final Parser p, final int id) { public void jjtSetFirstToken(final Token t) { // 0xc = 12, 12 bits -> 4096 // 0xfff, 12 bits mask - this.lc = (t.beginLine << 0xc) | (0xfff & t.beginColumn); + this.lc = t.beginLine << 0xc | 0xfff & t.beginColumn; } public void jjtSetLastToken(final Token t) { @@ -145,7 +145,7 @@ protected boolean isConstant(final boolean literal) { if (literal) { for (int n = 0; n < jjtGetNumChildren(); ++n) { final JexlNode child = jjtGetChild(n); - if ((child instanceof ASTReference) || (child instanceof ASTMapEntry)) { + if (child instanceof ASTReference || child instanceof ASTMapEntry) { final boolean is = child.isConstant(true); if (!is) { return false; diff --git a/src/main/java/org/apache/commons/jexl3/parser/JexlParser.java b/src/main/java/org/apache/commons/jexl3/parser/JexlParser.java index 8204d2cdf..ebd67ab5f 100644 --- a/src/main/java/org/apache/commons/jexl3/parser/JexlParser.java +++ b/src/main/java/org/apache/commons/jexl3/parser/JexlParser.java @@ -221,7 +221,7 @@ protected void controlPragmaAnywhere() { * Gets the frame used by this parser. *

* Since local variables create new symbols, it is important to - * regain access after parsing to known which / how-many registers are needed. + * regain access after parsing to known which / how-many registers are needed. *

* @return the named register map */ @@ -697,18 +697,18 @@ protected void jjtreeCloseNodeScope(final JexlNode node) { * @param symbol the symbol * @return true if constant, false otherwise */ - private boolean isConstant(int symbol) { + private boolean isConstant(final int symbol) { if (symbol >= 0) { if (block != null && block.hasSymbol(symbol)) { return block.isConstant(symbol); } Scope blockScope = blockScopes.get(block); int lexical = symbol; - for (LexicalUnit unit : blocks) { - Scope unitScope = blockScopes.get(unit); + for (final LexicalUnit unit : blocks) { + final Scope unitScope = blockScopes.get(unit); // follow through potential capture if (blockScope != unitScope) { - int declared = blockScope.getCaptureDeclaration(lexical); + final int declared = blockScope.getCaptureDeclaration(lexical); if (declared >= 0) { lexical = declared; } diff --git a/src/main/java/org/apache/commons/jexl3/parser/NumberParser.java b/src/main/java/org/apache/commons/jexl3/parser/NumberParser.java index 5a9151437..5bd2a285d 100644 --- a/src/main/java/org/apache/commons/jexl3/parser/NumberParser.java +++ b/src/main/java/org/apache/commons/jexl3/parser/NumberParser.java @@ -126,7 +126,7 @@ NumberParser assignNatural(final boolean negative, final String natural) { // determine the base final int base; if (s.charAt(0) == '0') { - if ((s.length() > 1 && (s.charAt(1) == 'x' || s.charAt(1) == 'X'))) { + if (s.length() > 1 && (s.charAt(1) == 'x' || s.charAt(1) == 'X')) { base = 16; s = s.substring(2); // Trim the 0x off the front } else { diff --git a/src/main/java/org/apache/commons/jexl3/parser/SimpleNode.java b/src/main/java/org/apache/commons/jexl3/parser/SimpleNode.java index beed79a3f..e55201b56 100644 --- a/src/main/java/org/apache/commons/jexl3/parser/SimpleNode.java +++ b/src/main/java/org/apache/commons/jexl3/parser/SimpleNode.java @@ -125,7 +125,7 @@ public JexlNode jjtGetChild(final int i) { */ @Override public int jjtGetNumChildren() { - return (children == null) ? 0 : children.length; + return children == null ? 0 : children.length; } /** Sets this node value. diff --git a/src/main/java/org/apache/commons/jexl3/parser/StringParser.java b/src/main/java/org/apache/commons/jexl3/parser/StringParser.java index 89e2bf9a7..db8be5b8b 100644 --- a/src/main/java/org/apache/commons/jexl3/parser/StringParser.java +++ b/src/main/java/org/apache/commons/jexl3/parser/StringParser.java @@ -70,7 +70,7 @@ private static String buildString(final CharSequence str, final boolean eatsep, final StringBuilder strb = new StringBuilder(str.length()); final char sep = eatsep ? str.charAt(0) : 0; final int end = str.length() - (eatsep ? 1 : 0); - final int begin = (eatsep ? 1 : 0); + final int begin = eatsep ? 1 : 0; read(strb, str, begin, end, sep, esc); return strb.toString(); } @@ -116,7 +116,7 @@ private static int read(final StringBuilder strb, final CharSequence str, final for (; index < end; ++index) { final char c = str.charAt(index); if (escape) { - if (c == 'u' && (index + UCHAR_LEN) < end && readUnicodeChar(strb, str, index + 1) > 0) { + if (c == 'u' && index + UCHAR_LEN < end && readUnicodeChar(strb, str, index + 1) > 0) { index += UCHAR_LEN; } else { // if c is not an escapable character, re-emmit the backslash before it @@ -184,11 +184,11 @@ private static int readUnicodeChar(final StringBuilder strb, final CharSequence for (int offset = 0; offset < UCHAR_LEN; ++offset) { final char c = str.charAt(begin + offset); if (c >= '0' && c <= '9') { - value = (c - '0'); + value = c - '0'; } else if (c >= 'a' && c <= 'h') { - value = (c - 'a' + BASE10); + value = c - 'a' + BASE10; } else if (c >= 'A' && c <= 'H') { - value = (c - 'A' + BASE10); + value = c - 'A' + BASE10; } else { return 0; } diff --git a/src/main/java/org/apache/commons/jexl3/parser/TokenMgrException.java b/src/main/java/org/apache/commons/jexl3/parser/TokenMgrException.java index 36c8514bc..f1cb981a6 100644 --- a/src/main/java/org/apache/commons/jexl3/parser/TokenMgrException.java +++ b/src/main/java/org/apache/commons/jexl3/parser/TokenMgrException.java @@ -84,12 +84,12 @@ public class TokenMgrException extends RuntimeException implements JavaccError { */ @Override public String getMessage() { - return ("Lexical error at line " + return "Lexical error at line " + line + ", column " + column + ". Encountered: " + (eof ? " " - : (StringParser.escapeString(String.valueOf(current), '"')) + " (" + (int) current + "), ") - + "after : " + StringParser.escapeString(after, '"')); + : StringParser.escapeString(String.valueOf(current), '"') + " (" + (int) current + "), ") + + "after : " + StringParser.escapeString(after, '"'); } diff --git a/src/test/java/org/apache/commons/jexl3/AnnotationTest.java b/src/test/java/org/apache/commons/jexl3/AnnotationTest.java index 9bde8c479..6ab3aaf70 100644 --- a/src/test/java/org/apache/commons/jexl3/AnnotationTest.java +++ b/src/test/java/org/apache/commons/jexl3/AnnotationTest.java @@ -110,7 +110,7 @@ public Object processAnnotation(final String name, final Object[] args, final Ca } // transient side effect for silent if ("silent".equals(name)) { - if ((args != null) && (args.length != 0)) { + if (args != null && args.length != 0) { final boolean s = (Boolean) args[0]; final boolean b = options.isSilent(); options.setSilent(s); diff --git a/src/test/java/org/apache/commons/jexl3/Arithmetic360.java b/src/test/java/org/apache/commons/jexl3/Arithmetic360.java index a0028d229..6db71b53f 100644 --- a/src/test/java/org/apache/commons/jexl3/Arithmetic360.java +++ b/src/test/java/org/apache/commons/jexl3/Arithmetic360.java @@ -24,11 +24,11 @@ * An arithmetic that tries to keep argument types for bit-twiddling operators. */ public class Arithmetic360 extends JexlArithmetic { - public Arithmetic360(boolean astrict) { + public Arithmetic360(final boolean astrict) { super(astrict); } - public Arithmetic360(boolean astrict, MathContext bigdContext, int bigdScale) { + public Arithmetic360(final boolean astrict, final MathContext bigdContext, final int bigdScale) { super(astrict, bigdContext, bigdScale); } @@ -44,7 +44,7 @@ public Arithmetic360(boolean astrict, MathContext bigdContext, int bigdScale) { protected Number narrowLong(final Object lhs, final Object rhs, final long result) { if (!(lhs instanceof Long || rhs instanceof Long)) { final int ir = (int) result; - if (result == (long) ir) { + if (result == ir) { return ir; } } @@ -61,7 +61,7 @@ protected Number narrowLong(final Object lhs, final Object rhs, final long resul protected Number narrowLong(final Object operand, final long result) { if (!(operand instanceof Long)) { final int ir = (int) result; - if (result == (long) ir) { + if (result == ir) { return ir; } } @@ -161,7 +161,7 @@ public Object complement(final Object val) { * @return left << right. */ @Override - public Object shiftLeft(Object left, Object right) { + public Object shiftLeft(final Object left, final Object right) { if (left == null && right == null) { return controlNullNullOperands(JexlOperator.SHIFTLEFT); } @@ -185,7 +185,7 @@ public Object shiftLeft(Object left, Object right) { * @return left >> right. */ @Override - public Object shiftRight(Object left, Object right) { + public Object shiftRight(final Object left, final Object right) { if (left == null && right == null) { return controlNullNullOperands(JexlOperator.SHIFTRIGHT); } @@ -209,7 +209,7 @@ public Object shiftRight(Object left, Object right) { * @return left >>> right. */ @Override - public Object shiftRightUnsigned(Object left, Object right) { + public Object shiftRightUnsigned(final Object left, final Object right) { if (left == null && right == null) { return controlNullNullOperands(JexlOperator.SHIFTRIGHTU); } @@ -222,7 +222,7 @@ public Object shiftRightUnsigned(Object left, Object right) { if (l != null) { return l.longValue() >>> r; } - BigInteger bl = toBigInteger(left); + final BigInteger bl = toBigInteger(left); return bl.signum() < 0? bl.negate().shiftRight(r) : bl.shiftRight(r); } diff --git a/src/test/java/org/apache/commons/jexl3/ArithmeticOperatorTest.java b/src/test/java/org/apache/commons/jexl3/ArithmeticOperatorTest.java index 07a291393..395b0b75d 100644 --- a/src/test/java/org/apache/commons/jexl3/ArithmeticOperatorTest.java +++ b/src/test/java/org/apache/commons/jexl3/ArithmeticOperatorTest.java @@ -96,7 +96,7 @@ public void testRegexp() throws Exception { @Test public void test391() throws Exception { // with literals - for(String src : Arrays.asList( + for(final String src : Arrays.asList( "2 =~ [1, 2, 3, 4]", "[2, 3] =~ [1, 2, 3, 4]", "[2, 3,...] =~ [1, 2, 3, 4]", @@ -106,15 +106,15 @@ public void test391() throws Exception { asserter.assertExpression(src, Boolean.TRUE); } // with variables - int[] ic = new int[]{1, 2, 3, 4}; - List iic = new ArrayList<>(); - for(int v : ic) { iic.add(v); } - int[] iv = new int[]{2, 3}; - List iiv = new ArrayList<>(); - for(int v : iv) { iiv.add(v); } - String src = "(x,y) -> x =~ y "; - for(Object v : Arrays.asList(iv, iiv, 2)) { - for(Object c : Arrays.asList(ic, iic)) { + final int[] ic = {1, 2, 3, 4}; + final List iic = new ArrayList<>(); + for(final int v : ic) { iic.add(v); } + final int[] iv = {2, 3}; + final List iiv = new ArrayList<>(); + for(final int v : iv) { iiv.add(v); } + final String src = "(x,y) -> x =~ y "; + for(final Object v : Arrays.asList(iv, iiv, 2)) { + for(final Object c : Arrays.asList(ic, iic)) { asserter.assertExpression(src, Boolean.TRUE, v, c); } } @@ -227,7 +227,11 @@ public boolean contains(final int i) { } public boolean contains(final int[] i) { - for(int ii : i) if (!values.contains(ii)) return false; + for(final int ii : i) { + if (!values.contains(ii)) { + return false; + } + } return true; } @@ -601,15 +605,15 @@ public void testFormatArithmeticJxlt() throws Exception { testSelfAssignOperators("y.add(--x)", 42, 41, 41); } - void testSelfAssignOperators(String text, int x, int y0, int x0) { + void testSelfAssignOperators(final String text, final int x, final int y0, final int x0) { //String text = "y.add(x++)"; - JexlEngine jexl = new JexlBuilder().safe(true).create(); - JexlScript script = jexl.createScript(text); - JexlContext context = new MapContext(); + final JexlEngine jexl = new JexlBuilder().safe(true).create(); + final JexlScript script = jexl.createScript(text); + final JexlContext context = new MapContext(); context.set("x", x); - List y = new ArrayList<>(); + final List y = new ArrayList<>(); context.set("y", y); - Object result = script.execute(context); + final Object result = script.execute(context); Assert.assertEquals("x0", x0, context.get("x")); Assert.assertEquals("y0", y0, y.get(0)); } diff --git a/src/test/java/org/apache/commons/jexl3/ArithmeticTest.java b/src/test/java/org/apache/commons/jexl3/ArithmeticTest.java index d5da596c2..1ede95d30 100644 --- a/src/test/java/org/apache/commons/jexl3/ArithmeticTest.java +++ b/src/test/java/org/apache/commons/jexl3/ArithmeticTest.java @@ -53,7 +53,7 @@ public ArithmeticTest() { super("ArithmeticTest"); asserter = new Asserter(JEXL); jexla = JEXL.getArithmetic(); - JexlOptions options = new JexlOptions(); + final JexlOptions options = new JexlOptions(); options.setStrictArithmetic(false); jexlb = jexla.options(options); } @@ -63,18 +63,18 @@ public ArithmeticTest() { public void setUp() { } - static private void assertNullOperand(java.util.function.Supplier fun) { + static private void assertNullOperand(final java.util.function.Supplier fun) { try { Assert.assertNull(fun.get()); - } catch (JexlArithmetic.NullOperand xany) { + } catch (final JexlArithmetic.NullOperand xany) { Assert.assertNotNull(xany); } } - static private void assertArithmeticException(java.util.function.Supplier fun) { + static private void assertArithmeticException(final java.util.function.Supplier fun) { try { Assert.assertNull(fun.get()); - } catch (ArithmeticException xany) { + } catch (final ArithmeticException xany) { Assert.assertNotNull(xany); } } @@ -156,7 +156,7 @@ public void testIntegerCoercionEdges() { assertArithmeticException(() -> jexla.toInteger(date)); Assert.assertEquals(0, jexla.toInteger(Double.NaN)); Assert.assertEquals(0, jexla.toInteger("")); - Assert.assertEquals((int) 'b', jexla.toInteger('b')); + Assert.assertEquals('b', jexla.toInteger('b')); Assert.assertEquals(1, jexla.toInteger(new AtomicBoolean(true))); Assert.assertEquals(0, jexla.toInteger(new AtomicBoolean(false))); @@ -333,25 +333,25 @@ public void testOverflows() throws Exception { */ @Test public void testUnaryMinus() throws Exception { - asserter.setVariable("aByte", new Byte((byte) 1)); - asserter.setVariable("aShort", new Short((short) 2)); - asserter.setVariable("anInteger", new Integer(3)); - asserter.setVariable("aLong", new Long(4)); - asserter.setVariable("aFloat", new Float(5.5)); - asserter.setVariable("aDouble", new Double(6.6)); + asserter.setVariable("aByte", Byte.valueOf((byte) 1)); + asserter.setVariable("aShort", Short.valueOf((short) 2)); + asserter.setVariable("anInteger", Integer.valueOf(3)); + asserter.setVariable("aLong", Long.valueOf(4)); + asserter.setVariable("aFloat", Float.valueOf((float) 5.5)); + asserter.setVariable("aDouble", Double.valueOf(6.6)); asserter.setVariable("aBigInteger", new BigInteger("7")); asserter.setVariable("aBigDecimal", new BigDecimal("8.8")); // loop to allow checking caching of constant numerals (debug) for(int i = 0 ; i < 2; ++i) { - asserter.assertExpression("-3", new Integer("-3")); - asserter.assertExpression("-3.0", new Double("-3.0")); - asserter.assertExpression("-aByte", new Byte((byte) -1)); - asserter.assertExpression("-aShort", new Short((short) -2)); - asserter.assertExpression("-anInteger", new Integer(-3)); - asserter.assertExpression("-aLong", new Long(-4)); - asserter.assertExpression("-aFloat", new Float(-5.5)); - asserter.assertExpression("-aDouble", new Double(-6.6)); + asserter.assertExpression("-3", Integer.valueOf("-3")); + asserter.assertExpression("-3.0", Double.valueOf("-3.0")); + asserter.assertExpression("-aByte", Byte.valueOf((byte) -1)); + asserter.assertExpression("-aShort", Short.valueOf((short) -2)); + asserter.assertExpression("-anInteger", Integer.valueOf(-3)); + asserter.assertExpression("-aLong", Long.valueOf(-4)); + asserter.assertExpression("-aFloat", Float.valueOf((float) -5.5)); + asserter.assertExpression("-aDouble", Double.valueOf(-6.6)); asserter.assertExpression("-aBigInteger", new BigInteger("-7")); asserter.assertExpression("-aBigDecimal", new BigDecimal("-8.8")); } @@ -362,25 +362,25 @@ public void testUnaryMinus() throws Exception { */ @Test public void testUnaryPlus() throws Exception { - asserter.setVariable("aByte", new Byte((byte) 1)); - asserter.setVariable("aShort", new Short((short) 2)); - asserter.setVariable("anInteger", new Integer(3)); - asserter.setVariable("aLong", new Long(4)); - asserter.setVariable("aFloat", new Float(5.5)); - asserter.setVariable("aDouble", new Double(6.6)); + asserter.setVariable("aByte", Byte.valueOf((byte) 1)); + asserter.setVariable("aShort", Short.valueOf((short) 2)); + asserter.setVariable("anInteger", Integer.valueOf(3)); + asserter.setVariable("aLong", Long.valueOf(4)); + asserter.setVariable("aFloat", Float.valueOf((float) 5.5)); + asserter.setVariable("aDouble", Double.valueOf(6.6)); asserter.setVariable("aBigInteger", new BigInteger("7")); asserter.setVariable("aBigDecimal", new BigDecimal("8.8")); // loop to allow checking caching of constant numerals (debug) for(int i = 0 ; i < 2; ++i) { - asserter.assertExpression("+3", new Integer("3")); - asserter.assertExpression("+3.0", new Double("3.0")); - asserter.assertExpression("+aByte", new Integer(1)); - asserter.assertExpression("+aShort", new Integer(2)); - asserter.assertExpression("+anInteger", new Integer(3)); - asserter.assertExpression("+aLong", new Long(4)); - asserter.assertExpression("+aFloat", new Float(5.5)); - asserter.assertExpression("+aDouble", new Double(6.6)); + asserter.assertExpression("+3", Integer.valueOf("3")); + asserter.assertExpression("+3.0", Double.valueOf("3.0")); + asserter.assertExpression("+aByte", Integer.valueOf(1)); + asserter.assertExpression("+aShort", Integer.valueOf(2)); + asserter.assertExpression("+anInteger", Integer.valueOf(3)); + asserter.assertExpression("+aLong", Long.valueOf(4)); + asserter.assertExpression("+aFloat", Float.valueOf((float) 5.5)); + asserter.assertExpression("+aDouble", Double.valueOf(6.6)); asserter.assertExpression("+aBigInteger", new BigInteger("7")); asserter.assertExpression("+aBigDecimal", new BigDecimal("8.8")); } @@ -388,22 +388,22 @@ public void testUnaryPlus() throws Exception { @Test public void testMinusMinusPrefix() throws Exception { - asserter.setVariable("aByte", new Byte((byte) 2)); - asserter.setVariable("aShort", new Short((short) 3)); - asserter.setVariable("anInteger", new Integer(4)); - asserter.setVariable("aLong", new Long(5)); - asserter.setVariable("aFloat", new Float(6.6)); - asserter.setVariable("aDouble", new Double(7.7)); + asserter.setVariable("aByte", Byte.valueOf((byte) 2)); + asserter.setVariable("aShort", Short.valueOf((short) 3)); + asserter.setVariable("anInteger", Integer.valueOf(4)); + asserter.setVariable("aLong", Long.valueOf(5)); + asserter.setVariable("aFloat", Float.valueOf((float) 6.6)); + asserter.setVariable("aDouble", Double.valueOf(7.7)); asserter.setVariable("aBigInteger", new BigInteger("8")); asserter.setVariable("aBigDecimal", new BigDecimal("9.9")); asserter.setVariable("aString", "forty-two"); - asserter.assertExpression("--aByte", new Byte((byte) 1)); - asserter.assertExpression("--aShort", new Short((short) 2)); - asserter.assertExpression("--anInteger", new Integer(3)); - asserter.assertExpression("--aLong", new Long(4)); - asserter.assertExpression("--aFloat", new Float(5.6)); - asserter.assertExpression("--aDouble", new Double(6.7)); + asserter.assertExpression("--aByte", Byte.valueOf((byte) 1)); + asserter.assertExpression("--aShort", Short.valueOf((short) 2)); + asserter.assertExpression("--anInteger", Integer.valueOf(3)); + asserter.assertExpression("--aLong", Long.valueOf(4)); + asserter.assertExpression("--aFloat", Float.valueOf((float) 5.6)); + asserter.assertExpression("--aDouble", Double.valueOf(6.7)); asserter.assertExpression("--aBigInteger", new BigInteger("7")); asserter.assertExpression("--aBigDecimal", new BigDecimal("8.9")); @@ -412,31 +412,31 @@ public void testMinusMinusPrefix() throws Exception { @Test public void testMinusMinusPostfix() throws Exception { - asserter.setVariable("aByte", new Byte((byte) 2)); - asserter.setVariable("aShort", new Short((short) 3)); - asserter.setVariable("anInteger", new Integer(4)); - asserter.setVariable("aLong", new Long(5)); - asserter.setVariable("aFloat", new Float(6.6)); - asserter.setVariable("aDouble", new Double(7.7)); + asserter.setVariable("aByte", Byte.valueOf((byte) 2)); + asserter.setVariable("aShort", Short.valueOf((short) 3)); + asserter.setVariable("anInteger", Integer.valueOf(4)); + asserter.setVariable("aLong", Long.valueOf(5)); + asserter.setVariable("aFloat", Float.valueOf((float) 6.6)); + asserter.setVariable("aDouble", Double.valueOf(7.7)); asserter.setVariable("aBigInteger", new BigInteger("8")); asserter.setVariable("aBigDecimal", new BigDecimal("9.9")); asserter.setVariable("aString", "forty-two"); - asserter.assertExpression("aByte--",new Byte((byte) 2)); - asserter.assertExpression("aShort--", new Short((short) 3)); - asserter.assertExpression("anInteger--", new Integer(4)); - asserter.assertExpression("aLong--", new Long(5)); - asserter.assertExpression("aFloat--", new Float(6.6)); - asserter.assertExpression("aDouble--", new Double(7.7)); + asserter.assertExpression("aByte--",Byte.valueOf((byte) 2)); + asserter.assertExpression("aShort--", Short.valueOf((short) 3)); + asserter.assertExpression("anInteger--", Integer.valueOf(4)); + asserter.assertExpression("aLong--", Long.valueOf(5)); + asserter.assertExpression("aFloat--", Float.valueOf((float) 6.6)); + asserter.assertExpression("aDouble--", Double.valueOf(7.7)); asserter.assertExpression("aBigInteger--", new BigInteger("8")); asserter.assertExpression("aBigDecimal--", new BigDecimal("9.9")); - asserter.assertExpression("aByte", new Byte((byte) 1)); - asserter.assertExpression("aShort", new Short((short) 2)); - asserter.assertExpression("anInteger", new Integer(3)); - asserter.assertExpression("aLong", new Long(4)); - asserter.assertExpression("aFloat", new Float(5.6)); - asserter.assertExpression("aDouble", new Double(6.7)); + asserter.assertExpression("aByte", Byte.valueOf((byte) 1)); + asserter.assertExpression("aShort", Short.valueOf((short) 2)); + asserter.assertExpression("anInteger", Integer.valueOf(3)); + asserter.assertExpression("aLong", Long.valueOf(4)); + asserter.assertExpression("aFloat", Float.valueOf((float) 5.6)); + asserter.assertExpression("aDouble", Double.valueOf(6.7)); asserter.assertExpression("aBigInteger", new BigInteger("7")); asserter.assertExpression("aBigDecimal", new BigDecimal("8.9")); @@ -445,22 +445,22 @@ public void testMinusMinusPostfix() throws Exception { @Test public void testPlusPlusPrefix() throws Exception { - asserter.setVariable("aByte", new Byte((byte) 0)); - asserter.setVariable("aShort", new Short((short) 1)); - asserter.setVariable("anInteger", new Integer(2)); - asserter.setVariable("aLong", new Long(3)); - asserter.setVariable("aFloat", new Float(4.4)); - asserter.setVariable("aDouble", new Double(5.5)); + asserter.setVariable("aByte", Byte.valueOf((byte) 0)); + asserter.setVariable("aShort", Short.valueOf((short) 1)); + asserter.setVariable("anInteger", Integer.valueOf(2)); + asserter.setVariable("aLong", Long.valueOf(3)); + asserter.setVariable("aFloat", Float.valueOf((float) 4.4)); + asserter.setVariable("aDouble", Double.valueOf(5.5)); asserter.setVariable("aBigInteger", new BigInteger("6")); asserter.setVariable("aBigDecimal", new BigDecimal("7.7")); asserter.setVariable("aString", "forty-two"); - asserter.assertExpression("++aByte", new Byte((byte) 1)); - asserter.assertExpression("++aShort", new Short((short) 2)); - asserter.assertExpression("++anInteger", new Integer(3)); - asserter.assertExpression("++aLong", new Long(4)); - asserter.assertExpression("++aFloat", new Float(5.4)); - asserter.assertExpression("++aDouble", new Double(6.5)); + asserter.assertExpression("++aByte", Byte.valueOf((byte) 1)); + asserter.assertExpression("++aShort", Short.valueOf((short) 2)); + asserter.assertExpression("++anInteger", Integer.valueOf(3)); + asserter.assertExpression("++aLong", Long.valueOf(4)); + asserter.assertExpression("++aFloat", Float.valueOf((float) 5.4)); + asserter.assertExpression("++aDouble", Double.valueOf(6.5)); asserter.assertExpression("++aBigInteger", new BigInteger("7")); asserter.assertExpression("++aBigDecimal", new BigDecimal("8.7")); @@ -469,31 +469,31 @@ public void testPlusPlusPrefix() throws Exception { @Test public void testPlusPlusPostfix() throws Exception { - asserter.setVariable("aByte", new Byte((byte) 0)); - asserter.setVariable("aShort", new Short((short) 1)); - asserter.setVariable("anInteger", new Integer(2)); - asserter.setVariable("aLong", new Long(3)); - asserter.setVariable("aFloat", new Float(4.4)); - asserter.setVariable("aDouble", new Double(5.5)); + asserter.setVariable("aByte", Byte.valueOf((byte) 0)); + asserter.setVariable("aShort", Short.valueOf((short) 1)); + asserter.setVariable("anInteger", Integer.valueOf(2)); + asserter.setVariable("aLong", Long.valueOf(3)); + asserter.setVariable("aFloat", Float.valueOf((float) 4.4)); + asserter.setVariable("aDouble", Double.valueOf(5.5)); asserter.setVariable("aBigInteger", new BigInteger("6")); asserter.setVariable("aBigDecimal", new BigDecimal("7.7")); asserter.setVariable("aString", "forty-two"); - asserter.assertExpression("aByte++", new Byte((byte) 0)); - asserter.assertExpression("aShort++", new Short((short) 1)); - asserter.assertExpression("anInteger++", new Integer(2)); - asserter.assertExpression("aLong++", new Long(3)); - asserter.assertExpression("aFloat++", new Float(4.4)); - asserter.assertExpression("aDouble++", new Double(5.5)); + asserter.assertExpression("aByte++", Byte.valueOf((byte) 0)); + asserter.assertExpression("aShort++", Short.valueOf((short) 1)); + asserter.assertExpression("anInteger++", Integer.valueOf(2)); + asserter.assertExpression("aLong++", Long.valueOf(3)); + asserter.assertExpression("aFloat++", Float.valueOf((float) 4.4)); + asserter.assertExpression("aDouble++", Double.valueOf(5.5)); asserter.assertExpression("aBigInteger++", new BigInteger("6")); asserter.assertExpression("aBigDecimal++", new BigDecimal("7.7")); - asserter.assertExpression("aByte", new Byte((byte) 1)); - asserter.assertExpression("aShort", new Short((short) 2)); - asserter.assertExpression("anInteger", new Integer(3)); - asserter.assertExpression("aLong", new Long(4)); - asserter.assertExpression("aFloat", new Float(5.4)); - asserter.assertExpression("aDouble", new Double(6.5)); + asserter.assertExpression("aByte", Byte.valueOf((byte) 1)); + asserter.assertExpression("aShort", Short.valueOf((short) 2)); + asserter.assertExpression("anInteger", Integer.valueOf(3)); + asserter.assertExpression("aLong", Long.valueOf(4)); + asserter.assertExpression("aFloat", Float.valueOf((float) 5.4)); + asserter.assertExpression("aDouble", Double.valueOf(6.5)); asserter.assertExpression("aBigInteger", new BigInteger("7")); asserter.assertExpression("aBigDecimal", new BigDecimal("8.7")); @@ -502,7 +502,7 @@ public void testPlusPlusPostfix() throws Exception { @Test public void testNarrowBig() throws Exception { - List ls = Arrays.asList("zero", "one", "two"); + final List ls = Arrays.asList("zero", "one", "two"); asserter.setVariable("list",ls); asserter.setVariable("aBigDecimal", new BigDecimal("1")); asserter.setVariable("aBigInteger", new BigDecimal("1")); @@ -533,67 +533,67 @@ public void testCalculations() throws Exception { * test new null coersion */ asserter.setVariable("imanull", null); - asserter.assertExpression("imanull + 2", new Integer(2)); - asserter.assertExpression("imanull + imanull", new Integer(0)); - asserter.setVariable("foo", new Integer(2)); + asserter.assertExpression("imanull + 2", Integer.valueOf(2)); + asserter.assertExpression("imanull + imanull", Integer.valueOf(0)); + asserter.setVariable("foo", Integer.valueOf(2)); - asserter.assertExpression("foo + 2", new Integer(4)); - asserter.assertExpression("3 + 3", new Integer(6)); - asserter.assertExpression("3 + 3 + foo", new Integer(8)); - asserter.assertExpression("3 * 3", new Integer(9)); - asserter.assertExpression("3 * 3 + foo", new Integer(11)); - asserter.assertExpression("3 * 3 - foo", new Integer(7)); + asserter.assertExpression("foo + 2", Integer.valueOf(4)); + asserter.assertExpression("3 + 3", Integer.valueOf(6)); + asserter.assertExpression("3 + 3 + foo", Integer.valueOf(8)); + asserter.assertExpression("3 * 3", Integer.valueOf(9)); + asserter.assertExpression("3 * 3 + foo", Integer.valueOf(11)); + asserter.assertExpression("3 * 3 - foo", Integer.valueOf(7)); /* * test parenthesized exprs */ - asserter.assertExpression("(4 + 3) * 6", new Integer(42)); - asserter.assertExpression("(8 - 2) * 7", new Integer(42)); + asserter.assertExpression("(4 + 3) * 6", Integer.valueOf(42)); + asserter.assertExpression("(8 - 2) * 7", Integer.valueOf(42)); /* * test some floaty stuff */ - asserter.assertExpression("3 * \"3.0\"", new Double(9)); - asserter.assertExpression("3 * 3.0", new Double(9)); + asserter.assertExpression("3 * \"3.0\"", Double.valueOf(9)); + asserter.assertExpression("3 * 3.0", Double.valueOf(9)); /* * test / and % */ asserter.setStrict(false, false); - asserter.assertExpression("6 / 3", new Integer(6 / 3)); - asserter.assertExpression("6.4 / 3", new Double(6.4 / 3)); - asserter.assertExpression("0 / 3", new Integer(0 / 3)); - asserter.assertExpression("3 / 0", new Double(0)); - asserter.assertExpression("4 % 3", new Integer(1)); - asserter.assertExpression("4.8 % 3", new Double(4.8 % 3)); + asserter.assertExpression("6 / 3", Integer.valueOf(6 / 3)); + asserter.assertExpression("6.4 / 3", Double.valueOf(6.4 / 3)); + asserter.assertExpression("0 / 3", Integer.valueOf(0 / 3)); + asserter.assertExpression("3 / 0", Double.valueOf(0)); + asserter.assertExpression("4 % 3", Integer.valueOf(1)); + asserter.assertExpression("4.8 % 3", Double.valueOf(4.8 % 3)); } @Test public void testCoercions() throws Exception { - asserter.assertExpression("1", new Integer(1)); // numerics default to Integer - asserter.assertExpression("5L", new Long(5)); + asserter.assertExpression("1", Integer.valueOf(1)); // numerics default to Integer + asserter.assertExpression("5L", Long.valueOf(5)); - asserter.setVariable("I2", new Integer(2)); - asserter.setVariable("L2", new Long(2)); - asserter.setVariable("L3", new Long(3)); + asserter.setVariable("I2", Integer.valueOf(2)); + asserter.setVariable("L2", Long.valueOf(2)); + asserter.setVariable("L3", Long.valueOf(3)); asserter.setVariable("B10", BigInteger.TEN); // Integer & Integer => Integer - asserter.assertExpression("I2 + 2", new Integer(4)); - asserter.assertExpression("I2 * 2", new Integer(4)); - asserter.assertExpression("I2 - 2", new Integer(0)); - asserter.assertExpression("I2 / 2", new Integer(1)); + asserter.assertExpression("I2 + 2", Integer.valueOf(4)); + asserter.assertExpression("I2 * 2", Integer.valueOf(4)); + asserter.assertExpression("I2 - 2", Integer.valueOf(0)); + asserter.assertExpression("I2 / 2", Integer.valueOf(1)); // Integer & Long => Long - asserter.assertExpression("I2 * L2", new Long(4)); - asserter.assertExpression("I2 / L2", new Long(1)); + asserter.assertExpression("I2 * L2", Long.valueOf(4)); + asserter.assertExpression("I2 / L2", Long.valueOf(1)); // Long & Long => Long - asserter.assertExpression("L2 + 3", new Long(5)); - asserter.assertExpression("L2 + L3", new Long(5)); - asserter.assertExpression("L2 / L2", new Long(1)); - asserter.assertExpression("L2 / 2", new Long(1)); + asserter.assertExpression("L2 + 3", Long.valueOf(5)); + asserter.assertExpression("L2 + L3", Long.valueOf(5)); + asserter.assertExpression("L2 / L2", Long.valueOf(1)); + asserter.assertExpression("L2 / 2", Long.valueOf(1)); // BigInteger asserter.assertExpression("B10 / 10", BigInteger.ONE); @@ -706,21 +706,21 @@ public void testDivideByZero() throws Exception { final JexlEvalContext context = new JexlEvalContext(vars); final JexlOptions options = context.getEngineOptions(); options.setStrictArithmetic(true); - vars.put("aByte", new Byte((byte) 1)); - vars.put("aShort", new Short((short) 2)); - vars.put("aInteger", new Integer(3)); - vars.put("aLong", new Long(4)); - vars.put("aFloat", new Float(5.5)); - vars.put("aDouble", new Double(6.6)); + vars.put("aByte", Byte.valueOf((byte) 1)); + vars.put("aShort", Short.valueOf((short) 2)); + vars.put("aInteger", Integer.valueOf(3)); + vars.put("aLong", Long.valueOf(4)); + vars.put("aFloat", Float.valueOf((float) 5.5)); + vars.put("aDouble", Double.valueOf(6.6)); vars.put("aBigInteger", new BigInteger("7")); vars.put("aBigDecimal", new BigDecimal("8.8")); - vars.put("zByte", new Byte((byte) 0)); - vars.put("zShort", new Short((short) 0)); - vars.put("zInteger", new Integer(0)); - vars.put("zLong", new Long(0)); - vars.put("zFloat", new Float(0)); - vars.put("zDouble", new Double(0)); + vars.put("zByte", Byte.valueOf((byte) 0)); + vars.put("zShort", Short.valueOf((short) 0)); + vars.put("zInteger", Integer.valueOf(0)); + vars.put("zLong", Long.valueOf(0)); + vars.put("zFloat", Float.valueOf(0)); + vars.put("zDouble", Double.valueOf(0)); vars.put("zBigInteger", new BigInteger("0")); vars.put("zBigDecimal", new BigDecimal("0")); @@ -922,13 +922,13 @@ public void testAddWithStringsStrict() { @Test public void testNullArgs() { - JexlEngine jexl = new JexlBuilder().arithmetic(new JexlArithmetic(true) { - @Override public boolean isStrict(JexlOperator op) { + final JexlEngine jexl = new JexlBuilder().arithmetic(new JexlArithmetic(true) { + @Override public boolean isStrict(final JexlOperator op) { return JexlOperator.ADD == op? false: super.isStrict(op); } }).create(); - JexlScript script = jexl.createScript("'1.2' + x ", "x"); - Object result = script.execute(null); + final JexlScript script = jexl.createScript("'1.2' + x ", "x"); + final Object result = script.execute(null); Assert.assertEquals("1.2", result); } @@ -1475,7 +1475,7 @@ public Object divide(final Object left, final Object right) { if (isFloatingPointNumber(left) || isFloatingPointNumber(right)) { final double l = toDouble(left); final double r = toDouble(right); - return new Double(l / r); + return Double.valueOf(l / r); } // otherwise treat as integers final BigInteger l = toBigInteger(left); @@ -1506,7 +1506,7 @@ public Object mod(final Object left, final Object right) { if (isFloatingPointNumber(left) || isFloatingPointNumber(right)) { final double l = toDouble(left); final double r = toDouble(right); - return new Double(l % r); + return Double.valueOf(l % r); } // otherwise treat as integers final BigInteger l = toBigInteger(left); @@ -1653,7 +1653,7 @@ public void testXmlArithmetic() throws Exception { info = (Attr) nnm.getNamedItem("info"); Assert.assertEquals(y, r); Assert.assertEquals(y, info.getValue()); - } catch (JexlException.Property xprop) { + } catch (final JexlException.Property xprop) { // test fails in java > 11 because modules, etc; need investigation Assert.assertTrue(xprop.getMessage().contains("info")); Assert.assertTrue(getJavaVersion() > 11); @@ -1846,10 +1846,10 @@ public void testAtomicBoolean() { final AtomicBoolean ab = new AtomicBoolean(false); Object o; o = e.execute(jc, ab); - Assert.assertEquals("Result is not 2", new Integer(2), o); + Assert.assertEquals("Result is not 2", Integer.valueOf(2), o); ab.set(true); o = e.execute(jc, ab); - Assert.assertEquals("Result is not 1", new Integer(1), o); + Assert.assertEquals("Result is not 1", Integer.valueOf(1), o); // in a binary logical op e = JEXL.createScript("x && y", "x", "y"); ab.set(true); diff --git a/src/test/java/org/apache/commons/jexl3/ArrayAccessTest.java b/src/test/java/org/apache/commons/jexl3/ArrayAccessTest.java index a91af3e65..16d9970c1 100644 --- a/src/test/java/org/apache/commons/jexl3/ArrayAccessTest.java +++ b/src/test/java/org/apache/commons/jexl3/ArrayAccessTest.java @@ -40,11 +40,11 @@ public class ArrayAccessTest extends JexlTestCase { // Needs to be accessible by Foo.class static final String[] GET_METHOD_ARRAY = - new String[] { "One", "Two", "Three" }; + { "One", "Two", "Three" }; // Needs to be accessible by Foo.class static final String[][] GET_METHOD_ARRAY2 = - new String[][] { {"One", "Two", "Three"},{"Four", "Five", "Six"} }; + { {"One", "Two", "Three"},{"Four", "Five", "Six"} }; public ArrayAccessTest() { super("ArrayAccessTest"); @@ -67,16 +67,16 @@ public void testArrayAccess() throws Exception { */ final List l = new ArrayList<>(); - l.add(new Integer(1)); - l.add(new Integer(2)); - l.add(new Integer(3)); + l.add(Integer.valueOf(1)); + l.add(Integer.valueOf(2)); + l.add(Integer.valueOf(3)); asserter.setVariable("list", l); - asserter.assertExpression("list[1]", new Integer(2)); - asserter.assertExpression("list[1+1]", new Integer(3)); - asserter.setVariable("loc", new Integer(1)); - asserter.assertExpression("list[loc+1]", new Integer(3)); + asserter.assertExpression("list[1]", Integer.valueOf(2)); + asserter.assertExpression("list[1+1]", Integer.valueOf(3)); + asserter.setVariable("loc", Integer.valueOf(1)); + asserter.assertExpression("list[loc+1]", Integer.valueOf(3)); /* * test array access @@ -206,7 +206,7 @@ public void testArrayProperty() throws Exception { // This is JEXL-26 @Test public void testArrayAndDottedConflict() throws Exception { - final Object[] objects = new Object[] {"an", "array", new Long(0)}; + final Object[] objects = {"an", "array", Long.valueOf(0)}; asserter.setStrict(false); asserter.setSilent(true); asserter.setVariable("objects", objects); @@ -234,11 +234,11 @@ public void testArrayIdentifierParsing() throws Exception { @Test public void testArrayMethods() throws Exception { - final Object[] objects = new Object[] {"an", "array", new Long(0)}; + final Object[] objects = {"an", "array", Long.valueOf(0)}; asserter.setVariable("objects", objects); asserter.assertExpression("objects.get(1)", "array"); - asserter.assertExpression("objects.size()", new Integer(3)); + asserter.assertExpression("objects.size()", Integer.valueOf(3)); // setting an index returns the old value asserter.assertExpression("objects.set(1, 'dion')", "array"); asserter.assertExpression("objects[1]", "dion"); diff --git a/src/test/java/org/apache/commons/jexl3/ArrayLiteralTest.java b/src/test/java/org/apache/commons/jexl3/ArrayLiteralTest.java index 43a001f6a..217d9f7b0 100644 --- a/src/test/java/org/apache/commons/jexl3/ArrayLiteralTest.java +++ b/src/test/java/org/apache/commons/jexl3/ArrayLiteralTest.java @@ -43,15 +43,15 @@ public void testEmptyArrayLiteral() throws Exception { Assert.assertTrue(o instanceof List); Assert.assertEquals(0, ((List) o).size()); try { - Object ff = JEXL.createExpression("[ , ]"); + final Object ff = JEXL.createExpression("[ , ]"); Assert.fail(ff.toString()); - } catch(JexlException.Parsing parsing) { + } catch(final JexlException.Parsing parsing) { Assert.assertNotNull(parsing); } try { - Object ff = JEXL.createExpression("[ ... , ]"); + final Object ff = JEXL.createExpression("[ ... , ]"); Assert.fail(ff.toString()); - } catch(JexlException.Parsing parsing) { + } catch(final JexlException.Parsing parsing) { Assert.assertNotNull(parsing); } } @@ -59,8 +59,8 @@ public void testEmptyArrayLiteral() throws Exception { @Test public void testLiteralWithStrings() throws Exception { final Object[] check = {"foo", "bar"}; - List sources = Arrays.asList("[ 'foo' , 'bar' ]", "[ 'foo' , 'bar', ]"); - for(String src : sources) { + final List sources = Arrays.asList("[ 'foo' , 'bar' ]", "[ 'foo' , 'bar', ]"); + for(final String src : sources) { final JexlExpression e = JEXL.createExpression(src); final Object o = e.evaluate(null); Assert.assertArrayEquals(check, (Object[]) o); @@ -79,7 +79,7 @@ public void testLiteralWithElipsis() throws Exception { try { JEXL.createExpression("[ 'foo' , 'bar', ... , ]"); Assert.fail("syntax"); - } catch(JexlException.Parsing parsing) { + } catch(final JexlException.Parsing parsing) { Assert.assertNotNull(parsing); } } @@ -87,8 +87,8 @@ public void testLiteralWithElipsis() throws Exception { @Test public void testLiteralWithOneEntry() throws Exception { final Object[] check = {"foo"}; - List sources = Arrays.asList("[ 'foo']", "[ 'foo' , ]"); - for(String src : sources) { + final List sources = Arrays.asList("[ 'foo']", "[ 'foo' , ]"); + for(final String src : sources) { final JexlExpression e = JEXL.createExpression(src); final Object o = e.evaluate(null); Assert.assertArrayEquals(check, (Object[]) o); @@ -101,7 +101,7 @@ public void testLiteralWithNumbers() throws Exception { final JexlContext jc = new MapContext(); final Object o = e.evaluate(jc); - final Object[] check = {new Double(5), new Integer(10)}; + final Object[] check = {Double.valueOf(5), Integer.valueOf(10)}; Assert.assertArrayEquals(check, (Object[]) o); Assert.assertTrue(o.getClass().isArray() && o.getClass().getComponentType().equals(Number.class)); } @@ -116,9 +116,9 @@ public void testLiteralWithNulls() throws Exception { "[ null, '10' , null ]" }; final Object[][] checks = { - {null, new Integer(10)}, - {new Integer(10), null}, - {new Integer(10), null, new Integer(10)}, + {null, Integer.valueOf(10)}, + {Integer.valueOf(10), null}, + {Integer.valueOf(10), null, Integer.valueOf(10)}, {"10", null}, {null, "10", null} }; @@ -147,7 +147,7 @@ public void testSizeOfSimpleArrayLiteral() throws Exception { final JexlContext jc = new MapContext(); final Object o = e.evaluate(jc); - Assert.assertEquals(new Integer(2), o); + Assert.assertEquals(Integer.valueOf(2), o); } @Test @@ -156,7 +156,7 @@ public void notestCallingMethodsOnNewMapLiteral() throws Exception { final JexlContext jc = new MapContext(); final Object o = e.evaluate(jc); - Assert.assertEquals(new Integer(1), o); + Assert.assertEquals(Integer.valueOf(1), o); } @Test diff --git a/src/test/java/org/apache/commons/jexl3/AssignTest.java b/src/test/java/org/apache/commons/jexl3/AssignTest.java index ed510174e..bbbe3e798 100644 --- a/src/test/java/org/apache/commons/jexl3/AssignTest.java +++ b/src/test/java/org/apache/commons/jexl3/AssignTest.java @@ -81,9 +81,9 @@ public void testAntish() { final JexlExpression check = JEXL.createExpression("froboz.value"); final JexlContext jc = new MapContext(); Object o = assign.evaluate(jc); - Assert.assertEquals("Result is not 10", new Integer(10), o); + Assert.assertEquals("Result is not 10", Integer.valueOf(10), o); o = check.evaluate(jc); - Assert.assertEquals("Result is not 10", new Integer(10), o); + Assert.assertEquals("Result is not 10", Integer.valueOf(10), o); } @Test @@ -92,9 +92,9 @@ public void testAntishInteger() { final JexlExpression check = JEXL.createExpression("froboz.0"); final JexlContext jc = new MapContext(); Object o = assign.evaluate(jc); - Assert.assertEquals("Result is not 10", new Integer(10), o); + Assert.assertEquals("Result is not 10", Integer.valueOf(10), o); o = check.evaluate(jc); - Assert.assertEquals("Result is not 10", new Integer(10), o); + Assert.assertEquals("Result is not 10", Integer.valueOf(10), o); } @Test @@ -105,9 +105,9 @@ public void testBeanish() { final Froboz froboz = new Froboz(-169); jc.set("froboz", froboz); Object o = assign.evaluate(jc); - Assert.assertEquals("Result is not 10", new Integer(10), o); + Assert.assertEquals("Result is not 10", Integer.valueOf(10), o); o = check.evaluate(jc); - Assert.assertEquals("Result is not 10", new Integer(10), o); + Assert.assertEquals("Result is not 10", Integer.valueOf(10), o); } @Test @@ -137,9 +137,9 @@ public void testArray() { final Froboz froboz = new Froboz(0); jc.set("froboz", froboz); Object o = assign.evaluate(jc); - Assert.assertEquals("Result is not 10", new Integer(10), o); + Assert.assertEquals("Result is not 10", Integer.valueOf(10), o); o = check.evaluate(jc); - Assert.assertEquals("Result is not 10", new Integer(10), o); + Assert.assertEquals("Result is not 10", Integer.valueOf(10), o); } @Test @@ -147,7 +147,7 @@ public void testMini() { final JexlContext jc = new MapContext(); final JexlExpression assign = JEXL.createExpression("quux = 10"); final Object o = assign.evaluate(jc); - Assert.assertEquals("Result is not 10", new Integer(10), o); + Assert.assertEquals("Result is not 10", Integer.valueOf(10), o); } @@ -162,9 +162,9 @@ public void testMore() { final Quux quux = (Quux) create.evaluate(jc); Assert.assertNotNull("quux is null", quux); Object o = assign.evaluate(jc); - Assert.assertEquals("Result is not 10", new Integer(10), o); + Assert.assertEquals("Result is not 10", Integer.valueOf(10), o); o = check.evaluate(jc); - Assert.assertEquals("Result is not 10", new Integer(10), o); + Assert.assertEquals("Result is not 10", Integer.valueOf(10), o); } @Test @@ -173,10 +173,10 @@ public void testUtil() { Assert.assertNotNull(quux); JEXL.setProperty(quux, "froboz.value", Integer.valueOf(100)); Object o = JEXL.getProperty(quux, "froboz.value"); - Assert.assertEquals("Result is not 100", new Integer(100), o); + Assert.assertEquals("Result is not 100", Integer.valueOf(100), o); JEXL.setProperty(quux, "['froboz'].value", Integer.valueOf(1000)); o = JEXL.getProperty(quux, "['froboz']['value']"); - Assert.assertEquals("Result is not 1000", new Integer(1000), o); + Assert.assertEquals("Result is not 1000", Integer.valueOf(1000), o); } @Test @@ -199,7 +199,7 @@ public void testRejectLocal() { @Test public void testPropertyInError0() { JexlScript script; - for(String op : Arrays.asList( + for(final String op : Arrays.asList( " = ", "+= ", " -= "," *= "," /= "," %= ", " &= ", " |= ", " ^= ", " <<= ", " >>= ", " >>>= ")) { diff --git a/src/test/java/org/apache/commons/jexl3/BitwiseOperatorTest.java b/src/test/java/org/apache/commons/jexl3/BitwiseOperatorTest.java index ead912557..f9d7fb548 100644 --- a/src/test/java/org/apache/commons/jexl3/BitwiseOperatorTest.java +++ b/src/test/java/org/apache/commons/jexl3/BitwiseOperatorTest.java @@ -44,133 +44,133 @@ public BitwiseOperatorTest() { @Test public void testAndWithTwoNulls() throws Exception { - asserter.assertExpression("null & null", new Long(0)); + asserter.assertExpression("null & null", Long.valueOf(0)); } @Test public void testAndWithLeftNull() throws Exception { - asserter.assertExpression("null & 1", new Long(0)); + asserter.assertExpression("null & 1", Long.valueOf(0)); } @Test public void testAndWithRightNull() throws Exception { - asserter.assertExpression("1 & null", new Long(0)); + asserter.assertExpression("1 & null", Long.valueOf(0)); } @Test public void testAndSimple() throws Exception { - asserter.assertExpression("15 & 3", new Long(15 & 3)); + asserter.assertExpression("15 & 3", Long.valueOf(15 & 3)); } @Test public void testAndVariableNumberCoercion() throws Exception { - asserter.setVariable("x", new Integer(15)); - asserter.setVariable("y", new Short((short) 7)); - asserter.assertExpression("x & y", new Long(15 & 7)); + asserter.setVariable("x", Integer.valueOf(15)); + asserter.setVariable("y", Short.valueOf((short) 7)); + asserter.assertExpression("x & y", Long.valueOf(15 & 7)); } @Test public void testAndVariableStringCoercion() throws Exception { - asserter.setVariable("x", new Integer(15)); + asserter.setVariable("x", Integer.valueOf(15)); asserter.setVariable("y", "7"); - asserter.assertExpression("x & y", new Long(15 & 7)); + asserter.assertExpression("x & y", Long.valueOf(15 & 7)); } @Test public void testComplementWithNull() throws Exception { - asserter.assertExpression("~null", new Long(-1)); + asserter.assertExpression("~null", Long.valueOf(-1)); } @Test public void testComplementSimple() throws Exception { - asserter.assertExpression("~128", new Long(-129)); + asserter.assertExpression("~128", Long.valueOf(-129)); } @Test public void testComplementVariableNumberCoercion() throws Exception { - asserter.setVariable("x", new Integer(15)); - asserter.assertExpression("~x", new Long(~15)); + asserter.setVariable("x", Integer.valueOf(15)); + asserter.assertExpression("~x", Long.valueOf(~15)); } @Test public void testComplementVariableStringCoercion() throws Exception { asserter.setVariable("x", "15"); - asserter.assertExpression("~x", new Long(~15)); + asserter.assertExpression("~x", Long.valueOf(~15)); } @Test public void testOrWithTwoNulls() throws Exception { - asserter.assertExpression("null | null", new Long(0)); + asserter.assertExpression("null | null", Long.valueOf(0)); } @Test public void testOrWithLeftNull() throws Exception { - asserter.assertExpression("null | 1", new Long(1)); + asserter.assertExpression("null | 1", Long.valueOf(1)); } @Test public void testOrWithRightNull() throws Exception { - asserter.assertExpression("1 | null", new Long(1)); + asserter.assertExpression("1 | null", Long.valueOf(1)); } @Test public void testOrSimple() throws Exception { - asserter.assertExpression("12 | 3", new Long(15)); + asserter.assertExpression("12 | 3", Long.valueOf(15)); } @Test public void testOrVariableNumberCoercion() throws Exception { - asserter.setVariable("x", new Integer(12)); - asserter.setVariable("y", new Short((short) 3)); - asserter.assertExpression("x | y", new Long(15)); + asserter.setVariable("x", Integer.valueOf(12)); + asserter.setVariable("y", Short.valueOf((short) 3)); + asserter.assertExpression("x | y", Long.valueOf(15)); } @Test public void testOrVariableStringCoercion() throws Exception { - asserter.setVariable("x", new Integer(12)); + asserter.setVariable("x", Integer.valueOf(12)); asserter.setVariable("y", "3"); - asserter.assertExpression("x | y", new Long(15)); + asserter.assertExpression("x | y", Long.valueOf(15)); } @Test public void testXorWithTwoNulls() throws Exception { - asserter.assertExpression("null ^ null", new Long(0)); + asserter.assertExpression("null ^ null", Long.valueOf(0)); } @Test public void testXorWithLeftNull() throws Exception { - asserter.assertExpression("null ^ 1", new Long(1)); + asserter.assertExpression("null ^ 1", Long.valueOf(1)); } @Test public void testXorWithRightNull() throws Exception { - asserter.assertExpression("1 ^ null", new Long(1)); + asserter.assertExpression("1 ^ null", Long.valueOf(1)); } @Test public void testXorSimple() throws Exception { - asserter.assertExpression("1 ^ 3", new Long(1 ^ 3)); + asserter.assertExpression("1 ^ 3", Long.valueOf(1 ^ 3)); } @Test public void testXorVariableNumberCoercion() throws Exception { - asserter.setVariable("x", new Integer(1)); - asserter.setVariable("y", new Short((short) 3)); - asserter.assertExpression("x ^ y", new Long(1 ^ 3)); + asserter.setVariable("x", Integer.valueOf(1)); + asserter.setVariable("y", Short.valueOf((short) 3)); + asserter.assertExpression("x ^ y", Long.valueOf(1 ^ 3)); } @Test public void testXorVariableStringCoercion() throws Exception { - asserter.setVariable("x", new Integer(1)); + asserter.setVariable("x", Integer.valueOf(1)); asserter.setVariable("y", "3"); - asserter.assertExpression("x ^ y", new Long(1 ^ 3)); + asserter.assertExpression("x ^ y", Long.valueOf(1 ^ 3)); } @Test public void testParenthesized() throws Exception { asserter.assertExpression("(2 | 1) & 3", Long.valueOf(3L)); asserter.assertExpression("(2 & 1) | 3", Long.valueOf(3L)); - asserter.assertExpression("~(120 | 42)", new Long(~(120 | 42))); + asserter.assertExpression("~(120 | 42)", Long.valueOf(~(120 | 42))); } } diff --git a/src/test/java/org/apache/commons/jexl3/BlockTest.java b/src/test/java/org/apache/commons/jexl3/BlockTest.java index fb646caa8..678590b4c 100644 --- a/src/test/java/org/apache/commons/jexl3/BlockTest.java +++ b/src/test/java/org/apache/commons/jexl3/BlockTest.java @@ -64,7 +64,7 @@ public void testBlockLastExecuted01() throws Exception { final JexlScript e = JEXL.createScript("if (true) { x = 1; } else { x = 2; }"); final JexlContext jc = new MapContext(); final Object o = e.execute(jc); - Assert.assertEquals("Block result is wrong", new Integer(1), o); + Assert.assertEquals("Block result is wrong", Integer.valueOf(1), o); } @Test @@ -72,7 +72,7 @@ public void testBlockLastExecuted02() throws Exception { final JexlScript e = JEXL.createScript("if (false) { x = 1; } else { x = 2; }"); final JexlContext jc = new MapContext(); final Object o = e.execute(jc); - Assert.assertEquals("Block result is wrong", new Integer(2), o); + Assert.assertEquals("Block result is wrong", Integer.valueOf(2), o); } @Test diff --git a/src/test/java/org/apache/commons/jexl3/BuilderTest.java b/src/test/java/org/apache/commons/jexl3/BuilderTest.java index 81fecc273..6b5e963a1 100644 --- a/src/test/java/org/apache/commons/jexl3/BuilderTest.java +++ b/src/test/java/org/apache/commons/jexl3/BuilderTest.java @@ -62,14 +62,14 @@ public void testValues() { @Test public void testOther() { - ClassLoader cls = getClass().getClassLoader().getParent(); + final ClassLoader cls = getClass().getClassLoader().getParent(); Assert.assertEquals(cls, builder().loader(cls).loader()); - Charset cs = Charset.forName("UTF16"); + final Charset cs = Charset.forName("UTF16"); Assert.assertEquals(cs, builder().charset(cs).charset()); Assert.assertEquals(cs, builder().loader(cs).charset()); - JexlUberspect u0 = builder().create().getUberspect(); - JexlSandbox sandbox = new JexlSandbox(); - JexlUberspect uberspect = new SandboxUberspect(u0, sandbox); + final JexlUberspect u0 = builder().create().getUberspect(); + final JexlSandbox sandbox = new JexlSandbox(); + final JexlUberspect uberspect = new SandboxUberspect(u0, sandbox); Assert.assertEquals(sandbox, builder().sandbox(sandbox).sandbox()); Assert.assertEquals(uberspect, builder().uberspect(uberspect).uberspect()); } diff --git a/src/test/java/org/apache/commons/jexl3/CacheTest.java b/src/test/java/org/apache/commons/jexl3/CacheTest.java index 4391f6dd1..751ea2a70 100644 --- a/src/test/java/org/apache/commons/jexl3/CacheTest.java +++ b/src/test/java/org/apache/commons/jexl3/CacheTest.java @@ -531,7 +531,7 @@ public ComputeTask(final int loops) { @Override public Integer call() throws Exception { args.ca = new Object[]{args.c0, args.c1, args.c2}; - args.value = new Object[]{new Integer(2), "quux"}; + args.value = new Object[]{Integer.valueOf(2), "quux"}; //jexl.setDebug(true); final JexlExpression compute2 = jexl.createExpression("cache.compute(a0, a1)"); final JexlExpression compute1 = jexl.createExpression("cache.compute(a0)"); @@ -687,7 +687,7 @@ public void testCOMPUTENoCache() throws Exception { args.ca = new Object[]{ Cached.class, Cached1.class, Cached2.class }; - args.value = new Object[]{new Integer(2), "quux"}; + args.value = new Object[]{Integer.valueOf(2), "quux"}; doCOMPUTE(args, LOOPS, false); } @@ -697,7 +697,7 @@ public void testCOMPUTECache() throws Exception { args.ca = new Object[]{ Cached.class, Cached1.class, Cached2.class }; - args.value = new Object[]{new Integer(2), "quux"}; + args.value = new Object[]{Integer.valueOf(2), "quux"}; doCOMPUTE(args, LOOPS, true); } } diff --git a/src/test/java/org/apache/commons/jexl3/ClassCreator.java b/src/test/java/org/apache/commons/jexl3/ClassCreator.java index e3685ec38..4c8255d39 100644 --- a/src/test/java/org/apache/commons/jexl3/ClassCreator.java +++ b/src/test/java/org/apache/commons/jexl3/ClassCreator.java @@ -105,7 +105,7 @@ public Class getClassInstance() throws Exception { public ClassLoader getClassLoader() throws Exception { if (loader == null) { - final URL classpath = (new File(base, Integer.toString(seed))).toURI().toURL(); + final URL classpath = new File(base, Integer.toString(seed)).toURI().toURL(); loader = new URLClassLoader(new URL[]{classpath}, getClass().getClassLoader()); } return loader; @@ -202,8 +202,8 @@ Class compile() throws Exception { // the classpath is {hbaseSrc}/target/classes. final String currentDir = new File(".").getAbsolutePath(); final String classpath = currentDir + File.separator + "target" + File.separator + "classes" - //+ System.getProperty("path.separator") + System.getProperty("java.class.path") - + System.getProperty("path.separator") + System.getProperty("surefire.test.class.path"); + //+ File.pathSeparator + System.getProperty("java.class.path") + + File.pathSeparator + System.getProperty("surefire.test.class.path"); options.add(classpath); //LOG.debug("Setting classpath to: " + classpath); diff --git a/src/test/java/org/apache/commons/jexl3/ClassCreatorTest.java b/src/test/java/org/apache/commons/jexl3/ClassCreatorTest.java index 5ff6dcec9..df75fae86 100644 --- a/src/test/java/org/apache/commons/jexl3/ClassCreatorTest.java +++ b/src/test/java/org/apache/commons/jexl3/ClassCreatorTest.java @@ -309,12 +309,12 @@ public void testMany() throws Exception { context.set("clazz", clazz); z = newx.evaluate(context); Assert.assertNotNull(clazz + ": class " + i + " could not be instantiated on pass " + pass, z); - Assert.assertEquals(new Integer(i), expr.evaluate(context)); + Assert.assertEquals(Integer.valueOf(i), expr.evaluate(context)); // with the proper class loader, attempt to create an instance from the class name jexl.setClassLoader(cctor.getClassLoader()); z = newx.evaluate(context); Assert.assertEquals(z.getClass(), clazz); - Assert.assertEquals(new Integer(i), expr.evaluate(context)); + Assert.assertEquals(Integer.valueOf(i), expr.evaluate(context)); cctor.clear(); jexl.setClassLoader(null); diff --git a/src/test/java/org/apache/commons/jexl3/CollectionLiteralTest.java b/src/test/java/org/apache/commons/jexl3/CollectionLiteralTest.java index 1898d2786..0adfd47a2 100644 --- a/src/test/java/org/apache/commons/jexl3/CollectionLiteralTest.java +++ b/src/test/java/org/apache/commons/jexl3/CollectionLiteralTest.java @@ -46,29 +46,29 @@ public static class Arithmetic363 extends JexlArithmetic { final AtomicInteger sets = new AtomicInteger(0); final AtomicInteger arrays = new AtomicInteger(0); - public Arithmetic363(boolean strict) { + public Arithmetic363(final boolean strict) { super(strict); } - @Override public MapBuilder mapBuilder(int size, boolean extended) { + @Override public MapBuilder mapBuilder(final int size, final boolean extended) { return new CountingMapBuilder(maps, size, extended); } - @Override public SetBuilder setBuilder(int size, boolean extended) { + @Override public SetBuilder setBuilder(final int size, final boolean extended) { return new CountingSetBuilder(sets, size, extended); } - @Override public ArrayBuilder arrayBuilder(int size, boolean extended) { + @Override public ArrayBuilder arrayBuilder(final int size, final boolean extended) { return new CountingArrayBuilder(arrays, size, extended); } } static class CountingSetBuilder extends SetBuilder { final AtomicInteger count; - public CountingSetBuilder(AtomicInteger ai, int size, boolean extended) { + public CountingSetBuilder(final AtomicInteger ai, final int size, final boolean extended) { super(size, extended); count = ai; } @Override public Set create() { - Set set = super.create(); + final Set set = super.create(); count.incrementAndGet(); return set; } @@ -76,12 +76,12 @@ public CountingSetBuilder(AtomicInteger ai, int size, boolean extended) { static class CountingMapBuilder extends MapBuilder { final AtomicInteger count; - public CountingMapBuilder(AtomicInteger ai, int size, boolean extended) { + public CountingMapBuilder(final AtomicInteger ai, final int size, final boolean extended) { super(size, extended); count = ai; } @Override public Map create() { - Map map = super.create(); + final Map map = super.create(); count.incrementAndGet(); return map; } @@ -90,13 +90,13 @@ public CountingMapBuilder(AtomicInteger ai, int size, boolean extended) { static class CountingArrayBuilder extends ArrayBuilder { final AtomicInteger count; - public CountingArrayBuilder(AtomicInteger ai, int size, boolean extended) { + public CountingArrayBuilder(final AtomicInteger ai, final int size, final boolean extended) { super(size, extended); count = ai; } - @Override public Object create(boolean extended) { - Object array = super.create(extended); + @Override public Object create(final boolean extended) { + final Object array = super.create(extended); count.incrementAndGet(); return array; } @@ -104,7 +104,7 @@ public CountingArrayBuilder(AtomicInteger ai, int size, boolean extended) { @Test public void testMapLBuilder() { - Arithmetic363 jc = new Arithmetic363(true); + final Arithmetic363 jc = new Arithmetic363(true); final JexlEngine jexl = new JexlBuilder().cache(4).arithmetic(jc).create(); JexlScript script; Object result; @@ -122,7 +122,7 @@ public void testMapLBuilder() { @Test public void testSetBuilder() { - Arithmetic363 jc = new Arithmetic363(true); + final Arithmetic363 jc = new Arithmetic363(true); final JexlEngine jexl = new JexlBuilder().cache(4).arithmetic(jc).create(); JexlScript script; Object result; @@ -140,7 +140,7 @@ public void testSetBuilder() { @Test public void testArrayBuilder() { - Arithmetic363 jc = new Arithmetic363(true); + final Arithmetic363 jc = new Arithmetic363(true); final JexlEngine jexl = new JexlBuilder().cache(4).arithmetic(jc).create(); JexlScript script; Object result; diff --git a/src/test/java/org/apache/commons/jexl3/ComposePermissionsTest.java b/src/test/java/org/apache/commons/jexl3/ComposePermissionsTest.java index be4f20e98..13765d85c 100644 --- a/src/test/java/org/apache/commons/jexl3/ComposePermissionsTest.java +++ b/src/test/java/org/apache/commons/jexl3/ComposePermissionsTest.java @@ -56,26 +56,26 @@ public void testComposePermissions2() throws Exception { runComposePermissions(new JexlPermissions.ClassPermissions(JexlPermissions.UNRESTRICTED, Collections.emptySet())); } - void runComposePermissions(JexlPermissions p) throws Exception { + void runComposePermissions(final JexlPermissions p) throws Exception { final String check = "http://example.com/content.jpg"; final File jsonFile = new File(SAMPLE_JSON); - Gson gson = new Gson(); - Object json = gson.fromJson(new FileReader(jsonFile), Object.class); + final Gson gson = new Gson(); + final Object json = gson.fromJson(new FileReader(jsonFile), Object.class); Assert.assertNotNull(json); // will succeed because java.util.Map is allowed and gson LinkedTreeMap is one - JexlEngine j0 = createEngine(false, p); - JexlScript s0 = j0.createScript("json.pageInfo.pagePic", "json"); - Object r0 = s0.execute(null, json); + final JexlEngine j0 = createEngine(false, p); + final JexlScript s0 = j0.createScript("json.pageInfo.pagePic", "json"); + final Object r0 = s0.execute(null, json); Assert.assertEquals(check, r0); // will fail if gson package is denied JexlEngine j1 = createEngine(false, p.compose("com.google.gson.internal {}")); JexlScript s1 = j1.createScript("json.pageInfo.pagePic", "json"); try { - Object r1 = s1.execute(null, json); + final Object r1 = s1.execute(null, json); Assert.fail("gson restricted"); - } catch (JexlException.Property xproperty) { + } catch (final JexlException.Property xproperty) { Assert.assertEquals("pageInfo", xproperty.getProperty()); } @@ -83,16 +83,16 @@ void runComposePermissions(JexlPermissions p) throws Exception { j1 = createEngine(false, p.compose("com.google.gson.internal { LinkedTreeMap {} }")); s1 = j1.createScript("json.pageInfo.pagePic", "json"); try { - Object r1 = s1.execute(null, json); + final Object r1 = s1.execute(null, json); Assert.fail("gson LinkTreeMap restricted"); - } catch (JexlException.Property xproperty) { + } catch (final JexlException.Property xproperty) { Assert.assertEquals("pageInfo", xproperty.getProperty()); } // will not fail since gson objects j1 = createEngine(false, JexlPermissions.RESTRICTED); s1 = j1.createScript("json.pageInfo.pagePic", "json"); - Object r1 = s1.execute(null, json); + final Object r1 = s1.execute(null, json); Assert.assertEquals(check, r0); } } diff --git a/src/test/java/org/apache/commons/jexl3/ContextNamespaceTest.java b/src/test/java/org/apache/commons/jexl3/ContextNamespaceTest.java index a6c868661..feb5db8fa 100644 --- a/src/test/java/org/apache/commons/jexl3/ContextNamespaceTest.java +++ b/src/test/java/org/apache/commons/jexl3/ContextNamespaceTest.java @@ -49,7 +49,7 @@ public Taxes(final double d) { } public double vat(final double n) { - return (n * vat) / 100.; + return n * vat / 100.; } } @@ -104,14 +104,14 @@ public void testNamespacePragma() { } public static class Context346 extends MapContext { - public int func(int y) { return 42 * y;} + public int func(final int y) { return 42 * y;} } @Test public void testNamespace346a() { - JexlContext ctxt = new Context346(); + final JexlContext ctxt = new Context346(); final JexlEngine jexl = new JexlBuilder().safe(false).create(); - String src = "x != null ? x : func(y)"; + final String src = "x != null ? x : func(y)"; final JexlScript script = jexl.createScript(src,"x","y"); Object result = script.execute(ctxt, null, 1); Assert.assertEquals(42, result); @@ -121,12 +121,12 @@ public void testNamespace346a() { @Test public void testNamespace346b() { - JexlContext ctxt = new MapContext(); - Map ns = new HashMap<>(); + final JexlContext ctxt = new MapContext(); + final Map ns = new HashMap<>(); ns.put("x", Math.class); ns.put(null, Math.class); final JexlEngine jexl = new JexlBuilder().safe(false).namespaces(ns).create(); - String src = "x != null ? x : abs(y)"; + final String src = "x != null ? x : abs(y)"; final JexlScript script = jexl.createScript(src,"x","y"); Object result = script.execute(ctxt, null, 42); Assert.assertEquals(42, result); @@ -135,22 +135,22 @@ public void testNamespace346b() { } public static class Ns348 { - public static int func(int y) { return 42 * y;} + public static int func(final int y) { return 42 * y;} } public static class ContextNs348 extends MapContext implements JexlContext.NamespaceResolver { - ContextNs348() { super(); } + ContextNs348() { } @Override - public Object resolveNamespace(String name) { + public Object resolveNamespace(final String name) { return "ns".equals(name)? new Ns348() : null; } } @Test public void testNamespace348a() { - JexlContext ctxt = new MapContext(); - Map ns = new HashMap<>(); + final JexlContext ctxt = new MapContext(); + final Map ns = new HashMap<>(); ns.put("ns", Ns348.class); final JexlEngine jexl = new JexlBuilder().safe(false).namespaces(ns).create(); run348a(jexl, ctxt); @@ -161,7 +161,7 @@ public void testNamespace348a() { @Test public void testNamespace348b() { - JexlContext ctxt = new ContextNs348(); + final JexlContext ctxt = new ContextNs348(); final JexlEngine jexl = new JexlBuilder().safe(false).create(); // no space for ns name as syntactic hint run348a(jexl, ctxt, "ns:"); @@ -172,11 +172,11 @@ public void testNamespace348b() { @Test public void testNamespace348c() { - JexlContext ctxt = new ContextNs348(); - Map ns = new HashMap<>(); + final JexlContext ctxt = new ContextNs348(); + final Map ns = new HashMap<>(); ns.put("ns", Ns348.class); - JexlFeatures f = new JexlFeatures(); - f.namespaceTest((n)->true); + final JexlFeatures f = new JexlFeatures(); + f.namespaceTest(n -> true); final JexlEngine jexl = new JexlBuilder().namespaces(ns).features(f).safe(false).create(); run348a(jexl, ctxt); run348b(jexl, ctxt); @@ -186,9 +186,9 @@ public void testNamespace348c() { @Test public void testNamespace348d() { - JexlContext ctxt = new ContextNs348(); - JexlFeatures f = new JexlFeatures(); - f.namespaceTest((n)->true); + final JexlContext ctxt = new ContextNs348(); + final JexlFeatures f = new JexlFeatures(); + f.namespaceTest(n -> true); final JexlEngine jexl = new JexlBuilder().features(f).safe(false).create(); run348a(jexl, ctxt); run348b(jexl, ctxt); @@ -196,26 +196,26 @@ public void testNamespace348d() { run348d(jexl, ctxt); } - private void run348a(JexlEngine jexl, JexlContext ctxt) { + private void run348a(final JexlEngine jexl, final JexlContext ctxt) { run348a(jexl, ctxt, "ns : "); } - private void run348a(JexlEngine jexl, JexlContext ctxt, String ns) { - String src = "empty(x) ? "+ns+"func(y) : z"; + private void run348a(final JexlEngine jexl, final JexlContext ctxt, final String ns) { + final String src = "empty(x) ? "+ns+"func(y) : z"; // local vars - JexlScript script = jexl.createScript(src, "x", "y", "z"); + final JexlScript script = jexl.createScript(src, "x", "y", "z"); Object result = script.execute(ctxt, null, 1, 169); Assert.assertEquals(42, result); result = script.execute(ctxt, "42", 1, 169); Assert.assertEquals(169, result); } - private void run348b(JexlEngine jexl, JexlContext ctxt) { + private void run348b(final JexlEngine jexl, final JexlContext ctxt) { run348b(jexl, ctxt, "ns : "); } - private void run348b(JexlEngine jexl, JexlContext ctxt, String ns) { - String src = "empty(x) ? "+ns+"func(y) : z"; + private void run348b(final JexlEngine jexl, final JexlContext ctxt, final String ns) { + final String src = "empty(x) ? "+ns+"func(y) : z"; // global vars - JexlScript script = jexl.createScript(src); + final JexlScript script = jexl.createScript(src); ctxt.set("x", null); ctxt.set("y", 1); ctxt.set("z", 169); @@ -229,29 +229,29 @@ private void run348b(JexlEngine jexl, JexlContext ctxt, String ns) { Assert.assertEquals(169, result); } - private void run348c(JexlEngine jexl, JexlContext ctxt) { + private void run348c(final JexlEngine jexl, final JexlContext ctxt) { run348c(jexl, ctxt, "ns : "); } - private void run348c(JexlEngine jexl, JexlContext ctxt, String ns) { - String src = "empty(x) ? z : "+ns+"func(y)"; + private void run348c(final JexlEngine jexl, final JexlContext ctxt, final String ns) { + final String src = "empty(x) ? z : "+ns+"func(y)"; // local vars - JexlScript script = jexl.createScript(src, "x", "z", "y"); + final JexlScript script = jexl.createScript(src, "x", "z", "y"); Object result = script.execute(ctxt, null, 169, 1); Assert.assertEquals(src, 169, result); result = script.execute(ctxt, "42", 169, 1); Assert.assertEquals(src, 42, result); } - private void run348d(JexlEngine jexl, JexlContext ctxt) { + private void run348d(final JexlEngine jexl, final JexlContext ctxt) { run348d(jexl, ctxt, "ns : "); } - private void run348d(JexlEngine jexl, JexlContext ctxt, String ns) { - String src = "empty(x) ? z : "+ns+"func(y)"; + private void run348d(final JexlEngine jexl, final JexlContext ctxt, final String ns) { + final String src = "empty(x) ? z : "+ns+"func(y)"; // global vars JexlScript script = null; try { script = jexl.createScript(src); - } catch (JexlException.Parsing xparse) { + } catch (final JexlException.Parsing xparse) { Assert.fail(src); } ctxt.set("x", null); @@ -329,13 +329,13 @@ public void testObjectContext() { public static class NsNs { private final int constVar; - public NsNs(JexlContext ctxt) { + public NsNs(final JexlContext ctxt) { nsnsCtor.incrementAndGet(); - Object n = ctxt.get("NUMBER"); - constVar = (n instanceof Number) ? ((Number) n).intValue() : -1; + final Object n = ctxt.get("NUMBER"); + constVar = n instanceof Number ? ((Number) n).intValue() : -1; } - public int callIt(int n) { + public int callIt(final int n) { return n + constVar; } } @@ -343,7 +343,7 @@ public int callIt(int n) { @Test public void testNsNsContext0() { nsnsCtor.set(0); - String clsName = NsNs.class.getName(); + final String clsName = NsNs.class.getName(); runNsNsContext(Collections.singletonMap("nsns", clsName)); } @@ -353,8 +353,8 @@ public void testNsNsContext1() { runNsNsContext(Collections.singletonMap("nsns", NsNs.class)); } - private void runNsNsContext(Map nsMap) { - JexlContext ctxt = new MapContext(); + private void runNsNsContext(final Map nsMap) { + final JexlContext ctxt = new MapContext(); ctxt.set("NUMBER", 19); final JexlEngine jexl = new JexlBuilder().strict(true).silent(false).cache(32) .namespaces(nsMap).create(); @@ -369,7 +369,7 @@ private void runNsNsContext(Map nsMap) { public static class StaticNs { private StaticNs() { } - public static int callIt(int n) { + public static int callIt(final int n) { return n + 19; } } @@ -384,8 +384,8 @@ public void testStaticNs1() { runStaticNsContext(Collections.singletonMap("sns", StaticNs.class.getName())); } - private void runStaticNsContext(Map nsMap) { - JexlContext ctxt = new MapContext(); + private void runStaticNsContext(final Map nsMap) { + final JexlContext ctxt = new MapContext(); final JexlEngine jexl = new JexlBuilder().strict(true).silent(false).cache(32) .namespaces(nsMap).create(); final JexlScript script = jexl.createScript("x ->{ sns:callIt(x); sns:callIt(x); }"); diff --git a/src/test/java/org/apache/commons/jexl3/DoWhileTest.java b/src/test/java/org/apache/commons/jexl3/DoWhileTest.java index 3f2e43f95..d92e03bba 100644 --- a/src/test/java/org/apache/commons/jexl3/DoWhileTest.java +++ b/src/test/java/org/apache/commons/jexl3/DoWhileTest.java @@ -73,13 +73,13 @@ public void testWhileExecutesExpressionWhenLooping() throws Exception { public void testWhileWithBlock() throws Exception { final JexlScript e = JEXL.createScript("do { x = x + 1; y = y * 2; } while (x < 10)"); final JexlContext jc = new MapContext(); - jc.set("x", new Integer(1)); - jc.set("y", new Integer(1)); + jc.set("x", Integer.valueOf(1)); + jc.set("y", Integer.valueOf(1)); final Object o = e.execute(jc); - Assert.assertEquals("Result is wrong", new Integer(512), o); - Assert.assertEquals("x is wrong", new Integer(10), jc.get("x")); - Assert.assertEquals("y is wrong", new Integer(512), jc.get("y")); + Assert.assertEquals("Result is wrong", Integer.valueOf(512), o); + Assert.assertEquals("x is wrong", Integer.valueOf(10), jc.get("x")); + Assert.assertEquals("y is wrong", Integer.valueOf(512), jc.get("y")); } @Test @@ -143,32 +143,32 @@ public void testWhileEmptyStmtBody() throws Exception { } @Test public void testForLoop0() { - String src = "(l)->{ for(let x = 0; x < 4; ++x) { l.add(x); } }"; - JexlEngine jexl = new JexlBuilder().safe(true).create(); - JexlScript script = jexl.createScript(src); - List l = new ArrayList<>(); - Object result = script.execute(null, l); + final String src = "(l)->{ for(let x = 0; x < 4; ++x) { l.add(x); } }"; + final JexlEngine jexl = new JexlBuilder().safe(true).create(); + final JexlScript script = jexl.createScript(src); + final List l = new ArrayList<>(); + final Object result = script.execute(null, l); Assert.assertNotNull(result); Assert.assertEquals(Arrays.asList(0, 1, 2, 3), l); } @Test public void testForLoop1() { - String src = "(l)->{ for(var x = 0; x < 4; ++x) { l.add(x); } }"; - JexlEngine jexl = new JexlBuilder().safe(true).create(); - JexlScript script = jexl.createScript(src); - List l = new ArrayList<>(); - Object result = script.execute(null, l); + final String src = "(l)->{ for(var x = 0; x < 4; ++x) { l.add(x); } }"; + final JexlEngine jexl = new JexlBuilder().safe(true).create(); + final JexlScript script = jexl.createScript(src); + final List l = new ArrayList<>(); + final Object result = script.execute(null, l); Assert.assertNotNull(result); Assert.assertEquals(Arrays.asList(0, 1, 2, 3), l); } @Test public void testForLoop2() { - String src = "(l)->{ for(x = 0; x < 4; ++x) { l.add(x); } }"; - JexlEngine jexl = new JexlBuilder().safe(true).create(); - JexlScript script = jexl.createScript(src); - List l = new ArrayList<>(); - JexlContext ctxt = new MapContext(); - Object result = script.execute(ctxt, l); + final String src = "(l)->{ for(x = 0; x < 4; ++x) { l.add(x); } }"; + final JexlEngine jexl = new JexlBuilder().safe(true).create(); + final JexlScript script = jexl.createScript(src); + final List l = new ArrayList<>(); + final JexlContext ctxt = new MapContext(); + final Object result = script.execute(ctxt, l); Assert.assertNotNull(result); Assert.assertEquals(Arrays.asList(0, 1, 2, 3), l); } diff --git a/src/test/java/org/apache/commons/jexl3/FeaturesTest.java b/src/test/java/org/apache/commons/jexl3/FeaturesTest.java index a197238a2..f61ee09bd 100644 --- a/src/test/java/org/apache/commons/jexl3/FeaturesTest.java +++ b/src/test/java/org/apache/commons/jexl3/FeaturesTest.java @@ -69,7 +69,7 @@ private void assertOk(final JexlFeatures features, final String[] scripts) { public void testNoScript() throws Exception { final JexlFeatures f = new JexlFeatures().script(false); Assert.assertTrue(f.supportsExpression()); - final String[] scripts = new String[]{ + final String[] scripts = { "if (false) { block(); }", "{ noway(); }", "while(true);", @@ -81,7 +81,7 @@ public void testNoScript() throws Exception { @Test public void testNoLoop() throws Exception { final JexlFeatures f = new JexlFeatures().loops(false); - final String[] scripts = new String[]{ + final String[] scripts = { "while(true);", "for(var i : {0 .. 10}) { bar(i); }" }; @@ -91,7 +91,7 @@ public void testNoLoop() throws Exception { @Test public void testNoLambda() throws Exception { final JexlFeatures f = new JexlFeatures().lambda(false); - final String[] scripts = new String[]{ + final String[] scripts = { "var x = ()->{ return 0 };", "()->{ return 0 };", "(x, y)->{ return 0 };", @@ -105,7 +105,7 @@ public void testNoLambda() throws Exception { @Test public void testNoNew() throws Exception { final JexlFeatures f = new JexlFeatures().newInstance(false); - final String[] scripts = new String[]{ + final String[] scripts = { "return new(clazz);", "new('java.math.BigDecimal', 12) + 1" }; @@ -115,7 +115,7 @@ public void testNoNew() throws Exception { @Test public void testNoSideEffects() throws Exception { final JexlFeatures f = new JexlFeatures().sideEffect(false); - final String[] scripts = new String[]{ + final String[] scripts = { "x = 1", "x.y = 1", "x().y = 1", @@ -139,7 +139,7 @@ public void testNoSideEffects() throws Exception { @Test public void testNoSideEffectsGlobal() throws Exception { final JexlFeatures f = new JexlFeatures().sideEffectGlobal(false); - final String[] scripts = new String[]{ + final String[] scripts = { "x = 1", "x.y = 1", "x().y = 1", @@ -170,7 +170,7 @@ public void testNoSideEffectsGlobal() throws Exception { @Test public void testNoLocals() throws Exception { final JexlFeatures f = new JexlFeatures().localVar(false); - final String[] scripts = new String[]{ + final String[] scripts = { "var x = 0;", "(x)->{ x }" }; @@ -180,13 +180,13 @@ public void testNoLocals() throws Exception { @Test public void testReservedVars() throws Exception { final JexlFeatures f = new JexlFeatures().reservedNames(Arrays.asList("foo", "bar")); - final String[] scripts = new String[]{ + final String[] scripts = { "var foo = 0;", "(bar)->{ bar }", "var f = function(bar) { bar; }" }; checkFeature(f, scripts); - final String[] scriptsOk = new String[]{ + final String[] scriptsOk = { "var foo0 = 0;", "(bar1)->{ bar }", "var f = function(bar2) { bar2; }" @@ -198,7 +198,7 @@ public void testReservedVars() throws Exception { public void testArrayRefs() throws Exception { final JexlFeatures f = new JexlFeatures().arrayReferenceExpr(false); - final String[] scripts = new String[]{ + final String[] scripts = { "x[y]", "x['a'][b]", "x()['a'][b]", @@ -207,7 +207,7 @@ public void testArrayRefs() throws Exception { checkFeature(f, scripts); assertOk(f, scripts); // same ones with constant array refs should work - final String[] scriptsOk = new String[]{ + final String[] scriptsOk = { "x['y']", "x['a'][1]", "x()['a']['b']", @@ -218,7 +218,7 @@ public void testArrayRefs() throws Exception { @Test public void testMethodCalls() throws Exception { final JexlFeatures f = new JexlFeatures().methodCall(false); - final String[] scripts = new String[]{ + final String[] scripts = { "x.y(z)", "x['a'].m(b)", "x()['a'](b)", @@ -226,7 +226,7 @@ public void testMethodCalls() throws Exception { }; checkFeature(f, scripts); // same ones with constant array refs should work - final String[] scriptsOk = new String[]{ + final String[] scriptsOk = { "x('y')", "x('a')[1]", "x()['a']['b']", @@ -237,7 +237,7 @@ public void testMethodCalls() throws Exception { @Test public void testStructuredLiterals() throws Exception { final JexlFeatures f = new JexlFeatures().structuredLiteral(false); - final String[] scripts = new String[]{ + final String[] scripts = { "{1, 2, 3}", "[1, 2, 3]", "{ 1 :'one', 2 : 'two', 3 : 'three' }", @@ -250,7 +250,7 @@ public void testStructuredLiterals() throws Exception { @Test public void testAnnotations() throws Exception { final JexlFeatures f = new JexlFeatures().annotation(false); - final String[] scripts = new String[]{ + final String[] scripts = { "@synchronized(2) { return 42; }", "@two var x = 3;" }; @@ -261,7 +261,7 @@ public void testAnnotations() throws Exception { @Test public void testPragma() throws Exception { final JexlFeatures f = new JexlFeatures().pragma(false); - final String[] scripts = new String[]{ + final String[] scripts = { "#pragma foo 42", "#pragma foo 'bar'\n@two var x = 3;" }; @@ -270,7 +270,7 @@ public void testPragma() throws Exception { @Test public void testPragmaAnywhere() throws Exception { final JexlFeatures f = new JexlFeatures().pragmaAnywhere(false); - final String[] scripts = new String[]{ + final String[] scripts = { "var x = 3;\n#pragma foo 42", }; checkFeature(f, scripts); @@ -285,7 +285,7 @@ public void testMixedFeatures() throws Exception { .lambda(false) .loops(false) .sideEffectGlobal(false); - final String[] scripts = new String[]{ + final String[] scripts = { "return new(clazz);", "()->{ return 0 };", "var x = 0;", @@ -300,7 +300,7 @@ public void testMixedFeatures() throws Exception { @Test public void testNoComparatorNames() throws Exception { final JexlFeatures f = new JexlFeatures().comparatorNames(false); - final String[] scripts = new String[]{ + final String[] scripts = { "1 eq 1", "2 ne 3", "1 lt 2", @@ -314,7 +314,7 @@ public void testNoComparatorNames() throws Exception { @Test public void testConstCapture() throws Exception { final JexlFeatures f = new JexlFeatures().constCapture(true); - final String[] scripts = new String[]{ + final String[] scripts = { "let x = 0; const f = y -> x += y; f(42)", "let x = 0; function f(y) { z -> x *= y }; f(42)" }; diff --git a/src/test/java/org/apache/commons/jexl3/ForEachTest.java b/src/test/java/org/apache/commons/jexl3/ForEachTest.java index f744d2014..ae4ee2ddd 100644 --- a/src/test/java/org/apache/commons/jexl3/ForEachTest.java +++ b/src/test/java/org/apache/commons/jexl3/ForEachTest.java @@ -39,26 +39,26 @@ public ForEachTest() { } @Test public void testForLoop0b0() { - String src = "(l)->{ for(let x = 0, y = 0; x < 4; ++x) l.add(x) }"; - JexlEngine jexl = new JexlBuilder().safe(false).create(); - JexlScript script = jexl.createScript(src); - List l = new ArrayList<>(); - Object result = script.execute(null, l); + final String src = "(l)->{ for(let x = 0, y = 0; x < 4; ++x) l.add(x) }"; + final JexlEngine jexl = new JexlBuilder().safe(false).create(); + final JexlScript script = jexl.createScript(src); + final List l = new ArrayList<>(); + final Object result = script.execute(null, l); Assert.assertNotNull(result); Assert.assertEquals(Arrays.asList(0, 1, 2, 3), l); - String resrc = toString(script); + final String resrc = toString(script); Assert.assertEquals(src, resrc); } @Test public void testForLoop0a() { - String src = "(l)->{ for(let x = 0; x < 4; ++x) { l.add(x); } }"; - JexlEngine jexl = new JexlBuilder().safe(false).create(); - JexlScript script = jexl.createScript(src); - List l = new ArrayList<>(); - Object result = script.execute(null, l); + final String src = "(l)->{ for(let x = 0; x < 4; ++x) { l.add(x); } }"; + final JexlEngine jexl = new JexlBuilder().safe(false).create(); + final JexlScript script = jexl.createScript(src); + final List l = new ArrayList<>(); + final Object result = script.execute(null, l); Assert.assertNotNull(result); Assert.assertEquals(Arrays.asList(0, 1, 2, 3), l); - String resrc = toString(script); + final String resrc = toString(script); Assert.assertEquals(src, resrc); } @@ -134,10 +134,10 @@ public void testForEachWithBlock() throws Exception { final JexlScript exs0 = JEXL.createScript("for(var in : list) { x = x + in; }"); final JexlContext jc = new MapContext(); jc.set("list", new Object[]{2, 3}); - jc.set("x", new Integer(1)); + jc.set("x", Integer.valueOf(1)); final Object o = exs0.execute(jc); - Assert.assertEquals("Result is wrong", new Integer(6), o); - Assert.assertEquals("x is wrong", new Integer(6), jc.get("x")); + Assert.assertEquals("Result is wrong", Integer.valueOf(6), o); + Assert.assertEquals("x is wrong", Integer.valueOf(6), jc.get("x")); } @Test diff --git a/src/test/java/org/apache/commons/jexl3/IfTest.java b/src/test/java/org/apache/commons/jexl3/IfTest.java index d160907a6..c0b76aefe 100644 --- a/src/test/java/org/apache/commons/jexl3/IfTest.java +++ b/src/test/java/org/apache/commons/jexl3/IfTest.java @@ -41,7 +41,7 @@ public void testSimpleIfTrue() throws Exception { final JexlContext jc = new MapContext(); final Object o = e.execute(jc); - Assert.assertEquals("Result is not 1", new Integer(1), o); + Assert.assertEquals("Result is not 1", Integer.valueOf(1), o); } /** @@ -69,7 +69,7 @@ public void testSimpleElse() throws Exception { final JexlContext jc = new MapContext(); final Object o = e.execute(jc); - Assert.assertEquals("Result is not 2", new Integer(2), o); + Assert.assertEquals("Result is not 2", Integer.valueOf(2), o); } /** @@ -97,7 +97,7 @@ public void testBlockElse() throws Exception { final JexlContext jc = new MapContext(); final Object o = e.execute(jc); - Assert.assertEquals("Result is wrong", new Integer(3), o); + Assert.assertEquals("Result is wrong", Integer.valueOf(3), o); } /** @@ -109,7 +109,7 @@ public void testBlockElse() throws Exception { public void testIfWithSimpleExpression() throws Exception { final JexlScript e = JEXL.createScript("if (x == 1) true;"); final JexlContext jc = new MapContext(); - jc.set("x", new Integer(1)); + jc.set("x", Integer.valueOf(1)); final Object o = e.execute(jc); Assert.assertEquals("Result is not true", Boolean.TRUE, o); @@ -165,7 +165,7 @@ public void testIfElseIfReturnExpression() throws Exception { public void testIfWithArithmeticExpression() throws Exception { final JexlScript e = JEXL.createScript("if ((x * 2) + 1 == 5) true;"); final JexlContext jc = new MapContext(); - jc.set("x", new Integer(2)); + jc.set("x", Integer.valueOf(2)); final Object o = e.execute(jc); Assert.assertEquals("Result is not true", Boolean.TRUE, o); @@ -180,7 +180,7 @@ public void testIfWithArithmeticExpression() throws Exception { public void testIfWithDecimalArithmeticExpression() throws Exception { final JexlScript e = JEXL.createScript("if ((x * 2) == 5) true"); final JexlContext jc = new MapContext(); - jc.set("x", new Float(2.5f)); + jc.set("x", Float.valueOf(2.5f)); final Object o = e.execute(jc); Assert.assertEquals("Result is not true", Boolean.TRUE, o); @@ -195,11 +195,11 @@ public void testIfWithDecimalArithmeticExpression() throws Exception { public void testIfWithAssignment() throws Exception { final JexlScript e = JEXL.createScript("if ((x * 2) == 5) {y = 1} else {y = 2;}"); final JexlContext jc = new MapContext(); - jc.set("x", new Float(2.5f)); + jc.set("x", Float.valueOf(2.5f)); e.execute(jc); final Object result = jc.get("y"); - Assert.assertEquals("y has the wrong value", new Integer(1), result); + Assert.assertEquals("y has the wrong value", Integer.valueOf(1), result); } /** diff --git a/src/test/java/org/apache/commons/jexl3/Issues100Test.java b/src/test/java/org/apache/commons/jexl3/Issues100Test.java index 9fbff9f10..bea1ebb5d 100644 --- a/src/test/java/org/apache/commons/jexl3/Issues100Test.java +++ b/src/test/java/org/apache/commons/jexl3/Issues100Test.java @@ -323,7 +323,7 @@ public void test117() throws Exception { final JexlEngine jexl = new Engine(); final JexlExpression e = jexl.createExpression("TIMESTAMP > 20100102000000"); final JexlContext ctx = new MapContext(); - ctx.set("TIMESTAMP", new Long("20100103000000")); + ctx.set("TIMESTAMP", Long.valueOf("20100103000000")); final Object result = e.evaluate(ctx); Assert.assertTrue((Boolean) result); } diff --git a/src/test/java/org/apache/commons/jexl3/Issues200Test.java b/src/test/java/org/apache/commons/jexl3/Issues200Test.java index fe5379097..3ac79973c 100644 --- a/src/test/java/org/apache/commons/jexl3/Issues200Test.java +++ b/src/test/java/org/apache/commons/jexl3/Issues200Test.java @@ -659,13 +659,13 @@ public void test275d() throws Exception { @Test public void test278() throws Exception { - final String[] srcs = new String[]{ + final String[] srcs = { "return union x143('arg',5,6) ", "return union y143('arg',5,6) ;", "return union\n z143('arg',5,6) ;", "var f =()->{ return union 143 } foo[0]" }; - final Object[] ctls = new Object[]{ + final Object[] ctls = { "42","42","42", 42 }; final JexlEngine jexl = new JexlBuilder().cache(4).create(); @@ -716,7 +716,7 @@ public void test279() throws Exception { Object result; JexlScript script; final JexlContext ctxt = new Context279(); - final String[] srcs = new String[]{ + final String[] srcs = { "var z = null; identity(z[0]);", "var z = null; z.0;", "var z = null; z.foo();", @@ -932,7 +932,7 @@ public void test289() { public void test290a() throws Exception { Object result; JexlScript script; - final String[] srcs = new String[]{ + final String[] srcs = { "(x)->{ x.nothing().toString() }", "(x)->{ x.toString().nothing() }", "(x)->{ x.nothing().nothing() }", @@ -963,7 +963,7 @@ public void test290a() throws Exception { public void test290b() throws Exception { Object result; JexlScript script; - final String[] srcs = new String[]{ + final String[] srcs = { "(x)->{ x?.nothing()?.toString() }", "(x)->{ x.toString()?.nothing() }", "(x)->{ x?.nothing().nothing() }",}; diff --git a/src/test/java/org/apache/commons/jexl3/Issues300Test.java b/src/test/java/org/apache/commons/jexl3/Issues300Test.java index 2d1aea3cf..411002f6d 100644 --- a/src/test/java/org/apache/commons/jexl3/Issues300Test.java +++ b/src/test/java/org/apache/commons/jexl3/Issues300Test.java @@ -48,7 +48,7 @@ public class Issues300Test { @Test public void test301a() { final JexlEngine jexl = new JexlBuilder().safe(false).arithmetic(new JexlArithmetic(false)).create(); - final String[] srcs = new String[]{ + final String[] srcs = { "var x = null; x.0", "var x = null; x[0]", "var x = [null,1]; x[0][0]" }; for (int i = 0; i < srcs.length; ++i) { @@ -68,8 +68,8 @@ public void test301a() { @Test public void tests301b() { final JexlEngine jexl = new JexlBuilder().safe(false).arithmetic(new JexlArithmetic(false)).create(); - final Object[] xs = new Object[]{null, null, new Object[]{null, 1}}; - final String[] srcs = new String[]{ + final Object[] xs = {null, null, new Object[]{null, 1}}; + final String[] srcs = { "x.0", "x[0]", "x[0][0]" }; final JexlContext ctxt = new MapContext(); @@ -89,7 +89,7 @@ public void tests301b() { @Test public void test302() { final JexlContext jc = new MapContext(); - final String[] strs = new String[]{ + final String[] strs = { "{if (0) 1 else 2; var x = 4;}", "if (0) 1; else 2; ", "{ if (0) 1; else 2; }", @@ -125,7 +125,7 @@ public void test304() { value = e304.evaluate(context); assertEquals(42, value); - final String[] keywords = new String[]{ + final String[] keywords = { "if", "else", "do", "while", "for", "break", "continue", "function", "return", "new", "size", "empty", "var", "let", "const", "null", "true", "false", @@ -133,15 +133,15 @@ public void test304() { "eq", "ne", "lt", "gt", "ge", "le", }; - for(int i = 0; i < keywords.length; ++i) { - String pkw = "e304." + keywords[i]; + for (final String keyword : keywords) { + final String pkw = "e304." + keyword; map.put(pkw, 42); e304 = jexlEngine.createExpression(pkw); value = e304.evaluate(context); assertEquals(42, value); } for(int i = 0; i < keywords.length; ++i) { - String pkw = "e304." + keywords[i] + "." + keywords[keywords.length - 1 - i]; + final String pkw = "e304." + keywords[i] + "." + keywords[keywords.length - 1 - i]; map.put(pkw, 42); e304 = jexlEngine.createExpression(pkw); value = e304.evaluate(context); @@ -390,10 +390,10 @@ public void test322a() { final JxltEngine jxlt = jexl.createJxltEngine(); final JexlContext context = new MapContext(); - final String[] ins = new String[]{ + final String[] ins = { "${'{'}", "${\"{\"}", "${\"{}\"}", "${'{42}'}", "${\"{\\\"\\\"}\"}" }; - final String[] ctls = new String[]{ + final String[] ctls = { "{", "{", "{}", "{42}", "{\"\"}" }; StringWriter strw; @@ -609,13 +609,13 @@ public void test347() { Assert.assertFalse((Boolean) result); jexl = new JexlBuilder().strict(true).safe(false).create(); - JexlContext ctxt = new MapContext(); + final JexlContext ctxt = new MapContext(); script = jexl.createScript(src); // A and A.B undefined try { result = script.execute(ctxt); Assert.fail("should only succeed with safe navigation"); - } catch (JexlException xany) { + } catch (final JexlException xany) { Assert.assertNotNull(xany); } // A is null, A.B is undefined @@ -623,7 +623,7 @@ public void test347() { try { result = script.execute(ctxt); Assert.fail("should only succeed with safe navigation"); - } catch (JexlException xany) { + } catch (final JexlException xany) { Assert.assertNotNull(xany); } // A.B is null @@ -634,10 +634,10 @@ public void test347() { @Test public void test349() { - String text = "(A ? C.D : E)"; - JexlEngine jexl = new JexlBuilder().safe(true).create(); - JexlExpression expr = jexl.createExpression(text); - JexlScript script = jexl.createScript(text); + final String text = "(A ? C.D : E)"; + final JexlEngine jexl = new JexlBuilder().safe(true).create(); + final JexlExpression expr = jexl.createExpression(text); + final JexlScript script = jexl.createScript(text); } static JexlContext pragmaticContext() { @@ -653,170 +653,170 @@ static JexlContext pragmaticContext() { + " ${$options.lexicalShade?'+':'-'}lexicalShade" + " ${$options.sharedInstance?'+':'-'}sharedInstance" + " ${$options.safe?'+':'-'}safe`"; - String text = "#pragma script.mode pro50\n" + + final String text = "#pragma script.mode pro50\n" + "()->{ ()->{ "+src0+"; } }"; - JexlEngine jexl = new JexlBuilder().safe(true).create(); - JexlScript script = jexl.createScript(text); + final JexlEngine jexl = new JexlBuilder().safe(true).create(); + final JexlScript script = jexl.createScript(text); JexlContext context = pragmaticContext(); - JexlScript closure = (JexlScript) script.execute(context); - JexlContext opts = new OptionsContext(); - Object result = closure.execute(opts); + final JexlScript closure = (JexlScript) script.execute(context); + final JexlContext opts = new OptionsContext(); + final Object result = closure.execute(opts); Assert.assertEquals("+strict +cancellable +lexical +lexicalShade -sharedInstance -safe", result); - String text0 = "#pragma script.mode pro50\n" + + final String text0 = "#pragma script.mode pro50\n" + "()->{ "+src0+"; }"; - JexlScript script0 = jexl.createScript(text0); + final JexlScript script0 = jexl.createScript(text0); context = pragmaticContext(); - Object result0 = script0.execute(context); + final Object result0 = script0.execute(context); Assert.assertEquals("+strict +cancellable +lexical +lexicalShade -sharedInstance -safe", result0); - String text1 = "#pragma script.mode pro50\n"+src0; - JexlScript script1 = jexl.createScript(text1); + final String text1 = "#pragma script.mode pro50\n"+src0; + final JexlScript script1 = jexl.createScript(text1); context = pragmaticContext(); - Object result1 = script1.execute(context); + final Object result1 = script1.execute(context); Assert.assertEquals("+strict +cancellable +lexical +lexicalShade -sharedInstance -safe", result1); - String text2 = src0; - JexlScript script2 = jexl.createScript(text2); + final String text2 = src0; + final JexlScript script2 = jexl.createScript(text2); context = pragmaticContext(); - Object result2 = script2.execute(context); + final Object result2 = script2.execute(context); Assert.assertEquals("-strict -cancellable -lexical -lexicalShade +sharedInstance +safe", result2); } @Test public void test361a_32() { - JexlEngine jexl = new Engine32(new JexlBuilder().safe(false)); - Object result = run361a(jexl); + final JexlEngine jexl = new Engine32(new JexlBuilder().safe(false)); + final Object result = run361a(jexl); Assert.assertNotNull(result); } @Test public void test361a_33() { - JexlEngine jexl = new JexlBuilder().safe(false).strict(true).create(); + final JexlEngine jexl = new JexlBuilder().safe(false).strict(true).create(); try { - Object result = run361a(jexl); + final Object result = run361a(jexl); Assert.fail("null arg should fail"); - } catch (JexlException xany) { + } catch (final JexlException xany) { Assert.assertNotNull(xany); } } - private Object run361a(JexlEngine jexl) { - String src = "()-> { ()-> { if (versionFile != null) { return 'foo'; } else { return 'bar'; }} }"; - JexlScript script = jexl.createScript(src); - Object result = script.execute(null); - JexlScript rs = (JexlScript) result; + private Object run361a(final JexlEngine jexl) { + final String src = "()-> { ()-> { if (versionFile != null) { return 'foo'; } else { return 'bar'; }} }"; + final JexlScript script = jexl.createScript(src); + final Object result = script.execute(null); + final JexlScript rs = (JexlScript) result; return rs.execute(null); } @Test public void test361b_33() { - JexlEngine jexl = new JexlBuilder().safe(false).strict(true).create(); + final JexlEngine jexl = new JexlBuilder().safe(false).strict(true).create(); try { - Object result = run361b(jexl); + final Object result = run361b(jexl); Assert.fail("null arg should fail"); - } catch (JexlException xany) { + } catch (final JexlException xany) { Assert.assertNotNull(xany); } } @Test public void test361b_32() { - JexlEngine jexl = new Engine32(new JexlBuilder().safe(false).strict(false)); - Object result = run361b(jexl); + final JexlEngine jexl = new Engine32(new JexlBuilder().safe(false).strict(false)); + final Object result = run361b(jexl); Assert.assertNotNull(result); } - private Object run361b(JexlEngine jexl) { - String src = "()-> { ()-> {" + + private Object run361b(final JexlEngine jexl) { + final String src = "()-> { ()-> {" + "var voa = vaf.value;\n" + "if (voa != NaN && voa <= 0)" + "{ return 'foo'; } else { return 'bar'; }" + "} }"; - JexlContext context = new MapContext(); - Map vaf = Collections.singletonMap("value", null); + final JexlContext context = new MapContext(); + final Map vaf = Collections.singletonMap("value", null); context.set("vaf", vaf); - JexlScript script = jexl.createScript(src); - Object result = script.execute(null); - JexlScript rs = (JexlScript) result; + final JexlScript script = jexl.createScript(src); + final Object result = script.execute(null); + final JexlScript rs = (JexlScript) result; return rs.execute(context); } @Test public void test361_33() { - JexlEngine jexl = new JexlBuilder().safe(false).strict(true).create(); + final JexlEngine jexl = new JexlBuilder().safe(false).strict(true).create(); try { run361c(jexl); Assert.fail("null arg should fail"); - } catch (JexlException xany) { + } catch (final JexlException xany) { Assert.assertNotNull(xany); } } @Test public void test361c_32() { - JexlEngine jexl = new Engine32(new JexlBuilder().safe(false).strict(false)); - String result = run361c(jexl); + final JexlEngine jexl = new Engine32(new JexlBuilder().safe(false).strict(false)); + final String result = run361c(jexl); Assert.assertNotNull(result); } - private String run361c(JexlEngine jexl) { - String src = "$$var t = null;\n" + + private String run361c(final JexlEngine jexl) { + final String src = "$$var t = null;\n" + "$$if (t < 0) {\n" + "'foo'\n" + "$$} else {\n" + "'bar'\n" + "$$}"; - JxltEngine jxlt = jexl.createJxltEngine(); - JexlContext context = new MapContext(); - Map vaf = Collections.singletonMap("value", null); + final JxltEngine jxlt = jexl.createJxltEngine(); + final JexlContext context = new MapContext(); + final Map vaf = Collections.singletonMap("value", null); context.set("vaf", vaf); - JxltEngine.Template template = jxlt.createTemplate(src); - StringWriter strw = new StringWriter(); + final JxltEngine.Template template = jxlt.createTemplate(src); + final StringWriter strw = new StringWriter(); template.evaluate(context, strw); return strw.toString(); } @Test public void test361d_32() { - JexlEngine jexl = new Engine32(new JexlBuilder().lexical(false).lexicalShade(false).safe(false)); - Object result = run361d(jexl); + final JexlEngine jexl = new Engine32(new JexlBuilder().lexical(false).lexicalShade(false).safe(false)); + final Object result = run361d(jexl); Assert.assertNotNull(result); } @Test public void test361d_33() { - JexlEngine jexl = new JexlBuilder().lexical(true).lexicalShade(true).safe(false).strict(true).create(); + final JexlEngine jexl = new JexlBuilder().lexical(true).lexicalShade(true).safe(false).strict(true).create(); try { - Object result = run361d(jexl); + final Object result = run361d(jexl); Assert.fail("null arg should fail"); - } catch (JexlException xany) { + } catch (final JexlException xany) { Assert.assertNotNull(xany); } } - private Object run361d(JexlEngine jexl) { - String src = "var foo = 42; var foo = 43;"; - JexlScript script = jexl.createScript(src); - Object result = script.execute(null); + private Object run361d(final JexlEngine jexl) { + final String src = "var foo = 42; var foo = 43;"; + final JexlScript script = jexl.createScript(src); + final Object result = script.execute(null); return result; } @Test public void test367() { - String text = "var toto; function foo(x) { x }; var tata = 3; foo(3)"; - JexlEngine jexl = new JexlBuilder().safe(true).create(); - JexlScript script = jexl.createScript(text); - Object result = script.execute(null); + final String text = "var toto; function foo(x) { x }; var tata = 3; foo(3)"; + final JexlEngine jexl = new JexlBuilder().safe(true).create(); + final JexlScript script = jexl.createScript(text); + final Object result = script.execute(null); Assert.assertEquals(3, result); - String s0 = script.getParsedText(); - String s1 = script.getSourceText(); + final String s0 = script.getParsedText(); + final String s1 = script.getSourceText(); Assert.assertNotEquals(s0, s1); } public static class Var370 { private String name = null; - public void setName(String s) { + public void setName(final String s) { name = s; } public String getName() { @@ -825,9 +825,9 @@ public String getName() { } @Test public void test370() { - Var370 var370 = new Var370(); - JexlEngine jexl = new JexlBuilder().safe(true).create(); - ObjectContext ctxt = new ObjectContext<>(jexl, var370); + final Var370 var370 = new Var370(); + final JexlEngine jexl = new JexlBuilder().safe(true).create(); + final ObjectContext ctxt = new ObjectContext<>(jexl, var370); JexlExpression get = jexl.createExpression("name"); // not null var370.setName("John"); @@ -843,7 +843,7 @@ public String getName() { try { get.evaluate(ctxt); Assert.fail("phone should be undefined!"); - } catch (JexlException.Variable xvar) { + } catch (final JexlException.Variable xvar) { Assert.assertEquals("phone", xvar.getVariable()); } } @@ -854,31 +854,31 @@ public static class TestObject374 { public String getName() { return name; } - public void setName(String pName) { + public void setName(final String pName) { this.name = pName; } public TestObject374 getNested() { return nested; } - public void setNested(TestObject374 pNested) { + public void setNested(final TestObject374 pNested) { nested = pNested; } } @Test public void test374() { - JexlEngine engine = new JexlBuilder().cache(512).strict(true).silent(false).antish(false).safe(false).create(); + final JexlEngine engine = new JexlBuilder().cache(512).strict(true).silent(false).antish(false).safe(false).create(); // Create expression to evaluate 'name' - JexlExpression expr = engine.createExpression("nested.name"); + final JexlExpression expr = engine.createExpression("nested.name"); // Create an object with getter for name - TestObject374 myObject = new TestObject374(); + final TestObject374 myObject = new TestObject374(); myObject.setName("John"); - JexlContext context = new ObjectContext<>(engine, myObject); + final JexlContext context = new ObjectContext<>(engine, myObject); // Expect an exception because nested is null, so we are doing null.name try { - Object result = expr.evaluate(context); + final Object result = expr.evaluate(context); Assert.fail("An exception expected, but got: " + result); - } catch (JexlException ex) { + } catch (final JexlException ex) { // Expected //ex.printStackTrace(); } @@ -886,11 +886,11 @@ public void test374() { @Test public void test375() { - JexlSandbox jexlSandbox = new JexlSandbox(false); + final JexlSandbox jexlSandbox = new JexlSandbox(false); jexlSandbox.allow(Type375.class.getName()); - JexlEngine engine = new JexlBuilder().sandbox(jexlSandbox).create(); + final JexlEngine engine = new JexlBuilder().sandbox(jexlSandbox).create(); - JexlContext context = new MapContext(); + final JexlContext context = new MapContext(); context.set("Type", Type375.class); Object result = engine.createScript("Type.valueOf('DOMICILE')").execute(context); @@ -908,10 +908,10 @@ public enum Type375 { @Test public void test377() { - String text = "function add(x, y) { x + y } add(a, b)"; - JexlEngine jexl = new JexlBuilder().safe(true).create(); - JexlScript script = jexl.createScript(text, "a", "b"); - Object result = script.execute(null, 20, 22); + final String text = "function add(x, y) { x + y } add(a, b)"; + final JexlEngine jexl = new JexlBuilder().safe(true).create(); + final JexlScript script = jexl.createScript(text, "a", "b"); + final Object result = script.execute(null, 20, 22); Assert.assertEquals(42, result); } @@ -920,10 +920,10 @@ public void test379a() { final String src = "#pragma jexl.import java.util\n"+ "const map = new LinkedHashMap({0 : 'zero'});"; - JexlEngine jexl = new JexlBuilder().safe(true).create(); - JexlScript script = jexl.createScript(src); + final JexlEngine jexl = new JexlBuilder().safe(true).create(); + final JexlScript script = jexl.createScript(src); Assert.assertNotNull(script); - Object result = script.execute(null); + final Object result = script.execute(null); Assert.assertNotNull(result); Assert.assertTrue(result instanceof LinkedHashMap); Assert.assertEquals(1, ((Map) result).size()); @@ -932,24 +932,24 @@ public void test379a() { @Test public void test373b() { final String src = "var i = ++1"; - JexlEngine jexl = new JexlBuilder().safe(true).create(); - JexlInfo info = new JexlInfo("badscript", 0, 0); + final JexlEngine jexl = new JexlBuilder().safe(true).create(); + final JexlInfo info = new JexlInfo("badscript", 0, 0); try { - JexlScript script = jexl.createScript(info, src); + final JexlScript script = jexl.createScript(info, src); Assert.fail("should not parse"); - } catch (JexlException.Parsing xparse) { - String msg = xparse.getMessage(); + } catch (final JexlException.Parsing xparse) { + final String msg = xparse.getMessage(); Assert.assertTrue(msg.contains("badscript")); } } @Test public void testBackslashes() throws Exception { - JexlEngine jexl = new JexlBuilder().safe(false).create(); - String src = "\"\b\t\f\""; + final JexlEngine jexl = new JexlBuilder().safe(false).create(); + final String src = "\"\b\t\f\""; JexlScript s = jexl.createScript(src); Assert.assertNotNull(s); - String ctl = "\b\t\f"; + final String ctl = "\b\t\f"; Assert.assertEquals(ctl, s.execute(null)); String parsed = s.getParsedText(); Assert.assertEquals("'\\b\\t\\f'", parsed); @@ -964,8 +964,8 @@ public void testBackslashes() throws Exception { * Mock driver. */ public static class Driver0930 { - private String name; - Driver0930(String n) { + private final String name; + Driver0930(final String n) { name = n; } public String getAttributeName() { @@ -980,7 +980,7 @@ public static class Context0930 extends MapContext { * @param filter the lambda to use as filter * @return the filtered stream */ - public Stream filter(Stream stream, JexlScript filter) { + public Stream filter(final Stream stream, final JexlScript filter) { return stream.filter(x -> Boolean.TRUE.equals(filter.execute(this, x))); } } @@ -988,7 +988,7 @@ public Stream filter(Stream stream, JexlScript filter) { @Test public void testSO20220930() { // fill some drivers in a list - List values = new ArrayList<>(); + final List values = new ArrayList<>(); for(int i = 0; i < 8; ++i) { values.add(new Driver0930("drvr" + Integer.toOctalString(i))); } @@ -996,34 +996,34 @@ public void testSO20220930() { values.add(new Driver0930("favorite" + Integer.toOctalString(i))); } // Use a context that can filter and that exposes Collectors - JexlEngine jexl = new JexlBuilder().safe(false).create(); - JexlContext context = new Context0930(); + final JexlEngine jexl = new JexlBuilder().safe(false).create(); + final JexlContext context = new Context0930(); context.set("values", values); context.set("Collectors", Collectors.class); // The script with a JEXL 3.2 (lambda function) and 3.3 syntax (lambda expression) - String src32 = "values.stream().filter((driver) ->{ driver.attributeName =^ 'favorite' }).collect(Collectors.toList())"; - String src33 = "values.stream().filter(driver -> driver.attributeName =^ 'favorite').collect(Collectors.toList())"; - for(String src : Arrays.asList(src32, src33)) { - JexlExpression s = jexl.createExpression(src); + final String src32 = "values.stream().filter((driver) ->{ driver.attributeName =^ 'favorite' }).collect(Collectors.toList())"; + final String src33 = "values.stream().filter(driver -> driver.attributeName =^ 'favorite').collect(Collectors.toList())"; + for(final String src : Arrays.asList(src32, src33)) { + final JexlExpression s = jexl.createExpression(src); Assert.assertNotNull(s); - Object r = s.evaluate(context); + final Object r = s.evaluate(context); Assert.assertNotNull(r); // got a filtered list of 4 drivers whose attribute name starts with 'favorite' - List l = (List) r; + final List l = (List) r; Assert.assertEquals(4, l.size()); - for (Driver0930 d : l) { + for (final Driver0930 d : l) { Assert.assertTrue(d.getAttributeName().startsWith("favorite")); } } } public static class Arithmetic383 extends JexlArithmetic { - public Arithmetic383(boolean astrict) { + public Arithmetic383(final boolean astrict) { super(astrict); } @Override - public boolean isStrict(JexlOperator op) { + public boolean isStrict(final JexlOperator op) { switch(op) { case NOT: case CONDITION: @@ -1034,9 +1034,9 @@ public boolean isStrict(JexlOperator op) { } @Test public void test383() { - JexlEngine jexl = new JexlBuilder().safe(false).arithmetic(new Arithmetic383(true)).create(); - String src0 = "if (a) 1; else 2;"; - String src1 = "if (!a) 1; else 2;"; + final JexlEngine jexl = new JexlBuilder().safe(false).arithmetic(new Arithmetic383(true)).create(); + final String src0 = "if (a) 1; else 2;"; + final String src1 = "if (!a) 1; else 2;"; // local var JexlScript s0 = jexl.createScript(src0, "a"); JexlScript s1 = jexl.createScript(src1, "a"); @@ -1047,28 +1047,28 @@ public boolean isStrict(JexlOperator op) { s1 = jexl.createScript(src1); try { Assert.assertEquals(2, s0.execute(null, (Object) null)); - } catch (JexlException.Variable xvar) { + } catch (final JexlException.Variable xvar) { Assert.assertEquals("a", xvar.getVariable()); } try { Assert.assertEquals(1, s1.execute(null, (Object) null)); - } catch (JexlException.Variable xvar) { + } catch (final JexlException.Variable xvar) { Assert.assertEquals("a", xvar.getVariable()); } // global var null - MapContext ctxt = new MapContext(); + final MapContext ctxt = new MapContext(); ctxt.set("a", null); Assert.assertEquals(2, s0.execute(ctxt, (Object) null)); Assert.assertEquals(1, s1.execute(ctxt, (Object) null)); } public static class Arithmetic384 extends JexlArithmetic { - public Arithmetic384(boolean astrict) { + public Arithmetic384(final boolean astrict) { super(astrict); } @Override - public boolean isStrict(JexlOperator op) { + public boolean isStrict(final JexlOperator op) { if (JexlOperator.ADD == op) { return false; } @@ -1077,29 +1077,29 @@ public boolean isStrict(JexlOperator op) { } @Test public void test384a() { - JexlEngine jexl = new JexlBuilder() + final JexlEngine jexl = new JexlBuilder() .safe(false) .strict(true) .create(); // constant - for(String src0 : Arrays.asList("'ABC' + null", "null + 'ABC'")) { - JexlContext ctxt = new MapContext(); - JexlScript s0 = jexl.createScript(src0); + for(final String src0 : Arrays.asList("'ABC' + null", "null + 'ABC'")) { + final JexlContext ctxt = new MapContext(); + final JexlScript s0 = jexl.createScript(src0); try { s0.execute(ctxt, (Object) null); Assert.fail("null argument should throw"); - } catch (JexlException xvar) { + } catch (final JexlException xvar) { Assert.assertTrue(xvar.toString().contains("+")); } } // null local a - for(String src1 : Arrays.asList("'ABC' + a", "a + 'ABC'")) { - JexlContext ctxt = new MapContext(); + for(final String src1 : Arrays.asList("'ABC' + a", "a + 'ABC'")) { + final JexlContext ctxt = new MapContext(); JexlScript s1 = jexl.createScript(src1, "a"); try { s1.execute(ctxt, (Object) null); Assert.fail("null argument should throw"); - } catch (JexlException.Variable xvar) { + } catch (final JexlException.Variable xvar) { Assert.assertEquals("a", xvar.getVariable()); } // undefined a @@ -1107,7 +1107,7 @@ public void test384a() { try { s1.execute(ctxt, (Object) null); Assert.fail("null argument should throw"); - } catch (JexlException.Variable xvar) { + } catch (final JexlException.Variable xvar) { Assert.assertEquals("a", xvar.getVariable()); Assert.assertTrue(xvar.isUndefined()); } @@ -1116,7 +1116,7 @@ public void test384a() { try { s1.execute(ctxt, (Object) null); Assert.fail("null argument should throw"); - } catch (JexlException.Variable xvar) { + } catch (final JexlException.Variable xvar) { Assert.assertEquals("a", xvar.getVariable()); Assert.assertFalse(xvar.isUndefined()); } @@ -1125,20 +1125,20 @@ public void test384a() { @Test public void test384b() { // be explicit about + handling null - JexlEngine jexl = new JexlBuilder() + final JexlEngine jexl = new JexlBuilder() .arithmetic(new Arithmetic384(true)) .safe(false) .strict(true) .create(); // constant - for(String src0 : Arrays.asList("'ABC' + null", "null + 'ABC'")) { - JexlContext ctxt = new MapContext(); - JexlScript s0 = jexl.createScript(src0); + for(final String src0 : Arrays.asList("'ABC' + null", "null + 'ABC'")) { + final JexlContext ctxt = new MapContext(); + final JexlScript s0 = jexl.createScript(src0); Assert.assertEquals("ABC", s0.execute(ctxt)); } // null local a - for(String src1 : Arrays.asList("'ABC' + a", "a + 'ABC'")) { - JexlContext ctxt = new MapContext(); + for(final String src1 : Arrays.asList("'ABC' + a", "a + 'ABC'")) { + final JexlContext ctxt = new MapContext(); JexlScript s1 = jexl.createScript(src1, "a"); Assert.assertEquals("ABC", s1.execute(ctxt, (Object) null)); // undefined a @@ -1146,7 +1146,7 @@ public void test384b() { try { s1.execute(ctxt, (Object) null); Assert.fail("null argument should throw"); - } catch (JexlException.Variable xvar) { + } catch (final JexlException.Variable xvar) { Assert.assertEquals("a", xvar.getVariable()); Assert.assertTrue(xvar.isUndefined()); } @@ -1168,12 +1168,12 @@ public void test390() throws Exception { try { script = jexl.createScript(src); Assert.fail("should have failed parsing"); - } catch (JexlException.Parsing xparse) { + } catch (final JexlException.Parsing xparse) { Assert.assertTrue(xparse.getDetail().contains("pragma")); } src = "if (true) { #pragma one 42 }"; script = jexl.createScript(src); - Object result = script.execute(null); + final Object result = script.execute(null); debuggerCheck(jexl); } @@ -1182,32 +1182,32 @@ public static class Arithmetic384c extends JexlArithmetic { int getCmpCalls() { return cmp.get(); } - public Arithmetic384c(boolean astrict) { + public Arithmetic384c(final boolean astrict) { super(astrict); } - public Arithmetic384c(boolean astrict, MathContext bigdContext, int bigdScale) { + public Arithmetic384c(final boolean astrict, final MathContext bigdContext, final int bigdScale) { super(astrict, bigdContext, bigdScale); } @Override - protected int compare(Object l, Object r, String op) { + protected int compare(final Object l, final Object r, final String op) { cmp.incrementAndGet(); return super.compare(l, r, op); } } public static class Arithmetic384d extends Arithmetic384c { - public Arithmetic384d(boolean astrict) { + public Arithmetic384d(final boolean astrict) { super(astrict); } - public Arithmetic384d(boolean astrict, MathContext bigdContext, int bigdScale) { + public Arithmetic384d(final boolean astrict, final MathContext bigdContext, final int bigdScale) { super(astrict, bigdContext, bigdScale); } } @Test public void test384c() { - Arithmetic384c ja = new Arithmetic384c(true); - JexlEngine jexl = new JexlBuilder() + final Arithmetic384c ja = new Arithmetic384c(true); + final JexlEngine jexl = new JexlBuilder() .safe(false) .strict(true) .arithmetic(ja) @@ -1223,8 +1223,8 @@ public void test384c() { @Test public void test384d() { - Arithmetic384c ja = new Arithmetic384d(true); - JexlEngine jexl = new JexlBuilder() + final Arithmetic384c ja = new Arithmetic384d(true); + final JexlEngine jexl = new JexlBuilder() .safe(false) .strict(true) .arithmetic(ja) @@ -1240,32 +1240,32 @@ public void test384d() { @Test public void test393() { - String src = "const total = 0;\n" + + final String src = "const total = 0;\n" + "if (true) {\n" + " total = 1;\n" + "}\n" + "total; "; - JexlEngine jexl = new JexlBuilder() + final JexlEngine jexl = new JexlBuilder() .safe(false) .strict(true) .create(); try { - JexlScript script = jexl.createScript(src); + final JexlScript script = jexl.createScript(src); Assert.fail("should fail on const total assignment"); - } catch (JexlException.Parsing xparse) { + } catch (final JexlException.Parsing xparse) { Assert.assertTrue(xparse.getMessage().contains("total")); } } @Test public void testDow() { - String src = "(y, m, d)->{\n" + + final String src = "(y, m, d)->{\n" + "// will return 0 for Sunday, 6 for Saturday\n" + "const t = [0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4];\n"+ "if (m < 3) { --y }\n" + "(y + y/4 - y/100 + y/400 + t[m-1] + d) % 7;\n" + "}"; - JexlEngine jexl = new JexlBuilder().create(); - JexlScript script = jexl.createScript(src); + final JexlEngine jexl = new JexlBuilder().create(); + final JexlScript script = jexl.createScript(src); Object r = script.execute(null, 2023, 3, 1); Assert.assertTrue(r instanceof Number); Number dow = (Number) r; @@ -1277,12 +1277,12 @@ public void test393() { } @Test public void testIssue394() { - StringBuilder x = new StringBuilder("foobar"); + final StringBuilder x = new StringBuilder("foobar"); Assert.assertEquals("foobar", x.toString()); - String src = "x -> x.setLength(3)"; - JexlEngine jexl = new JexlBuilder().create(); - JexlScript script = jexl.createScript(src); - Object result = script.execute(null, x); + final String src = "x -> x.setLength(3)"; + final JexlEngine jexl = new JexlBuilder().create(); + final JexlScript script = jexl.createScript(src); + final Object result = script.execute(null, x); Assert.assertEquals("foo", x.toString()); } @@ -1306,15 +1306,15 @@ T createProxy(final JexlEngine jexl, final Object o, final Class[] clazzz) { final String control = Class397.class.getName(); final JexlEngine jexl = new JexlBuilder().permissions(RESTRICTED).create(); - Interface397i instance = new Class397(); + final Interface397i instance = new Class397(); result = (String) jexl.invokeMethod(instance, "summary"); Assert.assertEquals(control, result); - Interface397i proxy = createProxy(jexl, instance, new Class[] { Interface397i.class }) ; + final Interface397i proxy = createProxy(jexl, instance, new Class[] { Interface397i.class }) ; result = (String) jexl.invokeMethod(proxy, "summary"); Assert.assertEquals(control, result); - JexlScript script = jexl.createScript("dan.summary()", "dan"); + final JexlScript script = jexl.createScript("dan.summary()", "dan"); result = (String) script.execute(null, instance); Assert.assertEquals(control, result); result = (String) script.execute(null, proxy); @@ -1324,7 +1324,7 @@ T createProxy(final JexlEngine jexl, final Object o, final Class[] clazzz) { @Test public void testUnsolvableMethod() throws Exception { final JexlEngine jexl = new JexlBuilder().create(); - JexlScript script = jexl.createScript( + final JexlScript script = jexl.createScript( "var myFunction1 = function(object) {" + " myNonExistentFunction();" + "}" @@ -1342,15 +1342,15 @@ public void testUnsolvableMethod() throws Exception { @Test public void testIssue398() { - String src = "let m = {\n" + + final String src = "let m = {\n" + " \"foo\": 1,\n" + " \"bar\": 2,\n" + "}"; final JexlEngine jexl = new JexlBuilder().create(); - JexlScript script = jexl.createScript(src); - Object result = script.execute(null); + final JexlScript script = jexl.createScript(src); + final Object result = script.execute(null); Assert.assertTrue(result instanceof Map); - Map map = (Map) result; + final Map map = (Map) result; Assert.assertEquals(2, map.size()); } } diff --git a/src/test/java/org/apache/commons/jexl3/Issues400Test.java b/src/test/java/org/apache/commons/jexl3/Issues400Test.java index 70be9f193..863d3b0e1 100644 --- a/src/test/java/org/apache/commons/jexl3/Issues400Test.java +++ b/src/test/java/org/apache/commons/jexl3/Issues400Test.java @@ -16,30 +16,11 @@ */ package org.apache.commons.jexl3; -import org.apache.commons.jexl3.internal.Engine32; -import org.apache.commons.jexl3.internal.OptionsContext; -import static org.apache.commons.jexl3.introspection.JexlPermissions.RESTRICTED; -import org.apache.commons.jexl3.introspection.JexlSandbox; import org.junit.Assert; import org.junit.Test; -import java.io.StringReader; -import java.io.StringWriter; -import java.lang.reflect.Proxy; -import java.math.MathContext; -import java.util.ArrayList; -import java.util.Arrays; import java.util.Collections; -import java.util.HashMap; -import java.util.LinkedHashMap; -import java.util.List; import java.util.Map; -import java.util.concurrent.atomic.AtomicInteger; -import java.util.stream.Collectors; -import java.util.stream.Stream; - -import static org.apache.commons.jexl3.internal.Util.debuggerCheck; -import static org.junit.Assert.assertEquals; /** * Test cases for reported issue between JEXL-300 and JEXL-399. @@ -49,7 +30,7 @@ public class Issues400Test { @Test public void test402() { final JexlContext jc = new MapContext(); - final String[] sources = new String[]{ + final String[] sources = { "if (true) { return }", "if (true) { 3; return }", "(x->{ 3; return })()" @@ -64,12 +45,12 @@ public void test402() { @Test public void test403() { - for(String setmap : new String[]{ + for(final String setmap : new String[]{ " map1.`${item.a}` = 1;\n", " map1[`${item.a}`] = 1;\n", " map1[item.a] = 1;\n" }) { - String src = "var a = {'a': 1};\n" + + final String src = "var a = {'a': 1};\n" + "var list = [a, a];\n" + "let map1 = {:};\n" + "for (var item : list) {\n" + @@ -77,11 +58,11 @@ public void test403() { "}\n " + "map1"; final JexlEngine jexl = new JexlBuilder().cache(64).create(); - JexlScript script = jexl.createScript(src); + final JexlScript script = jexl.createScript(src); for (int i = 0; i < 2; ++i) { - Object result = script.execute(null); + final Object result = script.execute(null); Assert.assertTrue(result instanceof Map); - Map map = (Map) result; + final Map map = (Map) result; Assert.assertEquals(1, map.size()); Assert.assertTrue(map.containsKey(1)); Assert.assertTrue(map.containsValue(1)); @@ -98,32 +79,32 @@ public void test404a() { .create(); Map a = Collections.singletonMap("b", 42); // access is constant - for(String src : new String[]{ "a.b", "a?.b", "a['b']", "a?['b']", "a?.`b`"}) { + for(final String src : new String[]{ "a.b", "a?.b", "a['b']", "a?['b']", "a?.`b`"}) { run404(jexl, src, a); run404(jexl, src + ";", a); } // access is variable - for(String src : new String[]{ "a[b]", "a?[b]", "a?.`${b}`"}) { + for(final String src : new String[]{ "a[b]", "a?[b]", "a?.`${b}`"}) { run404(jexl, src, a, "b"); run404(jexl, src + ";", a, "b"); } // add a 3rd access - Map b = Collections.singletonMap("c", 42); + final Map b = Collections.singletonMap("c", 42); a = Collections.singletonMap("b", b); - for(String src : new String[]{ "a[b].c", "a?[b]?['c']", "a?.`${b}`.c"}) { + for(final String src : new String[]{ "a[b].c", "a?[b]?['c']", "a?.`${b}`.c"}) { run404(jexl, src, a, "b"); } } - private static void run404(JexlEngine jexl, String src, Object...a) { + private static void run404(final JexlEngine jexl, final String src, final Object...a) { try { - JexlScript script = jexl.createScript(src, "a", "b"); + final JexlScript script = jexl.createScript(src, "a", "b"); if (!src.endsWith(";")) { Assert.assertEquals(script.getSourceText(), script.getParsedText()); } - Object result = script.execute(null, a); + final Object result = script.execute(null, a); Assert.assertEquals(42, result); - } catch(JexlException.Parsing xparse) { + } catch(final JexlException.Parsing xparse) { Assert.fail(src); } } @@ -135,8 +116,8 @@ public void test404b() { .strict(true) .safe(false) .create(); - Map b = Collections.singletonMap("c", 42); - Map a = Collections.singletonMap("b", b); + final Map b = Collections.singletonMap("c", 42); + final Map a = Collections.singletonMap("b", b); JexlScript script; Object result = -42; script = jexl.createScript("a?['B']?['C']", "a"); diff --git a/src/test/java/org/apache/commons/jexl3/JXLTTest.java b/src/test/java/org/apache/commons/jexl3/JXLTTest.java index 42b573c48..d61a07d5a 100644 --- a/src/test/java/org/apache/commons/jexl3/JXLTTest.java +++ b/src/test/java/org/apache/commons/jexl3/JXLTTest.java @@ -146,7 +146,7 @@ public void testStatement() throws Exception { context.set("froboz", froboz); final JxltEngine.Expression check = JXLT.createExpression("${ froboz.plus10() }"); final Object o = check.evaluate(context); - Assert.assertEquals("Result is not 32", new Integer(32), o); + Assert.assertEquals("Result is not 32", Integer.valueOf(32), o); Assert.assertEquals("Result is not 42", 42, froboz.getValue()); final Set> evars = check.getVariables(); Assert.assertEquals(1, evars.size()); @@ -159,9 +159,9 @@ public void testAssign() throws Exception { final JxltEngine.Expression assign = JXLT.createExpression("${froboz.value = 42}"); final JxltEngine.Expression check = JXLT.createExpression("${froboz.value}"); Object o = assign.evaluate(context); - Assert.assertEquals("Result is not 10", new Integer(42), o); + Assert.assertEquals("Result is not 10", Integer.valueOf(42), o); o = check.evaluate(context); - Assert.assertEquals("Result is not 10", new Integer(42), o); + Assert.assertEquals("Result is not 10", Integer.valueOf(42), o); } @Test @@ -778,7 +778,7 @@ public void testInterpolationLvsG2() throws Exception { @Test public void testInterpolationParameter() throws Exception { final String expr = "(user)->{`Hello \n${user}`}"; - JexlScript script = ENGINE.createScript(expr); + final JexlScript script = ENGINE.createScript(expr); Object value = script.execute(context, "Henrib"); Assert.assertEquals(expr, "Hello \nHenrib", value); value = ENGINE.createScript(expr).execute(context, "Dimitri"); @@ -787,18 +787,18 @@ public void testInterpolationParameter() throws Exception { @Test public void testDbgEscapes() throws Exception { - String[] srcs = new String[]{ + final String[] srcs = { "jexl:print('hello\\'\\nworld')", "'hello\\tworld'", "'hello\\nworld'", "'hello\\fworld'", "'hello\\rworld'" }; - for(String src : srcs) { - JexlScript script = ENGINE.createScript(src); - Debugger dbg = new Debugger(); + for(final String src : srcs) { + final JexlScript script = ENGINE.createScript(src); + final Debugger dbg = new Debugger(); dbg.debug(script); - String msrc = dbg.toString(); + final String msrc = dbg.toString(); Assert.assertEquals(src, msrc); } } @@ -1035,7 +1035,7 @@ public void testLexicalTemplate() throws Exception { final Writer strw0 = new StringWriter(); tmplt0.evaluate(ctxt, strw0); final String output0 = strw0.toString(); - JexlFeatures features = BUILDER.features(); + final JexlFeatures features = BUILDER.features(); if (features != null && features.isLexical() && features.isLexicalShade()) { Assert.assertEquals("-strict -cancellable +lexical +lexicalShade +safe", output0); } else { @@ -1155,7 +1155,7 @@ public void testCommentedTemplate1() throws Exception { @Test public void testConstantTemplate() { - String src = "