Bug 140481 - [compiler] Warnings: False positive when inaccessible members of base class is "shadowed" by parameter
Summary: [compiler] Warnings: False positive when inaccessible members of base class i...
Status: NEW
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.2   Edit
Hardware: Macintosh Mac OS X - Carbon (unsup.)
: P3 enhancement (vote)
Target Milestone: ---   Edit
Assignee: JDT-Core-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-05-06 15:43 EDT by Gordon Henriksen CLA
Modified: 2016-01-14 12:59 EST (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Gordon Henriksen CLA 2006-05-06 15:43:16 EDT
This class of warning is never useful to me:

    class Base {
      private boolean _bool;
    }
    class Sub extends Base {
      private boolean _bool; // warning
    }

I would like it to be suppressed, or to have an option to disable it. The warning in this case is especially irrelevant when Base is in a separate library.

Broadly, my interest in the shadowing warning is limited to actual shadowing; shadowing which might occur if a private member were to become public in some future revision of a library is of no concern to me.
Comment 1 Gordon Henriksen CLA 2006-05-06 15:46:59 EDT
I'm sorry, I mistook my example. The indicated case is of no concern to me, but I'm not sure it would raise; the warning that's actually biting me is such:

    class Base {
      private boolean bar;
    }
    class Sub extends Base {
      public void foo(
        boolean bar // warning
      ) {}
    }
Comment 2 Jerome Lanneluc CLA 2006-05-09 05:19:21 EDT
I don't get any shadowing warning with 3.2 RC3 with both of your examples.
Please reopen if you have more details on how to reproduce.
Comment 3 Gordon Henriksen CLA 2006-05-19 14:24:26 EDT
Reopening. To reproduce:

1. Create a new project.
2. Open its Settings window.
3. Go to Settings > Java > Compiler > Errors/Warnings.
4. Enable project-specific settings.
5. Under "Name shadowing and conflicts", set "Field declaration hides another field or variable" to 'Error'.
6. Create a new class FalseShadowing in package test, and paste the following source code:

    package test;
    public class FalseShadowing {
        private static class A {
            private static A _instance = new A();
            public A getA() {
                return _instance;
            }
        }
        private static class B extends A {
            private static B _instance = new B();
            public A getB() {
                return _instance;
            }
        }
    }

7. Build, and observe the error:
       The field FalseShadowing.B._instance is hiding a field from type FalseShadowing.A

This error is incorrect, since no actual shadowing occurs. To demonstrate, comment out this line:

    private static B _instance = new B();

And observe that A._instance is not accessible from B.
Comment 4 Gordon Henriksen CLA 2006-05-19 14:25:37 EDT
Reproduced with…

Eclipse SDK
Version: 3.2.0
Build id: I20060505-1306

Mac OS X 10.4.6; uname -a:
Darwin localhost.localdomain 8.6.1 Darwin Kernel Version 8.6.1: Tue Mar  7 16:55:45 PST 2006; root:xnu-792.9.22.obj~1/RELEASE_I386 i386 i386
Comment 5 Eclipse Webmaster CLA 2007-07-29 09:19:49 EDT
Changing OS from Mac OS to Mac OS X as per bug 185991
Comment 6 Philipe Mulet CLA 2007-10-12 09:48:37 EDT
I agree, the warning shouldn't occur. 
The rule should be that it would only arise in a situation where you could reach the hidden declaration (and thus the code is somewhat suspicious). As you said, there is ambiguity here.