This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 168894 - wrong error with generics, private fields and nested classes
Summary: wrong error with generics, private fields and nested classes
Status: RESOLVED WONTFIX
Alias: None
Product: java
Classification: Unclassified
Component: Editor (show other bugs)
Version: 6.x
Hardware: PC Windows XP
: P3 blocker with 1 vote (vote)
Assignee: Max Sauer
URL:
Keywords:
: 170742 (view as bug list)
Depends on:
Blocks:
 
Reported: 2009-07-21 15:15 UTC by muescha
Modified: 2009-11-30 10:24 UTC (History)
0 users

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description muescha 2009-07-21 15:17:43 UTC
given this code snippet (makes no sense and are condensed to the only needed lines to show the error):

--8<----8<----8<----8<----8<----8<----8<----8<----8<----8<--
package com.company.tools

public class Test<E extends Test.Element> {
    public static class Element {
        private String name;
    }

    public E setName(E element, String newName) {
        element.name = newName; // <-- error
        return element;
    }
}
--8<----8<----8<----8<----8<----8<----8<----8<----8<----8<--

show this error:
name has private access in com.company.tools.Test.Element



NOTE: in NB 6.5 there was no error
Comment 1 muescha 2009-07-21 15:18:37 UTC
NOTE2: this code in 6.7 not show an error:

--8<----8<----8<----8<----8<----8<----8<----8<----8<----8<--
package com.company.tools

public class Test {
    public static class Element {
        private String name;
    }

    public Element setName(Element element, String newName) {
        element.name = newName; // <-- no error
        return element;
    }
}
--8<----8<----8<----8<----8<----8<----8<----8<----8<----8<--
Comment 2 Max Sauer 2009-07-21 16:15:32 UTC
According to spec, the example in NOTE2 shouldn't show an error (http://java.sun.com/docs/books/jls/third_edition/html/names.html#6.6.1 ,  .. if the 
member or constructor is declared private, then access is permitted if and only if it occurs within the body of the top level class (ยง7.6) that encloses the 
declaration of the member or constructor -- technically, also a body of enclosing class).

However, this not the case as in the first example.

Technically, we use an internal javac 1.7 for error detection in NetBeans java editor. In the first example, the E.name (not Element.name, but something 
which extends it) field should not be allowed to be accessed, since in the scope of the method, 'element' is not an Element itself, but only something 
which extends it. This issue has been already addressed in JDK's 1.7 javac, but has not yet been backported (and, maybe it won't even be in the future, 
since this is a minor bug).

I know we're inconsistent a little bit, but let's wait until this will be backported to 1.5 and 1.6 JDKs or 1.7 becomes final. Thank you for understanding.
Comment 3 Max Sauer 2009-08-21 09:51:08 UTC
*** Issue 170742 has been marked as a duplicate of this issue. ***
Comment 4 nopnb 2009-11-30 10:24:36 UTC
Please take a look a Bug 170742, even if it's a duplicate, because the code is much much simpler and doesn't involve an inner class.
BTW, it's still there in the 6.8 RC1.

Here's the 170742 code:

public class SomeClass {

    private String attribute;

    public <T extends SomeClass> void doSomething(T target) {
        target.attribute = "theValue";
    }
}

Hope it still works in JDK 7 :)
I don't think it's minor.