Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4023081

ambiguous Float(String s) constructor spec

    XMLWordPrintable

    Details

    • Subcomponent:
    • Resolved In Build:
      1.2fcs
    • CPU:
      generic
    • OS:
      generic
    • Verification:
      Not verified

      Description

      masayoshi.okutsu@Eng 1996-12-20
      The lexical convention of Float(String s) is ambiguous to programmers.
      Fujitsu reported the following.

      Case 1: Float("1.23f")
      JDK1.1 : An exception occurs both on PC and Solaris.
      JDK1.0.2 : No exception occurs both on PC and Solaris.
      Case 2: Float("1.23")
      No exception occurs on any combination of JDK1.0.2 , JDK 1.1 , PC
      and Solaris.

      The spec of JDK 1.1 changed ?

      Sample program:

      public class floatTest {
      public static void main (String args[]) {
      try {
      Float f2 = new Float("1.23f") ;
      } catch (NumberFormatException n) {
      System.out.println("exception caught!!") ;
      }
      }
      }


      Execution result

      jdk102% javac floatTest.java
      jdk102% java floatTest

      jdk11% javac floatTest.java
      jdk11% java floatTest
      exception caught!!

      It seems that "1.23f" is a wrong notation, but the API spec should clarify
      character classes to specify a floating number in String. For example,
      does it accept the Thai digits?

      The imcompatibility between 1.0.2 and 1.1 is another issue.

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              asommere Alan Sommerer (Inactive)
              Reporter:
              okutsu Masayoshi Okutsu
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: