RFR: 8267361: JavaTokenizer reads octal numbers mistakenly

Jim Laskey jlaskey at openjdk.java.net
Wed May 19 11:11:42 UTC 2021


On Wed, 19 May 2021 10:01:19 GMT, Guoxiong Li <gli at openjdk.org> wrote:

> Hi all,
> 
> When compiling the following code about the wrong octal number:
> 
> 
> class Digit {
>         int n = 079;
> }
> 
> 
> The javac would output the following error message:
> 
> 
> Digit.java:2: error: integer number too large
>         int n = 079;
>                 ^
> 1 error
> 
> 
> This error message is unclear and not silimar to other wrong numbers.
> 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 javac would output the silimar error message: `error: ';' expected`. The whole information is shown below.
> 
> 
> 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
> 
> 
> Because the lexer(JavaTokenizer) incorrectly reads `079` as a token.
> Then the parser(JavacParser) would throw the NumberFormatException when using the method Convert#string2int.
> So the javac would output `integer number too large`.
> 
> The token  `079` is a wrong octal number token. And this is a issue of the lexer, but it is caught by the parser so that the unrelated error message is generated.
> 
> This patch fixes it and adds a corresponding test case.
> Thank you for taking the time to review.
> 
> Best Regards,
> -- Guoxiong

The fix is reasonable but I have a concern that more tests will start failing with the fix. Would you run `make test TEST=jdk_lang` and then maybe `make test-tier1` to make sure? You'll have to have jtreg installed and add `--with-jtreg=<path to jtreg home>` to your configuration. Thank you.

-------------

PR: https://git.openjdk.java.net/jdk/pull/4111


More information about the compiler-dev mailing list