-
Bug
-
Resolution: Unresolved
-
P4
-
7u51, 8
class InstanceFromStatic<T> {
class Inner {}
static void m(Inner i) {} // expected: error; actual: error
static class Child extends Inner { // expected: error; actual: nothing
Child() { new InstanceFromStatic().super(); }
}
}
InstanceFromStatic.java:5: error: non-static class InstanceFromStatic.Inner cannot be referenced from a static context
static void m(Inner i) {}
^
InstanceFromStatic.java:8: warning: [unchecked] unchecked conversion
Child() { new InstanceFromStatic().super(); }
^
required: InstanceFromStatic<T>
found: InstanceFromStatic
where T is a type-variable:
T extends Object declared in class InstanceFromStatic
Because the outer class is generic, references to the non-static instance class Inner are treated as if they were references to InstanceFromStatic<T>.Inner. Since T cannot be referenced from a static context, this should be an error. javac detects the error in most cases, but fails to do so in the 'extends' clause of a static nested class; an unchecked conversion to InstanceFromStatic<T> is then performed in order to provide the enclosing instance (even though T is undefined in this context).
Note that, if InstanceFromStatic is not generic, none of this is a problem, and the program (correctly) compiles without error.
I tried to find the spec for this check, and wasn't able to turn anything up. It's possible there needs to be a corresponding spec clarification.
This is a regression beginning with 7: javac 6u65 reports two errors, as expected.
class Inner {}
static void m(Inner i) {} // expected: error; actual: error
static class Child extends Inner { // expected: error; actual: nothing
Child() { new InstanceFromStatic().super(); }
}
}
InstanceFromStatic.java:5: error: non-static class InstanceFromStatic.Inner cannot be referenced from a static context
static void m(Inner i) {}
^
InstanceFromStatic.java:8: warning: [unchecked] unchecked conversion
Child() { new InstanceFromStatic().super(); }
^
required: InstanceFromStatic<T>
found: InstanceFromStatic
where T is a type-variable:
T extends Object declared in class InstanceFromStatic
Because the outer class is generic, references to the non-static instance class Inner are treated as if they were references to InstanceFromStatic<T>.Inner. Since T cannot be referenced from a static context, this should be an error. javac detects the error in most cases, but fails to do so in the 'extends' clause of a static nested class; an unchecked conversion to InstanceFromStatic<T> is then performed in order to provide the enclosing instance (even though T is undefined in this context).
Note that, if InstanceFromStatic is not generic, none of this is a problem, and the program (correctly) compiles without error.
I tried to find the spec for this check, and wasn't able to turn anything up. It's possible there needs to be a corresponding spec clarification.
This is a regression beginning with 7: javac 6u65 reports two errors, as expected.
- is blocked by
-
JDK-6558763 8.1.2: Disallow generic exception types by specifying generic inner classes
- Open