jscience
  1. jscience
  2. JSCIENCE-83

Unit.valueOf(CharSequence) parsing error due to readDouble() advancing parser one character too far

    Details

    • Type: Bug Bug
    • Status: Open
    • Priority: Blocker Blocker
    • Resolution: Unresolved
    • Affects Version/s: current
    • Fix Version/s: Version 6.0
    • Component/s: www
    • Labels:
      None
    • Environment:

      Operating System: All
      Platform: All

    • Issuezilla Id:
      83

      Description

      This problem was noticed in JScience 4.3.1.

      When Unit.valueOf(CharSequence) contains a float value, a parsing error results
      due to UnitFormat.DefaultFormat.readDouble(CharSequence,ParsePosition) advancing
      the parser one character too far. This occurs at the line 'pos.setIndex(end+1)'
      just after the end of the while loop. The 'end+1' should just be 'end'.

      ---- Begin example code snippet ----
      System.out.println( "JScience.VERSION=" + JScience.VERSION );

      final Unit<?> unitWithFloatBad = Unit.valueOf( "m*123.56/s" );
      ---- End example code snippet ----

      ---- Begin output ----
      JScience.VERSION=4.3.1 October 4 2007
      Exception in thread "main" java.lang.IllegalArgumentException:
      java.text.ParseException: unexpected token 1
      at javax.measure.unit.Unit.valueOf(Unit.java:482)
      at jscience.UnitValueOfFloatIndex1TooFar.main(UnitValueOfFloatIndex1TooFar.java:11)
      Caused by: java.text.ParseException: unexpected token 1
      at
      javax.measure.unit.UnitFormat$DefaultFormat.parseProductUnit(UnitFormat.java:468)
      at javax.measure.unit.Unit.valueOf(Unit.java:479)
      ... 1 more
      ---- End output ----

        Activity

        There are no comments yet on this issue.

          People

          • Assignee:
            jscience-issues
            Reporter:
            shanmann
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated: