Bug 126564 - [1.5][compiler] Inconsistent error reporting between static import and direct field access
Summary: [1.5][compiler] Inconsistent error reporting between static import and direct...
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.2   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.2 M5   Edit
Assignee: Philipe Mulet CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-02-06 10:01 EST by Olivier Thomann CLA
Modified: 2006-02-15 09:55 EST (History)
3 users (show)

See Also:


Attachments
Proposed fix (6.30 KB, patch)
2006-02-13 09:58 EST, Philipe Mulet CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Olivier Thomann CLA 2006-02-06 10:01:07 EST
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.
Comment 1 Olivier Thomann CLA 2006-02-06 11:19:23 EST
A.java:
package p;

public class A implements I {
}

I.java:
package p;

interface I {
	int CONST = 1;
}
Comment 2 Kent Johnson CLA 2006-02-06 12:30:42 EST
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; }
Comment 3 Kent Johnson CLA 2006-02-06 16:12:00 EST
Added StaticImportTest test36 to catch all the cases
Comment 4 Philipe Mulet CLA 2006-02-11 08:39:04 EST
Fix is breaking other scenarii, non based on static imports.
Comment 5 Philipe Mulet CLA 2006-02-11 08:45:40 EST
Added LookupTest#test058 for broken scenario example.
Removed entry from buildnotes, and removed fix for bug 126564 from HEAD.

Comment 6 Philipe Mulet CLA 2006-02-13 07:02:20 EST
Also what about static method invocations ?
Comment 7 Philipe Mulet CLA 2006-02-13 07:13:42 EST
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.
Comment 8 Philipe Mulet CLA 2006-02-13 07:15:55 EST
JLS 6.4.3
Comment 9 Philipe Mulet CLA 2006-02-13 07:45:40 EST
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.
Comment 10 Philipe Mulet CLA 2006-02-13 09:58:46 EST
Created attachment 34569 [details]
Proposed fix
Comment 11 Philipe Mulet CLA 2006-02-13 10:06:51 EST
haven't check the story for method imports.
Comment 12 Philipe Mulet CLA 2006-02-13 15:40:52 EST
Added more tests: StaticImportTest#test037-039, including method scenarii (appears we were fine there).
Released patch for M5.
Kent - pls double check
Comment 13 Jerome Lanneluc CLA 2006-02-15 09:55:07 EST
Verified for 3.2 M5 using build I20060215-0010