ahgittin commented on code in PR #1368:
URL: https://github.com/apache/brooklyn-server/pull/1368#discussion_r999835914
##########
core/src/main/java/org/apache/brooklyn/core/workflow/steps/SetVariableWorkflowStep.java:
##########
@@ -210,31 +209,39 @@ Object applyMathOperator(List<String> lhs0, List<String>
rhs0, BiFunction<Intege
return ((Maybe)asInteger(x)).orMaybe(() -> asDouble(x)).get();
}
- Maybe<Double> lhsD = asDouble(lhs);
- Maybe<Double> rhsD = asDouble(rhs);
- if (lhsD.isPresent() && rhsD.isPresent()) return
asDouble(ifDouble.apply(lhsD.get(), rhsD.get())).get();
+ if (ifDouble!=null) {
+ Maybe<Double> lhsD = asDouble(lhs);
+ Maybe<Double> rhsD = asDouble(rhs);
+ if (lhsD.isPresent() && rhsD.isPresent()) return
asDouble(ifDouble.apply(lhsD.get(), rhsD.get())).get();
+
+ if (lhsD.isAbsent()) throw new
IllegalArgumentException("Invalid left argument to operation '"+op+"': "+lhs0+"
=> "+lhs);
+ if (rhsD.isAbsent()) throw new
IllegalArgumentException("Invalid right argument to operation '"+op+"':
"+rhs0+" = "+rhs);
+ }
- if (lhsD.isAbsent())
- throw new IllegalArgumentException("Invalid value for
operation: "+lhs0+" = "+lhs);
- if (rhsD.isAbsent()) throw new IllegalArgumentException("Invalid
value for operation: "+rhs0+" = "+rhs);
+ if (lhsI.isAbsent()) throw new IllegalArgumentException("Invalid
left argument to operation '"+op+"': "+lhs0+" => "+lhs);
+ if (rhsI.isAbsent()) throw new IllegalArgumentException("Invalid
right argument to operation '"+op+"': "+rhs0+" = "+rhs);
throw new IllegalArgumentException("Should not come here");
}
- Object handleMultiple(List<String> lhs, List<String> rhs) {
- return applyMathOperator(lhs, rhs, (a,b)->a*b, (a,b)->a*b);
+ Object handleMultiply(List<String> lhs, List<String> rhs) {
+ return applyMathOperator("*", lhs, rhs, (a,b)->a*b, (a,b)->a*b);
}
Object handleDivide(List<String> lhs, List<String> rhs) {
- return applyMathOperator(lhs, rhs, (a,b)->1.0*a/b, (a,b)->a/b);
+ return applyMathOperator("/", lhs, rhs, (a,b)->1.0*a/b,
(a,b)->a/b);
Review Comment:
I think that exception _should_ be thrown if the author writes `5 / 0`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]