Bug 497718 - Calling private static method from subclass instance overload
Summary: Calling private static method from subclass instance overload
Status: NEW
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 4.5.2   Edit
Hardware: PC Windows 7
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: JDT-Core-Inbox CLA
QA Contact:
URL:
Whiteboard: stalebug
Keywords: helpwanted
Depends on:
Blocks:
 
Reported: 2016-07-11 20:39 EDT by Yosef Bart CLA
Modified: 2022-09-16 11:05 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 Yosef Bart CLA 2016-07-11 20:39:19 EDT
abstract class Test {
    
    private static void bar(int arg) {
    }

    abstract void bar();
    
    static class Foo extends Test {
        @Override
        void bar() {
            bar(1);
        }
    }
}

The above snippet compiles in eclipse, but throws the following error in javac (1.8.0_65-b17):

error: no suitable method found for bar(int)
            bar(1);
            ^
    method Test.bar() is not applicable
      (actual and formal argument lists differ in length)
    method Foo.bar() is not applicable
      (actual and formal argument lists differ in length)

I'm not sure which behavior is correct.
Comment 1 Stephan Herrmann CLA 2016-07-12 06:29:03 EDT
Thanks for the test case.

If you qualify the method call like this:
   Test.bar(1);
also javac will agree that this method is accessible.

It seems to be an issue of shadowing not detected by ecj, read: if Foo.bar() shadows Test.bar(int) then the latter cannot be referred to using the simple name "bar". 

I don't think that inheritance plays a role here (private methods are never inherited). If it were a case of inheritance, we'd be speaking of hiding of an inherited static method by an instance method, for which I don't readily see any rule in the spec.
Comment 2 Manoj N Palat CLA 2018-05-17 03:22:45 EDT
bulk move out of 4.8
Comment 3 Manoj N Palat CLA 2018-08-16 00:08:11 EDT
Bulk move out of 4.9
Comment 4 Eclipse Genie CLA 2022-09-16 11:05:50 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.