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

JavaTokenizer reads octal numbers mistakenly

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Fixed
    • Icon: P4 P4
    • 17
    • 17
    • tools
    • None
    • b23
    • generic
    • generic

      Considering the following code about the wrong octal number:

      ```
      class Digit {
              int n = 079;
      }
      ```

      When compiling it, the javac would output:


      ```
      Digit.java:2: error: integer number too large
              int n = 079;
                         ^
      1 error
      ```


      Because the lexer(JavaTokenizer) incorrectly reads `079` as a token.
      So the parser(JavacParser) would throw the NumberFormatException when using the method Convert#string2int.
      It is an issue of the lexer but it is caught by the parser, which is not our expectation.

      Considering the following code about the wrong binary, hexadecimal and floating point numbers:

      ```
      class Digit {
              double a = 9.f2;
              int n = 0b123;
              int n = 0x12r3;
      }
      ```

      The compiler would output:

      ```
      Digit.java:2: error: ';' expected
              double a = 9.f2;
                                    ^
      Digit.java:3: error: ';' expected
              int n = 0b123;
                               ^
      Digit.java:4: error: ';' expected
              int n = 0x12r3;
                                 ^
      Digit.java:4: error: <identifier> expected
              int n = 0x12r3;
                                    ^
      4 errors
      ```

      The output of the wrong octal numbers should be similar to them, which is like the following output:

      ```

      Digit.java:2: error: ';' expected
              int n = 079;
                             ^
      1 error
      ```

            gli Guoxiong Li
            gli Guoxiong Li
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: