Skip to content

Commit

Permalink
throw a NPE when trying to perform an operation on a null BigDecimal
Browse files Browse the repository at this point in the history
  • Loading branch information
mariofusco committed Dec 8, 2021
1 parent 3fa407d commit 42b8ac5
Show file tree
Hide file tree
Showing 6 changed files with 209 additions and 265 deletions.
28 changes: 11 additions & 17 deletions src/main/java/org/mvel2/ast/BinaryOperation.java
Expand Up @@ -22,6 +22,7 @@
import java.math.BigInteger;

import org.mvel2.CompileException;
import org.mvel2.DataTypes;
import org.mvel2.Operator;
import org.mvel2.ParserContext;
import org.mvel2.ScriptRuntimeException;
Expand Down Expand Up @@ -85,7 +86,7 @@ public BinaryOperation(int operation, ASTNode left, ASTNode right, ParserContext

if (right.isLiteral() && requiresConversion && canConvert(left.getEgressType(), right.getEgressType())) {
Class targetType = isAritmeticOperation(operation) ? egressType : left.getEgressType();
this.right = new LiteralNode(convert(right.getReducedValueAccelerated(null, null, null), targetType), pCtx);
this.right = new LiteralNode(convert(right.getReducedValueAccelerated(null, null, null), targetType), targetType, pCtx);
} else if ( !(areCompatible(left.getEgressType(), right.getEgressType()) ||
(( operation == Operator.EQUAL || operation == Operator.NEQUAL) &&
CompatibilityStrategy.areEqualityCompatible(left.getEgressType(), right.getEgressType()))) ) {
Expand All @@ -98,14 +99,19 @@ public BinaryOperation(int operation, ASTNode left, ASTNode right, ParserContext
}
}

if (this.left.isLiteral() && this.right.isLiteral()) {
if (this.left.egressType == this.right.egressType) {
lType = rType = ParseTools.__resolveType(left.egressType);
lType = rType = getOperandType(this.left);
} else {
lType = ParseTools.__resolveType(this.left.egressType);
rType = ParseTools.__resolveType(this.right.egressType);
lType = getOperandType(this.left);
rType = getOperandType(this.right);
}
}

private int getOperandType(ASTNode node) {
if (node.egressType == null || node.egressType == Object.class) {
return DataTypes.NULL;
}
return ParseTools.__resolveType(node.egressType);
}

private boolean doesRequireConversion(Class leftType, Class rightType, int op) {
Expand Down Expand Up @@ -149,10 +155,6 @@ public int getOperation() {
return operation;
}

public BinaryOperation getRightBinary() {
return right != null && right instanceof BinaryOperation ? (BinaryOperation) right : null;
}

public void setRightMost(ASTNode right) {
BinaryOperation n = this;
while (n.right != null && n.right instanceof BinaryOperation) {
Expand All @@ -173,14 +175,6 @@ public ASTNode getRightMost() {
return n.right;
}

public int getPrecedence() {
return PTABLE[operation];
}

public boolean isGreaterPrecedence(BinaryOperation o) {
return o.getPrecedence() > PTABLE[operation];
}

@Override
public boolean isLiteral() {
return false;
Expand Down

0 comments on commit 42b8ac5

Please sign in to comment.