[jira] Resolved: (JEXL-30) ASTAddNode does not add BigDecimal objects correctly

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[jira] Resolved: (JEXL-30) ASTAddNode does not add BigDecimal objects correctly

JIRA jira@apache.org

     [ https://issues.apache.org/jira/browse/JEXL-30?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

dion gillard resolved JEXL-30.
------------------------------

    Resolution: Fixed

committed to rev 589320 as part of 2.0 branch

> ASTAddNode does not add BigDecimal objects correctly
> ----------------------------------------------------
>
>                 Key: JEXL-30
>                 URL: https://issues.apache.org/jira/browse/JEXL-30
>             Project: Commons JEXL
>          Issue Type: Bug
>    Affects Versions: 1.1
>         Environment: All
>            Reporter: Curtis Stanford
>             Fix For: 2.0
>
>
> The ASTAddNode only checks for Float or Double objects when adding floating point numbers. If the objects are not Float or Double, they are added as Long's. As a result, adding BigDecimal objects loses any existing decimal points.
> Untested patch:
> Index: ASTAddNode.java
> ===================================================================
> --- ASTAddNode.java     (revision 476204)
> +++ ASTAddNode.java     (working copy)
> @@ -16,6 +16,8 @@
>  
>  package org.apache.commons.jexl.parser;
>  
> +import java.math.BigDecimal;
> +
>  import org.apache.commons.jexl.JexlContext;
>  import org.apache.commons.jexl.util.Coercion;
>  
> @@ -71,8 +73,8 @@
>           *  if anything is float, double or string with ( "." | "E" | "e")
>           *  coerce all to doubles and do it
>           */
> -        if (left instanceof Float || left instanceof Double
> -            || right instanceof Float || right instanceof Double
> +        if (left instanceof Float || left instanceof Double || left instanceof BigDecimal
> +            || right instanceof Float || right instanceof Double || right instanceof BigDecimal
>              || (left instanceof String
>                    && (((String) left).indexOf(".") != -1
>                            || ((String) left).indexOf("e") != -1

--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.