RFR: JDK-8227640: javac crashes on text blocks with invalid escapes.
Jim Laskey
james.laskey at oracle.com
Mon Jul 15 19:07:03 UTC 2019
Okay, I mis-remembered. Thank you. +1.
> On Jul 15, 2019, at 4:00 PM, Jan Lahoda <jan.lahoda at oracle.com> wrote:
>
> On 15. 07. 19 18:29, Jim Laskey wrote:
>> Actually, one problem, should break from the token loop when the error is encountered, otherwise it's a change in behaviour.
>
> Sorry, I am not sure I follow - if there are multiple illegal escapes in the literal, javac used to produce an error for each of them:
> (JDK 8):
> ---
> $ javac IllegalEscapes.java
> IllegalEscapes.java:2: error: illegal escape character
> private static final String s1 = "\!\!\!";
> ^
> IllegalEscapes.java:2: error: illegal escape character
> private static final String s1 = "\!\!\!";
> ^
> IllegalEscapes.java:2: error: illegal escape character
> private static final String s1 = "\!\!\!";
> ^
> 3 errors
> ---
>
> With this patch, it does the same:
> ---
> $ javac IllegalEscapes.java
> IllegalEscapes.java:2: error: illegal escape character
> private static final String s1 = "\!\!\!";
> ^
> IllegalEscapes.java:2: error: illegal escape character
> private static final String s1 = "\!\!\!";
> ^
> IllegalEscapes.java:2: error: illegal escape character
> private static final String s1 = "\!\!\!";
> ^
> 3 errors
> ---
>
> This is because the conversion is happening after the literal is fully scanned.
>
> Thanks,
> Jan
>
> IllegalEscapes.java:
> ---
> public class IllegalEscapes {
> private static final String s1 = "\!\!\!";
> }
> ---
>
>>> On Jul 15, 2019, at 1:05 PM, Jan Lahoda <jan.lahoda at oracle.com> wrote:
>>>
>>> Hi,
>>>
>>> When a text block contains an invalid escape sequence, there is an internal IllegalArgumentException thrown from String.translateEscapes invoked from javac. While this is concealed by javac, there are still ways to see the effects of the exception. So, I'd like to propose avoid calling String.translateEscapes when there are invalid escape sequences (errors for these invalid sequences are already reported).
>>>
>>> JBS: https://bugs.openjdk.java.net/browse/JDK-8227640
>>> Webrev: http://cr.openjdk.java.net/~jlahoda/8227640/webrev.00/
>>>
>>> How does this look?
>>>
>>> Thanks,
>>> Jan
More information about the compiler-dev
mailing list