| Summary: | [compiler] Access to protected overloaded methods/constructors in foreign plug-in if in same package | ||
|---|---|---|---|
| Product: | [Eclipse Project] JDT | Reporter: | Niko Stotz <eclipse> |
| Component: | Core | Assignee: | JDT-Core-Inbox <jdt-core-inbox> |
| Status: | CLOSED INVALID | QA Contact: | |
| Severity: | normal | ||
| Priority: | P3 | CC: | sasikanth.bharadwaj, stephan.herrmann |
| Version: | 4.7.1a | ||
| Target Milestone: | --- | ||
| Hardware: | PC | ||
| OS: | Windows 7 | ||
| Whiteboard: | stalebug | ||
Access to protected members is allowed with in the same package as they are declared in, so I don't see anything wrong with the compiler behavior itself as such. The run time error *may be * a result of java9. Need to investigate how things worked before java9 I ran this on Java8, so at least the runtime part should not be affected by Java9. This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet. As such, we're closing this bug. If you have further information on the current state of the bug, please add it and reopen this bug. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant. -- The automated Eclipse Genie. Compiler (and JLS) knows nothing about plug-ins, the boundaries are packages, not plug-ins. As Sasi pointed out the compiler is correct in this regard. |
Using Eclipse 4.7.1a (Oxygen.1a) Build id: 20171005-1200 The compiler binds method / constructor calls to protected class members in the same package in a foreign plug-in, even though there would be a public binding. This leads to IllegalAccessError on execution in an OSGi environment. Example: plug-in A (exports package a.b): package a.b; public class Target { public Target() {} // this should be bound in Caller.illegalAccessToProtectedConstructor*() public Target(Number n) {} // this is bound in Caller.illegalAccessToProtectedConstructor*() protected Target(Integer i) {} // this should be bound in Caller.illegalAccessToProtectedFunction*() public int f(Number n) { return 1; } // this is bound in Caller.illegalAccessToProtectedFunction*() protected int f(Integer i) { return 2; } } plug-in B (depends on A): package a.b; import a.b.Target; import static org.junit.Assert.assertEquals; import org.junit.Test; public class Caller { @Test public void illegalAccessToProtectedConstructorNull() throws Exception { new Target(null); } @Test public void illegalAccessToProtectedConstructor() throws Exception { new Target(new Integer(1)); } @Test public void validAccessToPublicConstructor() throws Exception { new Target((Number) new Integer(1)); } @Test public void validAccessToPublicFunction() throws Exception { Target target = new Target(); assertEquals(1, target.f((Number) null)); } @Test public void illegalAccessToProtectedFunctionNull() throws Exception { Target target = new Target(); assertEquals(2, target.f((Integer) null)); } @Test public void illegalAccessToProtectedFunction() throws Exception { Target target = new Target(); assertEquals(2, target.f(new Integer(1))); } }