Bug 29030 - Compiler Bug -- incorrect visibility of protected constructors
Summary: Compiler Bug -- incorrect visibility of protected constructors
Status: RESOLVED INVALID
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 2.1   Edit
Hardware: PC Windows 2000
: P3 normal (vote)
Target Milestone: 2.1 M5   Edit
Assignee: JDT-Core-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2003-01-06 09:53 EST by Marco Qualizza CLA
Modified: 2003-01-07 16:49 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 Marco Qualizza CLA 2003-01-06 09:53:48 EST
In the following example (which compiles fine with both Sun 1.3.1_06 & Sun
1.4.1_01), Eclipse claims that the constructor A() is not visible in B:
public class A {
   protected A _instance = new A();

   protected A() {}
}

public class B extends A {
   public static void resetInstance() {
      _instance = new A();
}
Comment 1 Olivier Thomann CLA 2003-01-06 16:09:59 EST
Could you please specify which build you are using?

Using 2.1 latest code, I got:
----------
1. ERROR in D:\temp\B.java (at line 3)
	_instance = new A();
	^^^^^^^^^
Cannot make a static reference to the non-static field _instance
----------
1 problem (1 error)

I had to add a closing '}' in B. My test case is:
1) save this code in A.java:
public class A {
   protected A _instance = new A();

   protected A() {}
}
2) save this code in B.java:
public class B extends A {
   public static void resetInstance() {
      _instance = new A();
	}
}
3) Compile both using the batch compiler or a self-hosting workspace.

If I remove the static modifier in B, then it compiles fine.

Could you please provide the exact steps to reproduce?

Thanks for the report.
Comment 2 Marco Qualizza CLA 2003-01-06 16:26:02 EST
I'm sorry for the bugs in the example and lost details -- I was doing it from
memory.  I've reverified, and here are the class definitions.  The important
part is that B is not in the same package as A.  This was done with M4.  The
error I get is "The constructor A() is not visible."

------------

package main;

public class A {
   protected static A _instance = new A();

   protected A() {}
}

------------

package main.test;

import main.A;

public class B extends A {
   public static void resetInstance() {
      _instance = new A();
   }
}
Comment 3 Marco Qualizza CLA 2003-01-06 16:49:46 EST
And, after thinking about it, I redid the test using SDK 1.4.1_01 and SDK
1.3.1_06 (I think that I forgot the packages when I tested the first time) and
it fails there too.  My apologies.
Comment 4 Olivier Thomann CLA 2003-01-07 13:24:34 EST
Ok to close?
Comment 5 Marco Qualizza CLA 2003-01-07 13:27:01 EST
Yes, my bad.
Comment 6 Olivier Thomann CLA 2003-01-07 16:49:05 EST
Close as INVALID.