Skip to content

Commit ad81ec9

Browse files
committed
OpDivide does not return a TypedValue for its operate result (consistent with OpMultiply)
Issue: SPR-9869
1 parent 9862fbf commit ad81ec9

File tree

2 files changed

+29
-19
lines changed

2 files changed

+29
-19
lines changed

org.springframework.expression/src/main/java/org/springframework/expression/spel/ast/OpDivide.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2009 the original author or authors.
2+
* Copyright 2002-2012 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -25,6 +25,7 @@
2525
* Implements division operator.
2626
*
2727
* @author Andy Clement
28+
* @author Juergen Hoeller
2829
* @since 3.0
2930
*/
3031
public class OpDivide extends Operator {
@@ -42,14 +43,16 @@ public TypedValue getValueInternal(ExpressionState state) throws EvaluationExcep
4243
Number op2 = (Number) operandTwo;
4344
if (op1 instanceof Double || op2 instanceof Double) {
4445
return new TypedValue(op1.doubleValue() / op2.doubleValue());
45-
} else if (op1 instanceof Long || op2 instanceof Long) {
46+
}
47+
else if (op1 instanceof Long || op2 instanceof Long) {
4648
return new TypedValue(op1.longValue() / op2.longValue());
47-
} else { // TODO what about non-int result of the division?
49+
}
50+
else {
51+
// TODO what about non-int result of the division?
4852
return new TypedValue(op1.intValue() / op2.intValue());
4953
}
5054
}
51-
Object result = state.operate(Operation.DIVIDE, operandOne, operandTwo);
52-
return new TypedValue(result);
55+
return state.operate(Operation.DIVIDE, operandOne, operandTwo);
5356
}
5457

5558
}

org.springframework.expression/src/main/java/org/springframework/expression/spel/ast/OpMultiply.java

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2009 the original author or authors.
2+
* Copyright 2002-2012 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -22,34 +22,38 @@
2222
import org.springframework.expression.spel.ExpressionState;
2323

2424
/**
25-
* Implements the multiply operator. Conversions and promotions:
26-
* http://java.sun.com/docs/books/jls/third_edition/html/conversions.html Section 5.6.2:
25+
* Implements the {@code multiply} operator.
2726
*
28-
* <p>If any of the operands is of a reference type, unboxing conversion (¤5.1.8) is performed. Then:<br>
27+
* <p>Conversions and promotions are handled as defined in
28+
* <a href="http://java.sun.com/docs/books/jls/third_edition/html/conversions.html">Section 5.6.2
29+
* of the Java Language Specification</a>:
30+
*
31+
* <p>If any of the operands is of a reference type, unboxing conversion (Section 5.1.8) is performed. Then:<br>
2932
* If either operand is of type double, the other is converted to double.<br>
3033
* Otherwise, if either operand is of type float, the other is converted to float.<br>
3134
* Otherwise, if either operand is of type long, the other is converted to long.<br>
3235
* Otherwise, both operands are converted to type int.
3336
*
34-
* <p>
35-
*
3637
* @author Andy Clement
38+
* @author Sam Brannen
3739
* @since 3.0
3840
*/
3941
public class OpMultiply extends Operator {
4042

41-
4243
public OpMultiply(int pos, SpelNodeImpl... operands) {
4344
super("*", pos, operands);
4445
}
4546

4647
/**
47-
* Implements multiply directly here for some types of operand, otherwise delegates to any registered overloader for
48-
* types it does not recognize. Supported types here are:
48+
* Implements the {@code multiply} operator directly here for certain types
49+
* of supported operands and otherwise delegates to any registered overloader
50+
* for types not supported here.
51+
* <p>Supported operand types:
4952
* <ul>
50-
* <li>integers
5153
* <li>doubles
52-
* <li>string and int ('abc' * 2 == 'abcabc')
54+
* <li>longs
55+
* <li>integers
56+
* <li>String and int ('abc' * 2 == 'abcabc')
5357
* </ul>
5458
*/
5559
@Override
@@ -61,12 +65,15 @@ public TypedValue getValueInternal(ExpressionState state) throws EvaluationExcep
6165
Number rightNumber = (Number) operandTwo;
6266
if (leftNumber instanceof Double || rightNumber instanceof Double) {
6367
return new TypedValue(leftNumber.doubleValue() * rightNumber.doubleValue());
64-
} else if (leftNumber instanceof Long || rightNumber instanceof Long) {
68+
}
69+
else if (leftNumber instanceof Long || rightNumber instanceof Long) {
6570
return new TypedValue(leftNumber.longValue() * rightNumber.longValue());
66-
} else {
71+
}
72+
else {
6773
return new TypedValue(leftNumber.intValue() * rightNumber.intValue());
6874
}
69-
} else if (operandOne instanceof String && operandTwo instanceof Integer) {
75+
}
76+
else if (operandOne instanceof String && operandTwo instanceof Integer) {
7077
int repeats = (Integer) operandTwo;
7178
StringBuilder result = new StringBuilder();
7279
for (int i = 0; i < repeats; i++) {

0 commit comments

Comments
 (0)