jscience
  1. jscience
  2. JSCIENCE-81

Unit.valueOf(CharSequence) parses float values incorrectly

    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:
      81

      Description

      This problem was noticed in JScience 4.3.1.

      Unit.valueOf(CharSequence) parses float values incorrectly because
      UnitFormat.DefaultFormat.readDouble(CharSequence,ParsePosition) does not include
      any characters at or beyond the decimal point ('.') in the String passed to
      Double.parseDouble(String). This also causes the decimal point ('.') being
      parsed as the start of the next token, which results in the
      'java.text.ParseException: unexpected token 1' shown in the example output below.

      ---- Begin example code ----
      package jscience;

      import javax.measure.quantity.Length;
      import javax.measure.unit.SI;
      import javax.measure.unit.Unit;

      import org.jscience.JScience;

      public class UnitValueOfFloat {
      public static void main( final String[] args )

      { System.out.println( "JScience.VERSION=" + JScience.VERSION ); final Unit<?> unitWithFloatBad = Unit.valueOf( "m*1234.56" ); System.out.println( "unitWithFloatBad=" + unitWithFloatBad ); }

      }
      ---- End example code ----

      ---- 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.UnitValueOfFloat.main(UnitValueOfFloat.java:13)
      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:480)
      ... 1 more
      ---- End output ----

        Activity

        Hide
        shanmann added a comment -

        I missed the source of the problem when I originally looked at the
        readDouble(CharSequence,ParsePosition) method. The string in the following is
        missing a '4', "012356789+-.E".indexOf(csq.charAt(end)).

        Show
        shanmann added a comment - I missed the source of the problem when I originally looked at the readDouble(CharSequence,ParsePosition) method. The string in the following is missing a '4', "012356789+-.E".indexOf(csq.charAt(end)).

          People

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

            Dates

            • Created:
              Updated: