Col-E / Recaf

The modern Java bytecode editor
https://recaf.coley.software
MIT License
5.96k stars 462 forks source link

4x assembler failing on javac bytecode #849

Closed LeFisheAuCoordLogger closed 3 weeks ago

LeFisheAuCoordLogger commented 1 month ago

Description

I opened the assembler on a method that contains what seems to be a finally block, a lot of uninitialized var errors pop up.

To Reproduce

Steps to reproduce the behavior:

  1. This was the jar
  2. At com/strobel/core/ExceptionUtilities in method getStackTraceString(Ljava/lang/Throwable;)Ljava/lang/String;
  3. Open the assembler and the errors are there

Exception

If applicable, add the exception/stacktrace.

stacktrace goes here

Screenshots image image

full code:

.method public static getStackTraceString (Ljava/lang/Throwable;)Ljava/lang/String; {
    parameters: { t },
    exceptions: { { K, L, M, Ljava/lang/Throwable; }, { P, Q, R, Ljava/lang/Throwable; }, { F, J, U, Ljava/lang/Throwable; }, { F, J, V, * }, { X, Y, Z, Ljava/lang/Throwable; }, { U, W, V, * }, { D, O, AC, Ljava/lang/Throwable; }, { U, AC, AC, Ljava/lang/Throwable; }, { D, O, AD, * }, { AF, AG, AH, Ljava/lang/Throwable; }, { U, AE, AD, * }, { B, T, AK, Ljava/lang/Throwable; }, { U, AK, AK, Ljava/lang/Throwable; } },
    code: {
    A: 
        line 66
        aload t
        ldc "t"
        invokestatic com/strobel/core/VerifyArgument.notNull (Ljava/lang/Object;Ljava/lang/String;)Ljava/lang/Object;
        pop 
    B: 
        line 68
        new java/io/ByteArrayOutputStream
        dup 
        sipush 1024
        invokespecial java/io/ByteArrayOutputStream.<init> (I)V
        astore stream
    C: 
        aconst_null 
        astore v2
    D: 
        line 69
        new java/io/PrintWriter
        dup 
        aload stream
        invokespecial java/io/PrintWriter.<init> (Ljava/io/OutputStream;)V
        astore writer
    E: 
        line 68
        aconst_null 
        astore v4
    F: 
        line 71
        aload t
        aload writer
        invokevirtual java/lang/Throwable.printStackTrace (Ljava/io/PrintWriter;)V
    G: 
        line 73
        aload writer
        invokevirtual java/io/PrintWriter.flush ()V
    H: 
        line 74
        aload stream
        invokevirtual java/io/ByteArrayOutputStream.flush ()V
    I: 
        line 76
        aload stream
        invokevirtual java/io/ByteArrayOutputStream.toString ()Ljava/lang/String;
        invokestatic com/strobel/core/StringUtilities.trimRight (Ljava/lang/String;)Ljava/lang/String;
        astore v5
    J: 
        line 77
        aload writer
        ifnull O
        aload v4
        ifnull N
    K: 
        aload writer
        invokevirtual java/io/PrintWriter.close ()V
    L: 
        goto O
    M: 
        astore v6
        aload v4
        aload v6
        invokevirtual java/lang/Throwable.addSuppressed (Ljava/lang/Throwable;)V
        goto O
    N: 
        aload writer
        invokevirtual java/io/PrintWriter.close ()V
    O: 
        aload stream
        ifnull T
        aload v2
        ifnull S
    P: 
        aload stream
        invokevirtual java/io/ByteArrayOutputStream.close ()V
    Q: 
        goto T
    R: 
        astore v6
        aload v2
        aload v6
        invokevirtual java/lang/Throwable.addSuppressed (Ljava/lang/Throwable;)V
        goto T
    S: 
        aload stream
        invokevirtual java/io/ByteArrayOutputStream.close ()V
    T: 
        line 76
        aload v5
        areturn 
    U: 
        line 68
        astore v5
        aload v5
        astore v4
        aload v5
        athrow 
    V: 
        line 77
        astore v7
    W: 
        aload writer
        ifnull AB
        aload v4
        ifnull AA
    X: 
        aload writer
        invokevirtual java/io/PrintWriter.close ()V
    Y: 
        goto AB
    Z: 
        astore v8
        aload v4
        aload v8
        invokevirtual java/lang/Throwable.addSuppressed (Ljava/lang/Throwable;)V
        goto AB
    AA: 
        aload writer
        invokevirtual java/io/PrintWriter.close ()V
    AB: 
        aload v7
        athrow 
    AC: 
        line 68
        astore v3
        aload v3
        astore v2
        aload v3
        athrow 
    AD: 
        line 77
        astore v9
    AE: 
        aload stream
        ifnull AJ
        aload v2
        ifnull AI
    AF: 
        aload stream
        invokevirtual java/io/ByteArrayOutputStream.close ()V
    AG: 
        goto AJ
    AH: 
        astore v10
        aload v2
        aload v10
        invokevirtual java/lang/Throwable.addSuppressed (Ljava/lang/Throwable;)V
        goto AJ
    AI: 
        aload stream
        invokevirtual java/io/ByteArrayOutputStream.close ()V
    AJ: 
        aload v9
        athrow 
    AK: 
        line 78
        astore ignored
    AL: 
        line 79
        aload t
        invokevirtual java/lang/Throwable.toString ()Ljava/lang/String;
        areturn 
    AM: 
    }
}
Col-E commented 1 month ago

Looks like scoping problems with the catch block handling and how we propagate (or don't in this case) variables into them.

LeFisheAuCoordLogger commented 1 month ago

Yeah, make it be a warning instead of an error, asm has no trouble computing the frames

Col-E commented 3 weeks ago

Addressed with 81e49e6363dac1e24a0f34ae74d16873650263da