IntelliJ compiler getting confused with uncompilable code in one liner comment

I have a class like the following:

/**
* From: JLS, 3.10.5
*
*/
public class JlsStringLiterals {
    public static void main(String[] args) {
        // String foo = "\u000a";
    }

}



If you see clearly this is uncompilable:  
String foo = "\u000a";

but it is commented, so it shouldn't cause a compiler error, anyway IntelliJ is warning the following:
Error:(9, 32) unclosed string literal


Is this a bug?
4 comments
Comment actions Permalink

I think the bug isn't the same, the following sentence

    public static void main(String[] args) {
        //  "\u000a";
    }


This doesn't:

    public static void main(String[] args) {
        //  \u000a;
    }
0
Comment actions Permalink

I don't have the JLS in front of me to provide a citation, but it is my understanding that the unicode escapes are treated almost at a "pre-processor" level: i.e. it appears to the compiler as if there was a literal "\n" character exactly where the backslash escape sequence starts.

Thus, if one thinks of it as a preprocessor expansion, the commented code is:

// String foo = "
";



Similarly, as you observed, just commenting out the "\u000a" sequence is not an error because it just puts a newline in the comment. It would match my expectations if you put some trailing characters after the "\u000a" and the compiler should equally barf.

For example:

// \u000a; hello I am extra text


  HTH,
  -- /v\atthew

0
Comment actions Permalink

You was right

// \u000a; hello I am extra text


Produces an error, because unicode character has been proccesed before compilation, while

// \u000a


Doesn't prompt any compiler error.

Anyway IntelliJ IDEA insn't prompting the error for the first example until compiling.

Thanks

0

Please sign in to leave a comment.