Community
Participate
Working Groups
Tim, can you please fix this? It causes a null pointer exception. I am not sure what the proper fix would be here. The problem is this. In the 3rd line where conversionDirection returns a value, a null is coming back. You check for the null in the if statement a few lines later, but in the 2nd half of the method (about 20 lines later) you don't check to a null, so it tries to use a null object in the statement (direction == -1) and this causes the NPE: if (result == null) { // If there was no operation then reverse the lookup if (direction == -1) { ************************************************* public static Operation getBinaryOperation(Classifier lhs, Classifier rhs, String opSymbol) { if (!(lhs instanceof StructPart)) return null; StructPart clazz = null; Integer direction = conversionDirection(lhs, rhs, opSymbol); // Now check for operation based on one type being converted to the other // to determine where to look for the operation Operation conOp = null; if (direction == null || direction == 0) { clazz = (StructPart)lhs; } else if (direction == -1) { conOp = getConversionOperation((StructPart)rhs, (StructPart)lhs); if (conOp == null) return null; clazz = (StructPart)conOp.getType().getClassifier(); } else if (direction == 1) { conOp = getConversionOperation((StructPart)lhs, (StructPart)rhs); if (conOp == null) return null; clazz = (StructPart)conOp.getType().getClassifier(); } else if (direction == 2) { clazz = (StructPart)TypeUtils.Type_DECIMAL; } // First check if there is an explicit operation // independent of conversion of either side to the other. // Check only the lhs classifier for this operation. // This is to handle the cases where binary operations are implemented // that do not force a conversion of one type to the other, i.e // they have the LHS and RHS being different types if (!lhs.equals(rhs)) { List<Operation> ops = TypeUtils.getBestFitOperation(clazz, opSymbol, (StructPart)lhs, (StructPart)rhs); // Filter out an operation that has the same parameter types for each parameter if (ops.size() == 1 && !(ops.get(0).getParameters().get(0).getType().equals(ops.get(0).getParameters().get(1).getType()))) { return ops.get(0); } if (ops.size() > 1) return null; } Operation result = TypeUtils.getBinaryOperation(clazz, opSymbol); if (result == null) { // If there was no operation then reverse the lookup if (direction == -1) { conOp = getConversionOperation((StructPart)lhs, (StructPart)rhs); if (conOp == null) return null; clazz = (StructPart)conOp.getType().getClassifier(); } else if (direction == 1) { conOp = getConversionOperation((StructPart)rhs, (StructPart)lhs); if (conOp == null) return null; clazz = (StructPart)conOp.getType().getClassifier(); } result = TypeUtils.getBinaryOperation(clazz, opSymbol); } return result; }
This has been fixed.
Verified