Bug 50140 - Compiler error when block-commenting a string that contains '*/'
Summary: Compiler error when block-commenting a string that contains '*/'
Status: RESOLVED INVALID
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.0   Edit
Hardware: PC Windows XP
: P3 major (vote)
Target Milestone: 3.0 M7   Edit
Assignee: JDT-Core-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-01-16 11:18 EST by Thomas Dudziak CLA
Modified: 2004-01-19 05:43 EST (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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.