InitArray with TernaryOp is handled incorrectly

Issue #302 resolved
Tagir Valeev
created an issue

This very simple class is decompiled incorrectly:

public class Test {
    int[] arr;

    public Test(boolean b) {
        arr = b ? new int[] {1,2} : new int[] {1};
    }
}

Decompilation result (compiled by javac, reproducible with 0.5.30 and current develop code):

public class Test
{
    int[] arr;

    public Test(final boolean b) {
        final int[] arr;
        if (b) {
            final int[] array2;
            final int[] array = array2 = new int[2];
            array[array[0] = 1] = 2;
        }
        else {
            arr = new int[] { 1 };
        }
        this.arr = arr;
    }
}

Bytecode:

  public Test(boolean);
    descriptor: (Z)V
    flags: ACC_PUBLIC
    Code:
      stack=5, locals=2, args_size=2
         0: aload_0
         1: invokespecial #1                  // Method java/lang/Object."<init>":()V
         4: aload_0
         5: iload_1
         6: ifeq          23
         9: iconst_2
        10: newarray       int
        12: dup
        13: iconst_0
        14: iconst_1
        15: iastore
        16: dup
        17: iconst_1
        18: iconst_2
        19: iastore
        20: goto          30
        23: iconst_1
        24: newarray       int
        26: dup
        27: iconst_0
        28: iconst_1
        29: iastore
        30: putfield      #2                  // Field arr:[I
        33: return
      LineNumberTable:
        line 4: 0
        line 5: 4
        line 6: 33
      StackMapTable: number_of_entries = 2
        frame_type = 255 /* full_frame */
          offset_delta = 23
          locals = [ class Test, int ]
          stack = [ class Test ]
        frame_type = 255 /* full_frame */
          offset_delta = 6
          locals = [ class Test, int ]
          stack = [ class Test, class "[I" ]

Comments (6)

  1. Log in to comment