Bug 285002 - [compiler] visibility error for package private method
Summary: [compiler] visibility error for package private method
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.5   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.6 M4   Edit
Assignee: Srikanth Sankaran CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-07-29 09:14 EDT by Michael Chervil CLA
Modified: 2009-12-08 03:22 EST (History)
3 users (show)

See Also:


Attachments
java source showing the possible bug (675 bytes, application/text)
2009-07-29 09:14 EDT, Michael Chervil CLA
no flags Details
Potential patch (6.89 KB, patch)
2009-10-29 07:10 EDT, Srikanth Sankaran CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Michael Chervil CLA 2009-07-29 09:14:53 EDT
Created attachment 142884 [details]
java source showing the possible bug

Using 3.5 I get the compiler error message

"The method packagePrivateMethod() from the type CompilerBug"

for the attached java source at line 18. JavaC doesn't have the problem with the source.

Am I missing something, or is this a bug?
Comment 1 Kent Johnson CLA 2009-07-29 11:50:27 EDT
This is the error I get from javac 7 and eclipse :

CompilerBug.java:17: privateMethod() in CompilerBug is defined in an inaccessibl
e class or interface
      getClass().newInstance().privateMethod();
                              ^
1 error


javac 1.5 & 6 compile it without error


This is a result of the fix for bug 257434
Comment 2 Srikanth Sankaran CLA 2009-08-04 04:38:00 EDT
Verified for 3.6M1
Comment 3 Srikanth Sankaran CLA 2009-10-22 06:13:13 EDT
Reopening this defect to take a closer look.

See that javac & eclipse are complaining about entirely different
lines of code.

// complained about by java 7, but not eclipse.
getClass().newInstance().privateMethod();  
// complained about by eclipse, but not java 7.
getClass().newInstance().packagePrivateMethod();

Eclipse head behavior is at odds with java 7.

Kent, can you comment on it ? Thanks.
Comment 4 Kent Johnson CLA 2009-10-22 10:46:30 EDT
Yes - you're right.

To be compatible with javac 7, we should find the private method not visible.

I'll work on it today - we can talk about it tomorrow morning.
Comment 5 Srikanth Sankaran CLA 2009-10-29 07:10:42 EDT
Created attachment 150812 [details]
Potential patch


Kent, please take a look. I left the behavior about private member
access as it is (as I strongly suspect it is a javac7 bug) and fixed 
only the access problems  package private members.
Comment 6 Kent Johnson CLA 2009-10-29 10:57:20 EDT
The patch looks good.

We just need to clarify whether the 'new' javac 7 behaviour is a bug or not (& I do agree with you that its likely a bug).
Comment 7 Srikanth Sankaran CLA 2009-11-02 09:21:01 EST
Released in HEAD for 3.6M4
Comment 8 Srikanth Sankaran CLA 2009-11-03 00:42:49 EST
The open issue surrounding the private method access, which we believe
is a bug in javac, has been reported to Sun compiler team.
Comment 9 Michael Chervil CLA 2009-11-03 04:29:52 EST
Thank you for reopening and fixing this. It actually even helps me :)

I don't believe Sun will accept the disallowed access to private methods as a compiler bug. 

getClass() returns Class<MyClass>. An instance of Class<MyClass> could be any subclass (in my usecase it IS a subclass). The subclass might also have a private method of the same name. Now which one gets called? Doesn't seem easy to answer. I guess that's the reason why they changed it.
Comment 10 Srikanth Sankaran CLA 2009-11-03 05:17:51 EST
(In reply to comment #9)
> Thank you for reopening and fixing this. It actually even helps me :)

You are welcome. (The recommendation from Sun is to leave the private
method access as it is.)
Comment 11 Jay Arthanareeswaran CLA 2009-12-08 01:59:08 EST
Verified for 3.6M4 using build I20091207-1800