Community
Participate
Working Groups
I would like to propose two extra java compiler style warnings. 1.One would be empty methods i.e. methods with no implementation: public void method(){} 2.The other would be empty catch blocks e.g: try{ ... } catch(Exception e){} // <-- empty catch block flag as a warning!
I am not sure why this bug is unconfirmed! Shouldn't it be new?
No clue how it got entered as unconfirmed...
Not for 2.1, nice suggestion will consider at some later stage.
I have another compiler marker that we could have. That is a method could be static marker. i.e. check if a method accesses local variables or calls non- static methods and if not mark that method as "should be static". Any chance these markers could be addressed for 3.0?
Let's resurrect it. No strong commitment for now. But these are definitely nice suggestions.
As Erich mentionned, a commented catch block should not be flagged as empty.
For empty blocks, why only flagging empty catch blocks as opposed to any uncommented empty block ? e.g. if (someCondition) { } This looks equally suspicious to me... Also, should a block with trailing line comment be tolerated as commented ? try { ... } catch (Exception e) {} // ignore or should we impose clients to write try { ... } catch (Exception e) { /* ignore */ }
Actually, I'd be tempted to say that the comment must be inside the block (i.e. ignore trailing line comment).
I agree - only comments inside the block count.
It could be argued that even blocks of empty code with comments are bad. You can always put a log message and make sure that you log it as "fine" detail.
This is true, however if user inserted a comment, then he probably meant to have such an empty block. Requiring to log is likely asking too much, or writing dummy code, e.g.: if (false) e.printStackTrace();
writing dummy code is wrong. You are assuming that the programmer will want to deal with this particular warning. If they just want to have a comment they can just ignore this warning!
We agree that dummy code would be bad, however if the block is intended to be left empty, then there should be a way for the user to mean this, and have this warning go away. If you start tolerating some warnings, then when scaling you will miss new warnings easily... the simplest approach is to fix them, not ignore them.
Made distinct PR for "method could be static" DCR, see bug 40536.
Added support for signaling empty blocks which aren't documented. The diagnosis will find also empty methods and empty type declarations. Fixed.
*** Bug 40569 has been marked as a duplicate of this bug. ***
Verified.
*** Bug 24307 has been marked as a duplicate of this bug. ***