Bug 334622 - Eclipse compiler allows access to private fields for typed variables
Summary: Eclipse compiler allows access to private fields for typed variables
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.7   Edit
Hardware: All Windows 7
: P3 normal (vote)
Target Milestone: 3.7 M6   Edit
Assignee: Srikanth Sankaran CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 362969 (view as bug list)
Depends on:
Blocks:
 
Reported: 2011-01-18 06:09 EST by Kasper Nielsen CLA
Modified: 2019-08-23 17:35 EDT (History)
4 users (show)

See Also:


Attachments
Patch under consideration (8.08 KB, patch)
2011-02-08 05:20 EST, Srikanth Sankaran CLA
no flags Details | Diff
Revised patch under test (13.19 KB, patch)
2011-02-08 06:37 EST, Srikanth Sankaran CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Kasper Nielsen CLA 2011-01-18 06:09:27 EST
Build Identifier: 20100917-0705

The Eclipse compiler allows the following to compile. According to JLS section 4.4 this should result in a compile-time exception.
http://java.sun.com/docs/books/jls/third_edition/html/typesValues.html#4.4 (Discussion)

public class Wtf {
    private Object foo;
    
    public <T extends Wtf> void test(T t) {
        System.out.println(t.foo);
    }
}


Reproducible: Always

Steps to Reproduce:
Compile the source code
Comment 1 Ayushman Jain CLA 2011-01-18 06:18:05 EST
This code compiles fine with java 6, but fails with java 7. 
Srikanth, please investigate. Thanks!
Comment 2 Kasper Nielsen CLA 2011-01-18 08:47:45 EST
Changes were made to the the java 7 compiler to bring the compiler in accordance with JLS

see:

http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6558551
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6644562
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6711619
Comment 3 Srikanth Sankaran CLA 2011-02-08 00:27:56 EST
We do handle members with package level access correctly.
Also the private member if the package differs.
Comment 4 Srikanth Sankaran CLA 2011-02-08 04:24:00 EST
It looks like the buggy behavior was introduced deliberately
to match javac behavior. See https://bugs.eclipse.org/bugs/show_bug.cgi?id=74096.
bug 74096 comment 2 is in direct contravention to JLS 4.4.

I'll introduce a fix for 1.7 compliance mode, leaving the behavior unchanged
(thus matching javac) for 1.5 and 1.6.
Comment 5 Srikanth Sankaran CLA 2011-02-08 05:20:15 EST
Created attachment 188502 [details]
Patch under consideration
Comment 6 Srikanth Sankaran CLA 2011-02-08 06:37:36 EST
Created attachment 188509 [details]
Revised patch under test


    - This patch handled private types also in an analogous manner.
    - Adjusts the existing tests to expect new behavior at >= 1.7
    - Under test.
Comment 7 Srikanth Sankaran CLA 2011-02-08 08:03:35 EST
All tests pass. Jay, please review. TIA.
Comment 8 Srikanth Sankaran CLA 2011-02-14 00:08:45 EST
Released in HEAD for 3.7 M6
Comment 9 Jay Arthanareeswaran CLA 2011-03-07 07:14:15 EST
Verified for 3.7M6 using build I20110301-1537.
Comment 10 Ayushman Jain CLA 2011-11-07 00:44:35 EST
*** Bug 362969 has been marked as a duplicate of this bug. ***
Comment 11 Ayushman Jain CLA 2011-11-07 07:21:32 EST
*** Bug 362969 has been marked as a duplicate of this bug. ***