You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by jl...@apache.org on 2017/03/08 21:31:44 UTC
svn commit: r1786082 -
/ofbiz/branches/release15.12/framework/minilang/src/org/ofbiz/minilang/method/conditional/Compare.java
Author: jleroux
Date: Wed Mar 8 21:31:44 2017
New Revision: 1786082
URL: http://svn.apache.org/viewvc?rev=1786082&view=rev
Log:
"Applied fix from trunk framework *by hand* for revision: 1786079"
------------------------------------------------------------------------
r1786079 | jleroux | 2017-03-08 22:27:30 +0100 (mer. 08 mars 2017) | 9 lignes
Fixed: compareBigDecimals in org.ofbiz.minilang.method.conditional.Compare
does not compare certain values correctly
(OFBIZ-6386)
compareBigDecimals scales down and rounds up meaning you lose information and
the comparison result is not as expected
Thanks: Gareth Carter for the patch, Mridul Pathak and Jacopo for discussing the
topic in all details (see the Jira issue)
------------------------------------------------------------------------
Modified:
ofbiz/branches/release15.12/framework/minilang/src/org/ofbiz/minilang/method/conditional/Compare.java
Modified: ofbiz/branches/release15.12/framework/minilang/src/org/ofbiz/minilang/method/conditional/Compare.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/release15.12/framework/minilang/src/org/ofbiz/minilang/method/conditional/Compare.java?rev=1786082&r1=1786081&r2=1786082&view=diff
==============================================================================
--- ofbiz/branches/release15.12/framework/minilang/src/org/ofbiz/minilang/method/conditional/Compare.java (original)
+++ ofbiz/branches/release15.12/framework/minilang/src/org/ofbiz/minilang/method/conditional/Compare.java Wed Mar 8 21:31:44 2017
@@ -18,8 +18,6 @@
*******************************************************************************/
package org.ofbiz.minilang.method.conditional;
-import java.math.BigDecimal;
-import java.math.RoundingMode;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
@@ -49,18 +47,6 @@ public abstract class Compare {
}
}
- private static int compareBigDecimals(BigDecimal lBigDecimal, BigDecimal rBigDecimal) {
- // Developers: Do not change this. We are comparing two fixed-point decimal numbers,
- // not performing accounting calculations - so it is okay to specify the rounding mode.
- int decimals = lBigDecimal.scale();
- if (rBigDecimal.scale() < decimals) {
- lBigDecimal = lBigDecimal.setScale(rBigDecimal.scale(), RoundingMode.UP);
- } else if (decimals < rBigDecimal.scale()) {
- rBigDecimal = rBigDecimal.setScale(decimals, RoundingMode.UP);
- }
- return lBigDecimal.compareTo(rBigDecimal);
- }
-
private static Map<String, Compare> createInstanceMap() {
Map<String, Compare> writableMap = new HashMap<String, Compare>(10);
writableMap.put("contains", new CompareContains());
@@ -132,12 +118,6 @@ public abstract class Compare {
if (convertedRvalue == null) {
return false;
}
- if (convertedLvalue instanceof BigDecimal &&
- convertedRvalue instanceof BigDecimal) {
- BigDecimal lBigDecimal = (BigDecimal) convertedLvalue;
- BigDecimal rBigDecimal = (BigDecimal) convertedRvalue;
- return compareBigDecimals(lBigDecimal, rBigDecimal) == 0;
- }
if (convertedLvalue instanceof Comparable &&
convertedRvalue instanceof Comparable) {
Comparable<Object> comparable = UtilGenerics.cast(convertedLvalue);
@@ -154,12 +134,6 @@ public abstract class Compare {
Object convertedLvalue = MiniLangUtil.convertType(lValue, type, locale, timeZone, format);
Object convertedRvalue = MiniLangUtil.convertType(rValue, type, locale, timeZone, format);
assertValuesNotNull(convertedLvalue, convertedRvalue);
- if (convertedLvalue instanceof BigDecimal &&
- convertedRvalue instanceof BigDecimal) {
- BigDecimal lBigDecimal = (BigDecimal) convertedLvalue;
- BigDecimal rBigDecimal = (BigDecimal) convertedRvalue;
- return compareBigDecimals(lBigDecimal, rBigDecimal) > 0;
- }
if (convertedLvalue instanceof Comparable &&
convertedRvalue instanceof Comparable) {
Comparable<Object> comparable = UtilGenerics.cast(convertedLvalue);
@@ -176,12 +150,6 @@ public abstract class Compare {
Object convertedLvalue = MiniLangUtil.convertType(lValue, type, locale, timeZone, format);
Object convertedRvalue = MiniLangUtil.convertType(rValue, type, locale, timeZone, format);
assertValuesNotNull(convertedLvalue, convertedRvalue);
- if (convertedLvalue instanceof BigDecimal &&
- convertedRvalue instanceof BigDecimal) {
- BigDecimal lBigDecimal = (BigDecimal) convertedLvalue;
- BigDecimal rBigDecimal = (BigDecimal) convertedRvalue;
- return compareBigDecimals(lBigDecimal, rBigDecimal) >= 0;
- }
if (convertedLvalue instanceof Comparable &&
convertedRvalue instanceof Comparable) {
Comparable<Object> comparable = UtilGenerics.cast(convertedLvalue);
@@ -225,12 +193,6 @@ public abstract class Compare {
Object convertedLvalue = MiniLangUtil.convertType(lValue, type, locale, timeZone, format);
Object convertedRvalue = MiniLangUtil.convertType(rValue, type, locale, timeZone, format);
assertValuesNotNull(convertedLvalue, convertedRvalue);
- if (convertedLvalue instanceof BigDecimal &&
- convertedRvalue instanceof BigDecimal) {
- BigDecimal lBigDecimal = (BigDecimal) convertedLvalue;
- BigDecimal rBigDecimal = (BigDecimal) convertedRvalue;
- return compareBigDecimals(lBigDecimal, rBigDecimal) < 0;
- }
if (convertedLvalue instanceof Comparable &&
convertedRvalue instanceof Comparable) {
Comparable<Object> comparable = UtilGenerics.cast(convertedLvalue);
@@ -247,12 +209,6 @@ public abstract class Compare {
Object convertedLvalue = MiniLangUtil.convertType(lValue, type, locale, timeZone, format);
Object convertedRvalue = MiniLangUtil.convertType(rValue, type, locale, timeZone, format);
assertValuesNotNull(convertedLvalue, convertedRvalue);
- if (convertedLvalue instanceof BigDecimal &&
- convertedRvalue instanceof BigDecimal) {
- BigDecimal lBigDecimal = (BigDecimal) convertedLvalue;
- BigDecimal rBigDecimal = (BigDecimal) convertedRvalue;
- return compareBigDecimals(lBigDecimal, rBigDecimal) <= 0;
- }
if (convertedLvalue instanceof Comparable &&
convertedRvalue instanceof Comparable) {
Comparable<Object> comparable = UtilGenerics.cast(convertedLvalue);
@@ -274,12 +230,6 @@ public abstract class Compare {
if (convertedRvalue == null) {
return true;
}
- if (convertedLvalue instanceof BigDecimal &&
- convertedRvalue instanceof BigDecimal) {
- BigDecimal lBigDecimal = (BigDecimal) convertedLvalue;
- BigDecimal rBigDecimal = (BigDecimal) convertedRvalue;
- return compareBigDecimals(lBigDecimal, rBigDecimal) != 0;
- }
if (convertedLvalue instanceof Comparable &&
convertedRvalue instanceof Comparable) {
Comparable<Object> comparable = UtilGenerics.cast(convertedLvalue);