-
Bug
-
Resolution: Fixed
-
P4
-
21, 22
-
b22
https://mail.openjdk.org/pipermail/amber-dev/2023-September/008300.html
The following raises a java.lang.VerifyError for the fourth case, unless the first component of the third case is named.
public class TestUnnamed {
record Tuple<T1, T2>(T1 first, T2 second) {}
record R1<T>(Integer value) implements R<T> {}
record R2<T>(Integer value) implements R<T> {}
sealed interface R<T> {}
static <T1 extends Comparable, T2 extends Comparable> int compareTo(Tuple<R<T1>, R<T2>> o) {
return switch (o) {
case Tuple<R<T1>, R<T2>>(R1<T1> _, R1<T2> _) -> -1;
case Tuple<R<T1>, R<T2>>(R1<T1> _, R2<T2> _) -> -1;
case Tuple<R<T1>, R<T2>>(R2<T1> _, R1<T2> _) -> -1;
case Tuple<R<T1>, R<T2>>(R2<T1> fst, R2<T2> snd) -> fst.value().compareTo(snd.value());
};
}
public static void main(String[] args) {
compareTo(new Tuple<R<Integer>, R<Integer>>(new R2<Integer>(1), new R2<Integer>(2)));
}
}
Output:
> java --enable-preview --source 22 TestUnnamed.java java 22-internal
Note: TestUnnamed.java uses preview features of Java SE 22.
Note: Recompile with -Xlint:preview for details.
Exception in thread "main" java.lang.VerifyError: Bad local variable type
Exception Details:
Location:
TestUnnamed.compareTo(LTestUnnamed$Tuple;)I @215: aload
Reason:
Type top (current frame, locals[7]) is not assignable to reference type
Current Frame:
bci: @215
flags: { }
locals: { 'TestUnnamed$Tuple', 'TestUnnamed$Tuple', integer, 'TestUnnamed$Tuple', top, top, top, top, top, 'TestUnnamed$R2', 'TestUnnamed$R', integer, 'TestUnnamed$R', integer }
stack: { }
Bytecode:
0000000: 2a59 b800 0757 4c03 3d2b 1cba 000d 0000
0000010: ab00 0000 0000 0014 0000 0001 0000 0000
0000020: 0000 001e bb00 1159 0101 b700 13bf 2b4e
0000030: 2db6 0016 c000 1c3a 0a03 360b 190a 150b
0000040: ba00 1e00 00aa 0000 0000 00a8 ffff ffff
0000050: 0000 0001 0000 00a8 0000 001b 0000 0059
0000060: 2db6 001f c000 1c3a 0c03 360d 190c 150d
0000070: ba00 1e00 00aa 0000 0000 0023 ffff ffff
0000080: 0000 0001 0000 0023 0000 001b 0000 001f
0000090: 02a7 0061 02a7 005d 0436 0ba7 ffa1 2db6
00000a0: 001f c000 1c3a 0c03 360d 190c 150d ba00
00000b0: 1e00 00aa 0000 0034 ffff ffff 0000 0001
00000c0: 0000 0034 0000 0019 0000 001d 02a7 0025
00000d0: 190c c000 223a 0919 07b6 0024 1909 b600
00000e0: 24b6 0028 a700 0e05 360b a7ff 5204 3da7
00000f0: ff1a ac4c bb00 1159 2bb6 0030 2bb7 0013
0000100: bf
Exception Handler Table:
bci [49, 52] => handler: 243
bci [97, 100] => handler: 243
bci [159, 162] => handler: 243
Stackmap Table:
append_frame(@9,Object[#23],Integer)
same_frame(@36)
same_frame(@46)
full_frame(@60,{Object[#23],Object[#23],Integer,Object[#23],Top,Top,Top,Top,Top,Top,Object[#28],Integer},{})
same_frame(@96)
append_frame(@108,Object[#28],Integer)
same_frame(@144)
same_frame(@148)
same_frame(@152)
chop_frame(@158,2)
append_frame(@170,Object[#28],Integer)
same_frame(@204)
same_frame(@208)
same_frame(@231)
chop_frame(@237,2)
full_frame(@242,{Object[#23]},{Integer})
same_locals_1_stack_item_frame(@243,Object[#46])
at java.base/java.lang.Class.forName0(Native Method)
at java.base/java.lang.Class.forName(Class.java:537)
at java.base/java.lang.Class.forName(Class.java:516)
at jdk.compiler/com.sun.tools.javac.launcher.Main.execute(Main.java:432)
at jdk.compiler/com.sun.tools.javac.launcher.Main.run(Main.java:208)
at jdk.compiler/com.sun.tools.javac.launcher.Main.main(Main.java:135)
The following raises a java.lang.VerifyError for the fourth case, unless the first component of the third case is named.
public class TestUnnamed {
record Tuple<T1, T2>(T1 first, T2 second) {}
record R1<T>(Integer value) implements R<T> {}
record R2<T>(Integer value) implements R<T> {}
sealed interface R<T> {}
static <T1 extends Comparable, T2 extends Comparable> int compareTo(Tuple<R<T1>, R<T2>> o) {
return switch (o) {
case Tuple<R<T1>, R<T2>>(R1<T1> _, R1<T2> _) -> -1;
case Tuple<R<T1>, R<T2>>(R1<T1> _, R2<T2> _) -> -1;
case Tuple<R<T1>, R<T2>>(R2<T1> _, R1<T2> _) -> -1;
case Tuple<R<T1>, R<T2>>(R2<T1> fst, R2<T2> snd) -> fst.value().compareTo(snd.value());
};
}
public static void main(String[] args) {
compareTo(new Tuple<R<Integer>, R<Integer>>(new R2<Integer>(1), new R2<Integer>(2)));
}
}
Output:
> java --enable-preview --source 22 TestUnnamed.java java 22-internal
Note: TestUnnamed.java uses preview features of Java SE 22.
Note: Recompile with -Xlint:preview for details.
Exception in thread "main" java.lang.VerifyError: Bad local variable type
Exception Details:
Location:
TestUnnamed.compareTo(LTestUnnamed$Tuple;)I @215: aload
Reason:
Type top (current frame, locals[7]) is not assignable to reference type
Current Frame:
bci: @215
flags: { }
locals: { 'TestUnnamed$Tuple', 'TestUnnamed$Tuple', integer, 'TestUnnamed$Tuple', top, top, top, top, top, 'TestUnnamed$R2', 'TestUnnamed$R', integer, 'TestUnnamed$R', integer }
stack: { }
Bytecode:
0000000: 2a59 b800 0757 4c03 3d2b 1cba 000d 0000
0000010: ab00 0000 0000 0014 0000 0001 0000 0000
0000020: 0000 001e bb00 1159 0101 b700 13bf 2b4e
0000030: 2db6 0016 c000 1c3a 0a03 360b 190a 150b
0000040: ba00 1e00 00aa 0000 0000 00a8 ffff ffff
0000050: 0000 0001 0000 00a8 0000 001b 0000 0059
0000060: 2db6 001f c000 1c3a 0c03 360d 190c 150d
0000070: ba00 1e00 00aa 0000 0000 0023 ffff ffff
0000080: 0000 0001 0000 0023 0000 001b 0000 001f
0000090: 02a7 0061 02a7 005d 0436 0ba7 ffa1 2db6
00000a0: 001f c000 1c3a 0c03 360d 190c 150d ba00
00000b0: 1e00 00aa 0000 0034 ffff ffff 0000 0001
00000c0: 0000 0034 0000 0019 0000 001d 02a7 0025
00000d0: 190c c000 223a 0919 07b6 0024 1909 b600
00000e0: 24b6 0028 a700 0e05 360b a7ff 5204 3da7
00000f0: ff1a ac4c bb00 1159 2bb6 0030 2bb7 0013
0000100: bf
Exception Handler Table:
bci [49, 52] => handler: 243
bci [97, 100] => handler: 243
bci [159, 162] => handler: 243
Stackmap Table:
append_frame(@9,Object[#23],Integer)
same_frame(@36)
same_frame(@46)
full_frame(@60,{Object[#23],Object[#23],Integer,Object[#23],Top,Top,Top,Top,Top,Top,Object[#28],Integer},{})
same_frame(@96)
append_frame(@108,Object[#28],Integer)
same_frame(@144)
same_frame(@148)
same_frame(@152)
chop_frame(@158,2)
append_frame(@170,Object[#28],Integer)
same_frame(@204)
same_frame(@208)
same_frame(@231)
chop_frame(@237,2)
full_frame(@242,{Object[#23]},{Integer})
same_locals_1_stack_item_frame(@243,Object[#46])
at java.base/java.lang.Class.forName0(Native Method)
at java.base/java.lang.Class.forName(Class.java:537)
at java.base/java.lang.Class.forName(Class.java:516)
at jdk.compiler/com.sun.tools.javac.launcher.Main.execute(Main.java:432)
at jdk.compiler/com.sun.tools.javac.launcher.Main.run(Main.java:208)
at jdk.compiler/com.sun.tools.javac.launcher.Main.main(Main.java:135)