Bug 32285 - DCR - extra java compiler markers
Summary: DCR - extra java compiler markers
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 2.1   Edit
Hardware: All All
: P3 enhancement (vote)
Target Milestone: 3.0 M3   Edit
Assignee: Philipe Mulet CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 24307 40569 (view as bug list)
Depends on:
Blocks:
 
Reported: 2003-02-19 15:26 EST by Nikolay Metchev CLA
Modified: 2003-08-28 12:51 EDT (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Nikolay Metchev CLA 2003-02-19 15:26:34 EST
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!
Comment 1 Nikolay Metchev CLA 2003-02-20 05:24:41 EST
I am not sure why this bug is unconfirmed! Shouldn't it be new?
Comment 2 Philipe Mulet CLA 2003-02-20 05:31:31 EST
No clue how it got entered as unconfirmed...
Comment 3 Philipe Mulet CLA 2003-02-20 05:31:55 EST
Not for 2.1, nice suggestion will consider at some later stage.
Comment 4 Nikolay Metchev CLA 2003-07-10 09:11:05 EDT
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?
Comment 5 Philipe Mulet CLA 2003-07-10 09:39:36 EDT
Let's resurrect it. No strong commitment for now. But these are definitely nice 
suggestions.
Comment 6 Philipe Mulet CLA 2003-07-15 04:42:38 EDT
As Erich mentionned, a commented catch block should not be flagged as empty.
Comment 7 Philipe Mulet CLA 2003-07-16 12:33:06 EDT
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 */ }

      
Comment 8 Philipe Mulet CLA 2003-07-16 17:49:25 EDT
Actually, I'd be tempted to say that the comment must be inside the block (i.e. 
ignore trailing line comment).
Comment 9 Erich Gamma CLA 2003-07-16 18:38:13 EDT
I agree - only comments inside the block count.
Comment 10 Nikolay Metchev CLA 2003-07-17 04:11:19 EDT
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.
Comment 11 Philipe Mulet CLA 2003-07-17 05:59:43 EDT
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();
Comment 12 Nikolay Metchev CLA 2003-07-17 06:05:24 EDT
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!
Comment 13 Philipe Mulet CLA 2003-07-17 06:21:09 EDT
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.
Comment 14 Philipe Mulet CLA 2003-07-20 16:55:19 EDT
Made distinct PR for "method could be static" DCR, see bug 40536.
Comment 15 Philipe Mulet CLA 2003-07-20 16:56:35 EDT
Added support for signaling empty blocks which aren't documented. The diagnosis 
will find also empty methods and empty type declarations.

Fixed.
Comment 16 Philipe Mulet CLA 2003-07-22 04:10:49 EDT
*** Bug 40569 has been marked as a duplicate of this bug. ***
Comment 17 David Audel CLA 2003-08-28 04:42:37 EDT
Verified.
Comment 18 Philipe Mulet CLA 2003-08-28 12:51:49 EDT
*** Bug 24307 has been marked as a duplicate of this bug. ***