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 123955 - [68cat] Hint "Field hides another field" should distinguish between static and instance fields
Summary: [68cat] Hint "Field hides another field" should distinguish between static an...
Status: RESOLVED FIXED
Alias: None
Product: java
Classification: Unclassified
Component: Hints (show other bugs)
Version: 6.x
Hardware: PC Windows XP
: P4 blocker with 2 votes (vote)
Assignee: Jan Lahoda
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-12-13 14:02 UTC by matthies
Modified: 2011-03-04 05:44 UTC (History)
1 user (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description matthies 2007-12-13 14:02:48 UTC
The hint "Field hides another field" is indiscriminately applied to both static and instance fields. It arguably makes 
less sense for static fields, though. In contrast to instance fields, static fields are normally referenced by 
explicitly stating the specific class (even if by a static import statement), and therefore, while one static field 
may "shadow" another one, the other one is still accessible by stating the appropriate class. Compare also with static 
methods, where you probably wouldn't add such a warning.

The hint should either be restricted to when the field being hidden is an instance field (because this is the case 
where hiding the field means making it inaccessible), regardless of whether the hiding field is itself an instance 
field or a static field, or the hint should be turned into two hints, one for instance fields being hidden and one for 
static fields being hidden. (If you want to go the whole route, you can even make it four hints, by also discriminating 
on the kind of the hiding field, but I don't quite see the necessity for that.)

The situation where I most often come across this unwanted warning is for classes that have a predefined instance 
stored in a static final field named "DEFAULT" or "INSTANCE" or the like (either because there is an obvious default, 
or because all exact-type instances behave the same) while still being extendable (non-final). For example:

    public class FooStrategy {
        ...
        public static final FooStrategy INSTANCE = new FooStrategy();
    }

    public class SomewhatModifiedFooStrategy extends FooStrategy {
        ...
        public static final SomewhatModifiedFooStrategy INSTANCE
            // don't want a warning hint here
            = new SomewhatModifiedFooStrategy();
    }
Comment 1 Jaroslav Tulach 2007-12-14 21:20:42 UTC
I do not think this is a bug. More just an enhancement. If it should be fixed, then I suggest to split the hint into 
two and let user enable/disable each of them. As I personally would like this to hint to apply to static instances as 
well.

Jan, I am reassigning back to you, as I do not think I should be responsible for non-critical issue in this area 
anymore.
Comment 2 nleck 2009-03-02 04:57:45 UTC
We generate static fields into the Java files. It would be great to be able to just turn off the static field check or
be able to add a notation to disable it on a field by field bases. 
Comment 3 matthies 2009-10-27 23:22:50 UTC
Still reproducable in 6.8 Beta.
Comment 4 nleck 2009-10-28 01:45:29 UTC
can we be able to suppress this like we can other hints ? 

in our code we have a static final field in each generated source file so this hint is shown in all classes. 
Comment 5 Jan Lahoda 2011-03-03 12:08:41 UTC
I have added an option to disable the hint in this case:
http://hg.netbeans.org/jet-main/rev/ed6f67e0fe75
Comment 6 Quality Engineering 2011-03-04 05:44:12 UTC
Integrated into 'main-golden', will be available in build *201103040000* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)
Changeset: http://hg.netbeans.org/main/rev/ed6f67e0fe75
User: Jan Lahoda <jlahoda@netbeans.org>
Log: #123955: adding option to disable the HideField when the hidden field is static.