RFR: JDK-8247790: javac shouldn't allow type variable references from local static declarations
Jan Lahoda
jan.lahoda at oracle.com
Tue Jun 23 09:12:06 UTC 2020
Hi Vicente,
I think this is a good direction, but probably not sufficient. My
question would be if it is possible to piggy back more on the existing
"staticOnly" flag, instead of checking the innermost environment.
Specifically, consider this example:
---
package javaapplication29;
public class JavaApplication29 {
public static <T> void main(String[] args) {
String hello = "hello";
interface I {
public default void test1() {
class X {
public void test2() {
System.err.println(hello);
T t = null;
}
}
new X().test2();
}
}
record R(int i) {
public void test1() {
class X {
public void test2() {
System.err.println(hello);
T t = null;
}
}
new X().test2();
}
}
enum E {
A;
public void test1() {
class X {
public void test2() {
System.err.println(hello);
T t = null;
}
}
new X().test2();
}
}
new I() {}.test1();
new R(0).test1();
E.A.test1();
}
}
---
The behavior here does not seem to be quite right - there are no errors
reported, but javac crashes on "E", produces wrong classfile for "I" and
suspicious (but working) classfile for "R".
Jan
On 23. 06. 20 0:29, Vicente Romero wrote:
> Hi,
>
> Please review the fix for [1] at [2]. The issue here is that local
> interfaces, enums and records shouldn't be allow to refer to type
> variables defined in an enclosing context. The compiler was checking for
> this if the type variables were defined by the enclosing class but
> references to type variables defined by the enclosing method were
> allowed. This patch is covering this gap,
>
> Thanks,
> Vicente
>
> [1] http://cr.openjdk.java.net/~vromero/8247790/webrev.00/
> [2] https://bugs.openjdk.java.net/browse/JDK-8247790
More information about the compiler-dev
mailing list