Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 200588

Summary: super.field access to protected member of superclass should be a compile-time errror
Product: [Eclipse Project] JDT Reporter: Henning Makholm <henning>
Component: CoreAssignee: 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

Description Henning Makholm CLA 2007-08-20 14:03:17 EDT
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.
Comment 1 Olivier Thomann CLA 2007-08-21 15:13:50 EDT
Note that javac 1.4.2, 1.5.0 and 1.6 report the same error as the Eclipse compiler.
Comment 2 Olivier Thomann CLA 2007-08-21 15:17:20 EDT
I forgot to mention that jikes also reports an error only for the third case.
Comment 3 Kent Johnson CLA 2007-08-24 15:34:25 EDT
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.
Comment 4 Eclipse Genie CLA 2020-04-21 05:25:26 EDT
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.
Comment 5 Stephan Herrmann CLA 2020-04-21 07:27:10 EDT
still today, ecj & javac agree in this matter.