Skip to content

Commit

Permalink
Javadoc, comments, formatting tidbits
Browse files Browse the repository at this point in the history
  • Loading branch information
Henri Biestro committed Oct 18, 2023
1 parent 41d6999 commit 891a6d7
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 17 deletions.
9 changes: 6 additions & 3 deletions src/main/java/org/apache/commons/jexl3/JexlArithmetic.java
Original file line number Diff line number Diff line change
Expand Up @@ -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)));
}

/**
Expand Down
20 changes: 10 additions & 10 deletions src/main/java/org/apache/commons/jexl3/internal/Debugger.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -897,7 +897,9 @@ private static void writePragmas(final StringBuilder builder, final Map<String,
for (final Map.Entry<String, Object> pragma : pragmas.entrySet()) {
final String key = pragma.getKey();
final Object value = pragma.getValue();
final Set<Object> values = value instanceof Set ? (Set) value : Collections.singleton(value);
final Set<Object> values = value instanceof Set<?>
? (Set<Object>) value
: Collections.singleton(value);
for (final Object pragmaValue : values) {
builder.append("#pragma ");
builder.append(key);
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
}

/**
Expand Down Expand Up @@ -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);
}

Expand Down

0 comments on commit 891a6d7

Please sign in to comment.