This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 184673 - Warning for redundant modifiers involving interfaces - plugin available
Summary: Warning for redundant modifiers involving interfaces - plugin available
Status: NEW
Alias: None
Product: java
Classification: Unclassified
Component: Hints (show other bugs)
Version: 6.x
Hardware: All All
: P4 normal with 1 vote (vote)
Assignee: Svata Dedic
URL: http://bugs.sun.com/bugdatabase/view_...
Keywords:
: 236797 (view as bug list)
Depends on:
Blocks:
 
Reported: 2010-04-21 18:35 UTC by Jesse Glick
Modified: 2016-07-01 18:40 UTC (History)
1 user (show)

See Also:
Issue Type: ENHANCEMENT
Exception Reporter:


Attachments
Start of patch (8.62 KB, patch)
2010-04-21 18:35 UTC, Jesse Glick
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Jesse Glick 2010-04-21 18:35:26 UTC
Created attachment 97820 [details]
Start of patch

See javac RFE. I think it would be good to have the NetBeans editor warn about unnecessary modifiers, since they clutter code, and their presence can mislead you into thinking that their _absence_ in other cases is meaningful.

I have tried to implement case #1 but got stuck - the unit test fails (and I can really reproduce the problems in the editor). It seems that ClassTree.getModifiers() includes synthetic modifiers not present in the source code (due to javac.comp.Check.checkFlags and/or javac.comp.Enter.visitClassDef?), and I have no idea how to get the literal list of modifiers from the source code.
Comment 1 Jan Lahoda 2010-04-22 11:58:39 UTC
I would personally prefer opposite - a hint that would warn about missing public and public static for interface methods and constants/classes, as that makes the meaning very clear. Would also catch the situation with class being public by accident (without depending on the user to notice anything).

AFAIK, the only way to check the modifiers is to check the actual tokens in the source code (using e.g. CompilationInfo.getTokenHierarchy).
Comment 2 Jesse Glick 2010-04-22 18:21:52 UTC
(In reply to comment #1)
> I would personally prefer opposite

I guess both sets of hints could be present and disabled by default. But note that the JLS in several cases specifically discourages use of redundant modifiers. For example, 9.4:

"It is permitted, but strongly discouraged as a matter of style, to redundantly specify the public modifier for interface methods."

In other cases it is silent. In no case that I know of does it recommend specifying a redundant modifier.

> the only way to check the modifiers is to check the actual tokens in the
> source code (using e.g. CompilationInfo.getTokenHierarchy).

Hmm, sounds messy, but I will try it when I get a chance.
Comment 3 markiewb 2013-11-25 23:19:50 UTC
*** Bug 236797 has been marked as a duplicate of this bug. ***
Comment 4 markiewb 2013-11-25 23:22:22 UTC
FYI: Fixed in 1.1.0 of the additional hints plugin https://github.com/markiewb/nb-additional-hints/issues/14 . 

There is a hint which removes the redundant modifiers.
Comment 5 Jesse Glick 2013-12-04 20:25:47 UTC
@markiewb: nice, seems to work also in Inspect & Transform. Note that you are missing some cases of redundant modifiers, e.g. ‘public’ and/or ‘static’ on nested classes.
Comment 6 markiewb 2013-12-04 21:09:29 UTC
(In reply to Jesse Glick from comment #5)
> @markiewb: nice, seems to work also in Inspect & Transform. 

Thank you. Fixes based on org.netbeans.spi.java.hints.JavaFix provide this out-of-the-box AFAIK.

> Note that you
> are missing some cases of redundant modifiers, e.g. ‘public’ and/or ‘static’
> on nested classes.
Please report more missing combinations at 
https://github.com/markiewb/nb-additional-hints/issues/24 and I will add them.
Comment 7 markiewb 2014-05-14 17:36:56 UTC
FYI: the plugin http://plugins.netbeans.org/plugin/47589/additional-hints version 1.2.0 provides the requested hint/quickfix

So set the prio to P4