Skip to main content



      Home
Home » Language IDEs » Java Development Tools (JDT) » Misleading compiler error on single line if statement
Misleading compiler error on single line if statement [message #244243] Tue, 05 June 2007 13:14 Go to next message
Eclipse UserFriend
I'm running Eclipse 3.3 RC2 and had a compiler error for code which boiled
down to:

public class Test {
public void test() {
if (true)
String string = new String();
}
}

Obviously this is useless code (defining a variable in a single line if statement),
but the error annotations I received were misleading:

Multiple markers at this line
- Syntax error, insert ";" to complete Statement
- String cannot be resolved
- string cannot be resolved
- Syntax error, insert "AssignmentOperator Expression" to complete Assignment

I tried on javac and got

Test.java:3: not a statement
if (true) String string = new String();
^
Test.java:3: ';' expected
if (true) String string = new String();

This isn't much better, but at least it doesn't make me start thinking something
is wrong with my syntax or imports. Should I create a bug?
Re: Misleading compiler error on single line if statement [message #244253 is a reply to message #244243] Tue, 05 June 2007 14:22 Go to previous message
Eclipse UserFriend
Will Horn a écrit :
> This isn't much better, but at least it doesn't make me start thinking
> something is wrong with my syntax or imports. Should I create a bug?
Yes. The problem comes from the grammar.
Technically speaking your code is a syntax error. We might try to see
how we can modify the grammar in order to digest such syntax and reject
the case later.
--
Olivier
Previous Topic:Java Code Formatter from command line
Next Topic:Checking if external jar modified
Goto Forum:
  


Current Time: Fri Jul 18 05:56:36 EDT 2025

Powered by FUDForum. Page generated in 0.11536 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top