-
Enhancement
-
Resolution: Fixed
-
P4
-
1.4.2, 5.0
-
b49
-
x86, sparc
-
solaris_8, windows_xp
-
Verified
Name: gm110360 Date: 08/13/2003
A DESCRIPTION OF THE REQUEST :
Hi! Consider the following code:
String foo = "testing";
String bar = "failure";
if (foo.equals(bar));
{
// do something
}
Due to the semicolon after the comparison, the code block after the code control statement is always executed. To catch this type of programming mistake (which can slip to quite far in the development cycle), javac should warn there's an empty block immediately after the if statement.
JUSTIFICATION :
The enhancement would make javac more useful as a development tool. I can't come up with a single useful code sample with would utilize the described (faulty) code structure so logically a warning should be given to the programmer.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
During compilation of the above code, a warning in style
WARNING! Empty code block following a code control structure on line 123: if (foo.equals(bar));
ACTUAL -
No warnign is given.
---------- BEGIN SOURCE ----------
String foo = "testing";
String bar = "failure";
if (foo.equals(bar));
{
// do something
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Not applicable.
(Incident Review ID: 198976)
======================================================================
A DESCRIPTION OF THE REQUEST :
Hi! Consider the following code:
String foo = "testing";
String bar = "failure";
if (foo.equals(bar));
{
// do something
}
Due to the semicolon after the comparison, the code block after the code control statement is always executed. To catch this type of programming mistake (which can slip to quite far in the development cycle), javac should warn there's an empty block immediately after the if statement.
JUSTIFICATION :
The enhancement would make javac more useful as a development tool. I can't come up with a single useful code sample with would utilize the described (faulty) code structure so logically a warning should be given to the programmer.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
During compilation of the above code, a warning in style
WARNING! Empty code block following a code control structure on line 123: if (foo.equals(bar));
ACTUAL -
No warnign is given.
---------- BEGIN SOURCE ----------
String foo = "testing";
String bar = "failure";
if (foo.equals(bar));
{
// do something
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Not applicable.
(Incident Review ID: 198976)
======================================================================
- duplicates
-
JDK-6217488 Improperly formatted if-statement slips past the syntax checker.
-
- Closed
-