From 891a6d7d3f7afd8c1d14581c21fc589c56190e6b Mon Sep 17 00:00:00 2001 From: Henri Biestro Date: Wed, 18 Oct 2023 15:31:12 +0200 Subject: [PATCH] Javadoc, comments, formatting tidbits --- .../apache/commons/jexl3/JexlArithmetic.java | 9 ++++++--- .../commons/jexl3/internal/Debugger.java | 20 +++++++++---------- .../jexl3/introspection/JexlPermissions.java | 9 +++++---- 3 files changed, 21 insertions(+), 17 deletions(-) diff --git a/src/main/java/org/apache/commons/jexl3/JexlArithmetic.java b/src/main/java/org/apache/commons/jexl3/JexlArithmetic.java index f92a02747..fc6ad8a4c 100644 --- a/src/main/java/org/apache/commons/jexl3/JexlArithmetic.java +++ b/src/main/java/org/apache/commons/jexl3/JexlArithmetic.java @@ -1393,9 +1393,12 @@ 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)); + // Some bits greater than 2^31 that might cause overflow + // Check the result using the divide operator + // and check for the special case of Long.MIN_VALUE * -1 + return !(((ax | ay) >>> (Integer.SIZE - 1) != 0) + && ((y != 0 && r / y != x) + || (x == Long.MIN_VALUE && y == -1))); } /** diff --git a/src/main/java/org/apache/commons/jexl3/internal/Debugger.java b/src/main/java/org/apache/commons/jexl3/internal/Debugger.java index b0683ecea..710cae8d2 100644 --- a/src/main/java/org/apache/commons/jexl3/internal/Debugger.java +++ b/src/main/java/org/apache/commons/jexl3/internal/Debugger.java @@ -439,7 +439,7 @@ protected Object acceptStatement(final JexlNode child, final Object data) { /** * Checks if a terminal node is the cause to debug & adds its representation to the rebuilt expression. * @param node the child node - * @param image the child node token image (may be null) + * @param image the child node token image (optionally null) * @param data visitor pattern argument * @return visitor pattern value */ @@ -802,7 +802,7 @@ protected Object visit(final ASTGTNode node, final Object data) { * (but underscore, at-sign, sharp-sign and dollar). */ protected static final Pattern QUOTED_IDENTIFIER = - Pattern.compile("[\\s]|[\\p{Punct}&&[^@#$_]]"); + Pattern.compile("\\s|\\p{Punct}&&[^@#$_]"); /** * Checks whether an identifier should be quoted or not. @@ -897,7 +897,9 @@ private static void writePragmas(final StringBuilder builder, final Map pragma : pragmas.entrySet()) { final String key = pragma.getKey(); final Object value = pragma.getValue(); - final Set values = value instanceof Set ? (Set) value : Collections.singleton(value); + final Set values = value instanceof Set + ? (Set) value + : Collections.singleton(value); for (final Object pragmaValue : values) { builder.append("#pragma "); builder.append(key); @@ -1054,8 +1056,6 @@ protected Object visit(final ASTConstructorNode node, final Object data) { for (int i = 1; i < num; ++i) { if (!first) { builder.append(", "); - } else { - first = true; } accept(node.jjtGetChild(i), data); } @@ -1275,15 +1275,15 @@ protected Object visit(final ASTDefineVars node, final Object data) { if (child instanceof ASTAssignment) { final ASTAssignment assign = (ASTAssignment) child; final int nc = assign.jjtGetNumChildren(); - final ASTVar var = (ASTVar) assign.jjtGetChild(0); - builder.append(var.getName()); + final ASTVar avar = (ASTVar) assign.jjtGetChild(0); + builder.append(avar.getName()); if (nc > 1) { builder.append(" = "); accept(assign.jjtGetChild(1), data); } } else if (child instanceof ASTVar) { - final ASTVar var = (ASTVar) child; - builder.append(var.getName()); + final ASTVar avar = (ASTVar) child; + builder.append(avar.getName()); } else { // that's odd accept(child, data); @@ -1411,7 +1411,7 @@ protected Object visit(final ASTAnnotation node, final Object data) { protected Object visit(final ASTAnnotatedStatement node, final Object data) { final int num = node.jjtGetNumChildren(); for (int i = 0; i < num; ++i) { - if (i > 0) {// && child instanceof ASTBlock) { + if (i > 0) { builder.append(' '); } final JexlNode child = node.jjtGetChild(i); 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 19a8b2e4e..ee0b67eb2 100644 --- a/src/main/java/org/apache/commons/jexl3/introspection/JexlPermissions.java +++ b/src/main/java/org/apache/commons/jexl3/introspection/JexlPermissions.java @@ -392,10 +392,11 @@ 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(final Class... allow) { + public ClassPermissions(final Class... allow) { this(JexlPermissions.RESTRICTED, - Arrays.asList(Objects.requireNonNull(allow)) - .stream().map(Class::getCanonicalName).collect(Collectors.toList())); + Arrays.stream(Objects.requireNonNull(allow)) + .map(Class::getCanonicalName) + .collect(Collectors.toList())); } /** @@ -423,7 +424,7 @@ public boolean allow(final Method method) { } @Override - public boolean allow(final Constructor constructor) { + public boolean allow(final Constructor constructor) { return validate(constructor) && isClassAllowed(constructor.getDeclaringClass()) || super.allow(constructor); }