> There are semicolons after the if statement. Get rid of them.

Signature
Unemployed English Java programmer
http://jroller.com/page/tackline/
>>> if(result.contains(EnumTest.ONE));
>>> {
[quoted text clipped - 3 lines]
> I once spent a day or two trying to optimise some embedded code before I
> realised I had a semicolon in the middle of an if statement
Lucky you. Early in my career I spent a week trying to debug a problem
like this (and I use that term loosely because the only debugging tool I
had was printf and this was in an interrupt so I couldn't call printf).
After a week I decided to scrap it and rewrite it without the
interrupts. It wasn't until I was half-way done rewriting it that I
found the semicolon. And of course I didn't keep a copy of the old code.
Doh!
> (pessimising the code would have actually made it sound better).
Did you ever read the famous "Pessimal algorithms and simplexity
analysis" paper? It is a must read:
http://www.cs.uiuc.edu/class/fa05/cs473ug/resources/pessimal-algorithms.pdf
> So, always put opening braces where god intended (and as instructed by
> the Java coding standard). And never treat them as optional in
> if/else/for/do/while statements (except in the else-if chain
> idiom).</code-style-police>
And using a tool like checkstyle to enforce it.

Signature
Dale King
Oliver Wong - 01 Jun 2006 15:30 GMT
>>>> if(result.contains(EnumTest.ONE));
>>>> {
>>
>>> There are semicolons after the if statement. Get rid of them.
[...]
>> So, always put opening braces where god intended (and as instructed by
>> the Java coding standard). And never treat them as optional in
>> if/else/for/do/while statements (except in the else-if chain
>> idiom).</code-style-police>
>
> And using a tool like checkstyle to enforce it.
FWIW, here's how I discovered the problem: I took the OP's SSCCE, copied
and pasted it into Eclipse, and hit CTRL-F to have Eclipse automatically
format the code for me. I always do this before actually reading the SSCCE,
because USENET tends to mangle the indentation. Eclipse formatted the code
as:
if(result.contains(EnumTest.ONE))
;
{
bla bla bla;
}
so it was immediately obvious to me what the problem was.
- Oliver
Ulrich Scholz - 02 Jun 2006 09:58 GMT
My suggestion is to have Eclipse mark empty block the same way as,
e.g., unused variables are marked. I had a short look at the Eclipse
homepage but I couldn't find the proper place to place this suggestion.
Any ideas?
Ulrich
Patricia Shanahan - 02 Jun 2006 14:01 GMT
> My suggestion is to have Eclipse mark empty block the same way as,
> e.g., unused variables are marked. I had a short look at the Eclipse
> homepage but I couldn't find the proper place to place this suggestion.
> Any ideas?
>
> Ulrich
If they do that, it needs to be balanced by some annotation or other
convention to indicate that the programmer really meant the empty block.
Before annotations, I used:
while(some_complex_condition){
// EMPTY
}
Patricia
Dale King - 02 Jun 2006 14:48 GMT
>> My suggestion is to have Eclipse mark empty block the same way as,
>> e.g., unused variables are marked. I had a short look at the Eclipse
[quoted text clipped - 10 lines]
> // EMPTY
> }
And this is why I suggested checkstyle which has an eclipse plug-in. You
can configure it to generate warnings or errors in Eclipse if you are
missing braces, have empty statements (standalone ;), or empty blocks.
The empty block check can be configured to require an actual statement
or just text (i.e. a comment). You can also configure it differently
based on what type of block (e.g. allow only comments for catch but
require a statement for if and else).
See:
http://checkstyle.sourceforge.net/config_blocks.html#NeedBraces
http://checkstyle.sourceforge.net/config_coding.html#EmptyStatement
http://checkstyle.sourceforge.net/config_blocks.html#EmptyBlock

Signature
Dale King
Christian Kaufhold - 04 Jun 2006 11:56 GMT
> If they do that, it needs to be balanced by some annotation or other
> convention to indicate that the programmer really meant the empty block.
> while(some_complex_condition){
continue;
> }
Oliver Wong - 02 Jun 2006 14:52 GMT
> My suggestion is to have Eclipse mark empty block the same way as,
> e.g., unused variables are marked. I had a short look at the Eclipse
> homepage but I couldn't find the proper place to place this suggestion.
> Any ideas?
https://bugs.eclipse.org/bugs/enter_feature.cgi
- Oliver