Infinite Loop in Pattern switch with guarded patterns in JDK 17 ea27/ea36
Jan Lahoda
jan.lahoda at oracle.com
Thu Jun 24 07:06:15 UTC 2021
Hi Manoj,
thanks for the report. There is:
https://bugs.openjdk.java.net/browse/JDK-8269141
filled for this.
Thanks,
Jan
On 24. 06. 21 2:56, Manoj Palat wrote:
> Hi,
> I see an infinite loop with with JDK 17 ea27/ea26 for pattern switch;
> given switch pattern with guarded pattern case:
> public class X {
> private static void foo(Object o) {
> switch (o) {
> case String s1 && s1.length()>1: System.out.println("Guarded");
> break;
> default : System.out.println("Object");
> }
> }
> public static void main(String[] args) {
> foo(new Object());
> }
> }
> compiles fine with ea27 (and ea26), but while running gets into an
> infinite loop.
>
> The disassembled code shows that there is a "goto 9" at 73 (to restart
> the switch) - I believe that this goto here is an error as switch need
> not be restarted at default; omitting the generation of this "goto"
> should remove the infinite loop.
> private static void foo(java.lang.Object arg0);
> ...
> 9 aload_1
> 10 iload_2
> 11 invokedynamic 0 typeSwitch(java.lang.Object, int) : int [13]
> 16 lookupswitch default: 65
> case 0: 36
> ....
> 65 getstatic java.lang.System.out : java.io.PrintStream [23]
> 68 ldc <String "Object"> [37]
> 70 invokevirtual java.io.PrintStream.println(java.lang.String) :
> void [31]
> 73 goto 9 <== this is an error
> 76 return
> Thanks,
> Manoj
> PS: Had sent a mail to jdk-dev, but I didn't see it in the list; also
> raised bug with oracle internal id: 9070727
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.java.net/pipermail/compiler-dev/attachments/20210624/1e238445/attachment-0001.htm>
More information about the compiler-dev
mailing list