Bug 325157 - [1.5][compiler] Contrary behaviour to Sun's compiler concerning visibility of private static methods to enclosed static classes
Summary: [1.5][compiler] Contrary behaviour to Sun's compiler concerning visibility of...
Status: VERIFIED INVALID
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.6   Edit
Hardware: PC Linux
: P3 normal (vote)
Target Milestone: 3.7 M3   Edit
Assignee: Srikanth Sankaran CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-09-13 15:49 EDT by Andrey Loskutov CLA
Modified: 2010-10-26 07:47 EDT (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Andrey Loskutov CLA 2010-09-13 15:49:39 EDT
The followed code compiles in Eclipse 3.6 but doesn't with sun javac from JDK 1.6.0_20. javac reports one error:

ConcreteClass.java:9: getText() in AClass cannot be applied to(java.lang.String)

----------------------
public class AClass {
	public String getText() {
		return "";
	}
}
----------------------
public class ConcreteClass extends AClass {
	private static String getText(String arg) {
		return arg;
	}
	static class StaticClass extends ConcreteClass {
		public String getAbbreviatedText(int endIndex){
			return getText("").substring(0, endIndex);
		}
	}
}
----------------------
Comment 1 Srikanth Sankaran CLA 2010-09-14 00:13:58 EDT
Interesting example. While the nested class doesn't have
access to the super class's private method, the super class
also happens to be the enclosing class and as such it has
access to the enclosing class's private method. Not clear
immediately that the bug is with eclipse and not with javac.

See that the code compiles alright with javac if you remove
the extends clause.

I'll follow up.
Comment 2 Srikanth Sankaran CLA 2010-09-20 04:23:25 EDT
This looks like a javac bug. Have you reported this to Sun ?
The javac compiler seems to exhibit some interesting behavior:

case (1)  (same case as comment#0, but in one file)
--------

public class ConcreteClass 
	extends AClass 
{
    private static String getText(String arg) {
        return arg;
    }
    static class StaticClass 
		    extends ConcreteClass 
    {
        public String getAbbreviatedText(int endIndex){
            return getText("").substring(0, endIndex);
        }
    }
}

class AClass {
    public String getText() {
        return "";
    }
}

JDK5,6,7 refuse to compile this.

case (2) 
--------


public class ConcreteClass 
//	extends AClass   // extends commented out.
{
    private static String getText(String arg) {
        return arg;
    }
    static class StaticClass 
		    extends ConcreteClass 
    {
        public String getAbbreviatedText(int endIndex){
            return getText("").substring(0, endIndex);
        }
    }
}

class AClass {
    public String getText() {
        return "";
    }
}

JDK5,6,7 compile this OK.

case (3)
--------

public class ConcreteClass 
	extends AClass 
{
    private static String getText(String arg) {
        return arg;
    }
    static class StaticClass 
//		    extends ConcreteClass   // extends commented out
    {
        public String getAbbreviatedText(int endIndex){
            return getText("").substring(0, endIndex);
        }
    }
}

class AClass {
    public String getText() {
        return "";
    }
}

JDK5,6,7, compile this OK.

case (4)
--------

// AClass is totally out of the picture
public class ConcreteClass 
{
    private static String getText(String arg) {
        return arg;
    }
    static class StaticClass 
		    extends ConcreteClass 
    {
        public String getAbbreviatedText(int endIndex){
            return getText("").substring(0, endIndex);
        }
    }
}


JDK5,6,7 compile this OK.

case (5)
--------

// private method changed to public.
public class ConcreteClass extends AClass {
    public String getText(String arg) {    // Note private changed to public
        return arg;
    }
    class StaticClass extends ConcreteClass {
        public String getAbbreviatedText(int endIndex){
            return getText("").substring(0, endIndex);
        }
    }
}

class AClass {
    public String getText() {
        return "";
    }
}

compiles OK with JDK5,6,7.

In summary, the method is accessible and applicable, so I don't see
why the code should be rejected at all.
Comment 3 Andrey Loskutov CLA 2010-09-20 16:33:34 EDT
Hi Srikanth, thanks for the evaluation.

I've submitted a new bug report (I couldn't find existing one, the search on sun/oracle bug database delivers too much unrelated stuff).

As usually, you never receive any immediate feedback, but if I have luck and they will accept the bug, I will post here a link to it.

Regards,
Andrei
Comment 4 Srikanth Sankaran CLA 2010-09-22 00:25:54 EDT
(In reply to comment #3)
> Hi Srikanth, thanks for the evaluation.
> 
> I've submitted a new bug report 

Hi Andrei,

Thanks for following this up with Sun/Oracle.
Can you share the defect number ? Thanks.
Comment 5 Andrey Loskutov CLA 2010-09-22 02:56:20 EDT
Here is a link (still not accessible):
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6986202
Comment 6 Srikanth Sankaran CLA 2010-10-22 00:34:34 EDT
Closing this as INVALID, as this is very likely a javac
compiler bug. If Sun/Oracle disagree with justification,
please reopen.
Comment 7 Jay Arthanareeswaran CLA 2010-10-26 07:47:02 EDT
Verified for 3.7M3