| Summary: | super.field access to protected member of superclass should be a compile-time errror | ||
|---|---|---|---|
| Product: | [Eclipse Project] JDT | Reporter: | Henning Makholm <henning> |
| Component: | Core | Assignee: | JDT-Core-Inbox <jdt-core-inbox> |
| Status: | CLOSED WONTFIX | QA Contact: | |
| Severity: | normal | ||
| Priority: | P5 | CC: | Olivier_Thomann, stephan.herrmann |
| Version: | 3.4 | ||
| Target Milestone: | --- | ||
| Hardware: | PC | ||
| OS: | Windows XP | ||
| Whiteboard: | stalebug | ||
Note that javac 1.4.2, 1.5.0 and 1.6 report the same error as the Eclipse compiler. I forgot to mention that jikes also reports an error only for the third case. For a spec issue, you should report the problem to Sun. In the past, even when we agree with a reporter's interpretation of the spec, we're stuck between changing our behaviour and maintaining compatibility with javac. Please update this bug with any information you get from reporting the issue to Sun. 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. still today, ecj & javac agree in this matter. |
Build ID: I20070625-1500 Consider the following two Java source files: package a; public class S { protected int name = 42 ; } and package b; import a.S; public class C extends S { static public void main(String[] args) { new C().foo(); } public void foo() { System.out.println(name); // 1 System.out.println(super.name); // 2 System.out.println(((S)this).name); // 3 } } The Eclipse compiler will accept the lines marked 1 and 2, but will report an access violation in the line marked 3. According to section 15.11.2 of the JLS (third edition), the expression super.name must be "treated exactly as if it had been the expression ((S)this).name", so either both of them should be errors or none of them should. My understanding of the JLS is that both should be errors, because the second condition of 6.6.2.1 is not satisfied by ((S)this).name. There seems to be nothing in JLS section 6.6.2 on protected access that special-cases super.name such that it should be treated differently from its unfolding with regard to access.