Uploaded image for project: 'CloverDX'
  1. CloverDX
  2. CLO-8756

Consistent behavior of isDecimal and str2Decimal functions

    XMLWordPrintable

Details

    • 1
    • JUnit test
    • org.jetel.util.string.StringUtilsTest.test_isNumber()
    • Green Sprint 61, Green Sprint 62

    Description

      When I use this code:

      string myString = "E0258";
      if(isDecimal(myString)) {
         $out.0.field2 = str2decimal(myString);
      }
      

      It returns the following stack trace:

      17:00:37,938 ERROR [WatchDog_28] Component [Reformat:REFORMAT] finished with status ERROR. (In0: 1 recs, Out0: 0 recs)
       Message: Transform failed!
        Interpreter runtime exception in function str2decimal on line 10 column 25
        Caused by: java.lang.NumberFormatException -> String 'E0258' is not a valid representation of a BigDecimal
        ----------------------- CTL2 snippet -----------------------
        10:         $out.0.field2 = str2decimal(myString);
                                    ^^^^^^^^^^^^^^^^^^^^^
        ----------------------- CTL2 snippet -----------------------
        Call arguments: 
        [1] variable "myString" (string) -> E0258
         can't convert "E0258" to decimal
          String 'E0258' is not a valid representation of a BigDecimal
      17:00:37,940 ERROR [WatchDog_28] Error details:
      org.jetel.exception.JetelRuntimeException: Component [Reformat:REFORMAT] finished with status ERROR. (In0: 1 recs, Out0: 0 recs)
      	at org.jetel.graph.Node.createNodeException(Node.java:631)
      	at org.jetel.graph.Node.run(Node.java:599)
      	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
      	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
      	at java.lang.Thread.run(Thread.java:744)
      Caused by: org.jetel.exception.TransformException: Message: Transform failed!
      	at org.jetel.component.CTLRecordTransformAdapter.transformOnError(CTLRecordTransformAdapter.java:110)
      	at org.jetel.component.Reformat.execute(Reformat.java:272)
      	at org.jetel.graph.Node.run(Node.java:562)
      	... 3 more
      Caused by: org.jetel.ctl.TransformLangExecutorRuntimeException: Interpreter runtime exception in function str2decimal on line 10 column 25
      Caused by: java.lang.NumberFormatException -> String 'E0258' is not a valid representation of a BigDecimal
      ----------------------- CTL2 snippet -----------------------
      10:         $out.0.field2 = str2decimal(myString);
                                  ^^^^^^^^^^^^^^^^^^^^^
      ----------------------- CTL2 snippet -----------------------
      Call arguments: 
      [1] variable "myString" (string) -> E0258
      	at org.jetel.ctl.ASTnode.CLVFFunctionCall.jjtAccept(CLVFFunctionCall.java:64)
      	at org.jetel.ctl.TransformLangExecutor.evaluateRHS(TransformLangExecutor.java:2001)
      	at org.jetel.ctl.TransformLangExecutor.computeAssignment(TransformLangExecutor.java:1693)
      	at org.jetel.ctl.TransformLangExecutor.visit(TransformLangExecutor.java:1853)
      	at org.jetel.ctl.ASTnode.CLVFAssignment.jjtAccept(CLVFAssignment.java:56)
      	at org.jetel.ctl.TransformLangExecutor.executeAndCleanup(TransformLangExecutor.java:2871)
      	at org.jetel.ctl.TransformLangExecutor.visit(TransformLangExecutor.java:1537)
      	at org.jetel.ctl.ASTnode.CLVFBlock.jjtAccept(CLVFBlock.java:44)
      	at org.jetel.ctl.TransformLangExecutor.visit(TransformLangExecutor.java:1375)
      	at org.jetel.ctl.ASTnode.CLVFIfStatement.jjtAccept(CLVFIfStatement.java:50)
      	at org.jetel.ctl.TransformLangExecutor.executeAndCleanup(TransformLangExecutor.java:2871)
      	at org.jetel.ctl.TransformLangExecutor.visit(TransformLangExecutor.java:1537)
      	at org.jetel.ctl.ASTnode.CLVFBlock.jjtAccept(CLVFBlock.java:44)
      	at org.jetel.ctl.TransformLangExecutor.executeFunction(TransformLangExecutor.java:2722)
      	at org.jetel.ctl.TransformLangExecutor.executeFunction(TransformLangExecutor.java:2779)
      	at org.jetel.component.CTLRecordTransformAdapter.transformImpl(CTLRecordTransformAdapter.java:121)
      	at org.jetel.component.CTLRecordTransformAdapter.transform(CTLRecordTransformAdapter.java:102)
      	at org.jetel.component.Reformat.execute(Reformat.java:270)
      	... 4 more
      Caused by: org.jetel.exception.JetelRuntimeException
      	at org.jetel.ctl.TransformLangExecutorRuntimeException.<init>(TransformLangExecutorRuntimeException.java:53)
      	at org.jetel.ctl.TransformLangExecutorRuntimeException.<init>(TransformLangExecutorRuntimeException.java:75)
      	... 22 more
      Caused by: org.jetel.exception.JetelRuntimeException: can't convert "E0258" to decimal
      	at org.jetel.ctl.extensions.ConvertLib.str2decimal(ConvertLib.java:726)
      	at org.jetel.ctl.extensions.ConvertLib$Str2DecimalFunction.execute(ConvertLib.java:748)
      	at org.jetel.ctl.TransformLangExecutor.visit(TransformLangExecutor.java:2628)
      	at org.jetel.ctl.ASTnode.CLVFFunctionCall.jjtAccept(CLVFFunctionCall.java:57)
      	... 21 more
      Caused by: java.lang.NumberFormatException: String 'E0258' is not a valid representation of a BigDecimal
      	at org.jetel.util.formatter.JavolutionNumericFormatter.parseBigDecimal(JavolutionNumericFormatter.java:122)
      	at org.jetel.ctl.extensions.ConvertLib.str2decimal(ConvertLib.java:724)
      	... 24 more
      

      I would, however, expect either false returned by isDecimal (which I assume should be the right behavior), or str2decimal should be able to cast it.

      The same issue appears to be with isNumber() and str2double() methods.

      Attachments

        Issue Links

          Activity

            People

              kovaca Andrej Kovac (Inactive)
              slechtaj Jan Slechta
              Votes:
              2 Vote for this issue
              Watchers:
              8 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: