Switch statement containing both null and guarded pattern freezes during execution

Ilyas Selimov ilyas.selimov at jetbrains.com
Thu Jul 15 10:07:05 UTC 2021


Hello!

I tried to execute the following code using OpenJDK 17 (build
17-ea+30-2618) and got the freeze:

    public static void main(String[] args) {
        test(null);
    }

    static void test(Integer i) {
        switch (i) {
            case null:
            case Integer ii && ii != null:
                System.out.println("int");
                break;
            default:
                System.out.println("def");
        }
    }

Looking at the test method's bytecode, it seems the issue is related to the
"goto" instruction on the 44's position:

  static void test(java.lang.Integer);
    Code:
       0: aload_0
       1: astore_1
       2: iconst_0
       3: istore_2
       4: aload_1
       5: iload_2
       6: invokedynamic #13,  0             // InvokeDynamic
#0:typeSwitch:(Ljava/lang/Object;I)I
      11: lookupswitch  { // 2
                    -1: 36
                     0: 36
               default: 58
          }
      36: aload_1
      37: astore_3
      38: aload_3
      39: ifnonnull     47
      42: iconst_1
      43: istore_2
      44: goto          4
      47: getstatic     #17                 // Field
java/lang/System.out:Ljava/io/PrintStream;
      50: ldc           #23                 // String int
      52: invokevirtual #25                 // Method
java/io/PrintStream.println:(Ljava/lang/String;)V
      55: goto          66
      58: getstatic     #17                 // Field
java/lang/System.out:Ljava/io/PrintStream;
      61: ldc           #31                 // String def
      63: invokevirtual #25                 // Method
java/io/PrintStream.println:(Ljava/lang/String;)V
      66: return

The third_var = null, as third_var = first_var = null.
So the result of "ifnonnull" instruction seems false and we meet "goto"
instruction, jump before the "lookupswitch" position again.

Seems the issue is related to
https://bugs.openjdk.java.net/browse/JDK-8269141.
Could somebody take a look?

Thanks,
Ilyas
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.java.net/pipermail/compiler-dev/attachments/20210715/e7d5fb5e/attachment.htm>


More information about the compiler-dev mailing list