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

Igor Vorobiov updated ODE-1016:
-------------------------------

    Description: 
org.apache.ode.bpel.elang.xpath10.runtime.XPath10ExpressionRuntime.evaluate(OExpression,
 EvaluationContext) works incorrect when number function with String argument 
is used. 
Following '*if*' statement should have check for NaN:
{code:title=org.apache.ode.bpel.elang.xpath10.runtime.XPath10ExpressionRuntime.java|borderStyle=solid}
      public List evaluate(OExpression cexp, EvaluationContext ctx) throws 
FaultException, EvaluationException {
              if (ret instanceof Double) { // !!! should be ==> if (ret 
instanceof Double   && !((Double) ret).isNaN()) 
                    // safely convert a double into a long if they are 
numerically equal. This
                    // makes 1 from 1.0, which is more reliable when calling 
web services.
                    if (Double.compare((Double)ret, Math.ceil((Double)ret)) == 
0) {
                        // the double is actually an int/long
                        ret = ((Double)ret).longValue();
                    }
                }
     }
{code}

Following test can be used to reproduce the problem:
{code:title=org.apache.ode.bpel.elang.xpath10.runtime.XPath10ExpressionRuntimeTest.java|borderStyle=solid}
    public void testEvaluate_NaN() throws Exception {
        setVariableName("existVar");

        OXPath10Expression exp = compile("number('/tns:Title/tns:Data')");
        Map<String, String> nsMap = new HashMap<String, String>();
        nsMap.put("tns", "http://foobar";);
        NSContext context = createNSContext(nsMap);
        exp.namespaceCtx = context;

        Node retVal = _runtime.evaluateNode(exp, this);

        assertNotNull(retVal);
        assertEquals(String.valueOf(Double.NaN), retVal.getTextContent());
    }
{code}

  was:
org.apache.ode.bpel.elang.xpath10.runtime.XPath10ExpressionRuntime.evaluate(OExpression,
 EvaluationContext) works incorrect when number function with String argument 
is used. 
Following statement should have check for NaN:
              if (ret instanceof Double) {
                    // safely convert a double into a long if they are 
numerically equal. This
                    // makes 1 from 1.0, which is more reliable when calling 
web services.
                    if (Double.compare((Double)ret, Math.ceil((Double)ret)) == 
0) {
                        // the double is actually an int/long
                        ret = ((Double)ret).longValue();
                    }
                }


> ASSIGN returns 0 when number function with String argument is used
> ------------------------------------------------------------------
>
>                 Key: ODE-1016
>                 URL: https://issues.apache.org/jira/browse/ODE-1016
>             Project: ODE
>          Issue Type: Bug
>          Components: BPEL Runtime
>    Affects Versions: 1.3.6
>            Reporter: Igor Vorobiov
>
> org.apache.ode.bpel.elang.xpath10.runtime.XPath10ExpressionRuntime.evaluate(OExpression,
>  EvaluationContext) works incorrect when number function with String argument 
> is used. 
> Following '*if*' statement should have check for NaN:
> {code:title=org.apache.ode.bpel.elang.xpath10.runtime.XPath10ExpressionRuntime.java|borderStyle=solid}
>       public List evaluate(OExpression cexp, EvaluationContext ctx) throws 
> FaultException, EvaluationException {
>               if (ret instanceof Double) { // !!! should be ==> if (ret 
> instanceof Double   && !((Double) ret).isNaN()) 
>                     // safely convert a double into a long if they are 
> numerically equal. This
>                     // makes 1 from 1.0, which is more reliable when calling 
> web services.
>                     if (Double.compare((Double)ret, Math.ceil((Double)ret)) 
> == 0) {
>                         // the double is actually an int/long
>                         ret = ((Double)ret).longValue();
>                     }
>                 }
>      }
> {code}
> Following test can be used to reproduce the problem:
> {code:title=org.apache.ode.bpel.elang.xpath10.runtime.XPath10ExpressionRuntimeTest.java|borderStyle=solid}
>     public void testEvaluate_NaN() throws Exception {
>       setVariableName("existVar");
>         OXPath10Expression exp = compile("number('/tns:Title/tns:Data')");
>         Map<String, String> nsMap = new HashMap<String, String>();
>         nsMap.put("tns", "http://foobar";);
>         NSContext context = createNSContext(nsMap);
>         exp.namespaceCtx = context;
>         Node retVal = _runtime.evaluateNode(exp, this);
>         assertNotNull(retVal);
>         assertEquals(String.valueOf(Double.NaN), retVal.getTextContent());
>     }
> {code}



--
This message was sent by Atlassian JIRA
(v6.2#6252)

Reply via email to