Bug 50140

Summary: Compiler error when block-commenting a string that contains '*/'
Product: [Eclipse Project] JDT Reporter: Thomas Dudziak <tomdzk>
Component: CoreAssignee: JDT-Core-Inbox <jdt-core-inbox>
Status: RESOLVED INVALID QA Contact:
Severity: major    
Priority: P3    
Version: 3.0   
Target Milestone: 3.0 M7   
Hardware: PC   
OS: Windows XP   
Whiteboard:

Description Thomas Dudziak CLA 2004-01-16 11:18:06 EST
Assume you have code like this:

public class Test
{
  public void doSomething()
  {
    String text = "This is a block comment end: */";
  }
}

Now insert a block comment begin '/*' at the start of the line containing the
variable declaration. The java editor then shows a block comment from the
beginning of the line to the '*/' in the string, and a compiler error for the
trailing '";' ("String literal is not properly closed by a double-quote").
Even if you now put a '*/' after the semicolon on the same or next line (e.g.
using Source->Add Block Comment in the first place), still the compiler error
persists.

Note: this compiler problem also exists in Sun's JDK 1.4.2_03
Comment 1 Philipe Mulet CLA 2004-01-17 07:24:14 EST
This behavior is imposed by the language.
If you break the string in between * and /, it will be fine.

public class Test
{
  public void doSomething()
  {
    String text = "This is a block comment end: *"+"/";
  }
}

Comment 2 Thomas Dudziak CLA 2004-01-19 05:43:47 EST
You're right, the JLS states as much
(http://java.sun.com/docs/books/jls/second_edition/html/lexical.doc.html#48125).
Of course it's sad that the weak expressivness of the recursive-descent grammar
imposes this - in my eyes - useless constraint upon the language.