[
https://issues.redhat.com/browse/DROOLS-5284?page=com.atlassian.jira.plug...
]
Toshiya Kobayashi commented on DROOLS-5284:
-------------------------------------------
First of all, the expression in the unit test is not good. Java cannot compile this
because Math.round() can accept only double or float.
{code:java}
15 * Math.round( new BigDecimal("49.4") ) / 100
{code}
Then, MVEL kindly find a "BestCandidate" method for this.
https://github.com/mvel/mvel/blob/mvel2-2.4.7.Final/src/main/java/org/mve...
So MVEL picks up
{code:java}
public static int java.lang.Math.round(float)
{code}
or
{code:java}
public static long java.lang.Math.round(double)
{code}
(Assuming MVEL can coerce BigDecimal to float or double).
However, these 2 methods has no superiority in terms of scoring for
"BestCandidate". Both get score "4".
https://github.com/mvel/mvel/blob/mvel2-2.4.7.Final/src/main/java/org/mve...
So the result depends on which method was picked first (The method lists are given by
Class.getMethods()).
In case of OpenJDK, Math.round(double) is picked. -> Finally, the expression results in
(Long / Long) which returns Double by MathProcessor.
In case of IBM JDK Math.round(float) is picked. -> Finally, the expression results in
(Integer / Integer) which returns Integer by IntDiv.
I think I can teak the selection logic as Double is preferred coercion for BigDecimal.
MVELTest.testTypeCoercionLongDivByInt fails with IBM JDK 8
----------------------------------------------------------
Key: DROOLS-5284
URL:
https://issues.redhat.com/browse/DROOLS-5284
Project: Drools
Issue Type: Bug
Components: core engine
Affects Versions: 7.36.0.Final
Reporter: Toshiya Kobayashi
Assignee: Toshiya Kobayashi
Priority: Major
MVELTest.testTypeCoercionLongDivByInt fails with IBM JDK 8
{noformat}
[ERROR] Tests run: 1, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 0.97 s
<<< FAILURE! - in org.drools.compiler.integrationtests.MVELTest
[ERROR] testTypeCoercionLongDivByInt(org.drools.compiler.integrationtests.MVELTest) Time
elapsed: 0.962 s <<< FAILURE!
java.lang.AssertionError: expected:<7.350000> but was:<7>
at org.junit.Assert.fail(Assert.java:88)
at org.junit.Assert.failNotEquals(Assert.java:834)
at org.junit.Assert.assertEquals(Assert.java:118)
at org.junit.Assert.assertEquals(Assert.java:144)
at
org.drools.compiler.integrationtests.MVELTest.testTypeCoercionLongDivByInt(MVELTest.java:1150)
...
[INFO]
[INFO] Results:
[INFO]
[ERROR] Failures:
[ERROR] MVELTest.testTypeCoercionLongDivByInt:1150 expected:<7.350000> but
was:<7>
{noformat}
--
This message was sent by Atlassian Jira
(v7.13.8#713008)