Community
Participate
Working Groups
Using latest, compile the following test case: 1) Compile first A and I 2) Compile X using A and I as binaries. - first case: using static import: import static p.A.CONST; public class X { public static int CONSTANT = CONST; } this reports the following error: ---------- 1. ERROR in d:\tests_sources\X.java (at line 4) public static int CONSTANT = CONST; ^^^^^ The type I is not visible ---------- 1 problem (1 error) - second case: direct field access: public class X { public static int CONSTANT = p.A.CONST; } this compiles fine. Both cases should lead to the first error.
A.java: package p; public class A implements I { } I.java: package p; interface I { int CONST = 1; }
This is a bug with inheriting constants thru a superinterface. Even using jdk1.4, this case should fail for both fields but it doesn't: class X { static int i = p.A.CONSTANT_I; // should report that I is not visible static int j = p.A.CONSTANT_B; // correctly reports that B is not visible } package p; public class A extends B implements I {} interface I { int CONSTANT_I = 1; } class B { int CONSTANT_B = 1; }
Added StaticImportTest test36 to catch all the cases
Fix is breaking other scenarii, non based on static imports.
Added LookupTest#test058 for broken scenario example. Removed entry from buildnotes, and removed fix for bug 126564 from HEAD.
Also what about static method invocations ?
Javac had same bug: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6225935 According to JLS all accessible members from supertypes are ok to reach. I don't see any check to be done on declaring class thus.
JLS 6.4.3
I believe testcases should be accepted. Static import resolution is wrong. It does check declaringClass visibility which it shouldn't. However, it should instead check visibility of target field against receiver type: import static p.A.CONST; 1. check that p.A is visible from unit scope 2. check that CONST is visible from p.A within unit scope and import reference as invocation site.
Created attachment 34569 [details] Proposed fix
haven't check the story for method imports.
Added more tests: StaticImportTest#test037-039, including method scenarii (appears we were fine there). Released patch for M5. Kent - pls double check
Verified for 3.2 M5 using build I20060215-0010