Storyyeller / Krakatau

Java decompiler, assembler, and disassembler
GNU General Public License v3.0
1.95k stars 220 forks source link

Incorrect optimization of InstantiationError #77

Closed samczsun closed 8 years ago

samczsun commented 8 years ago
.method public static main : ([Ljava/lang/String;)V 
    .code stack 10 locals 10 
        .catch java/lang/InstantiationError from L0 to L1 using L2
L0:
        new java/util/List
L1:
        dup
        invokespecial Method java/util/List <init> ()V
        getstatic java/lang/System out Ljava/io/PrintStream;
        swap
        invokevirtual Method java/io/PrintStream println (Ljava/lang/Object;)V
        return
L2:
        getstatic java/lang/System out Ljava/io/PrintStream;
        ldc "Hi"
        invokevirtual Method java/io/PrintStream println (Ljava/lang/Object;)V
        return
    .end code 
.end method 

Output:

    public static void main(String[] a)
    {
        java.util.List a0 = new java.util.List();
        System.out.println((Object)a0);
    }

I realize that 'new' is one of the opcodes that can't be adequately represented in Java source code. However, in this case it should be a plausible solution to simply check whether the target of the new statement is able to be instantiated or not.

Storyyeller commented 8 years ago

This is pretty much the same kind of issue as the LinkageError. It's not clear to me that trying to handle it is worth the effort.

samczsun commented 8 years ago

Ah, my bad. I forgot to turn on -xmagicthrow for this case. It displays the code with that so I suppose it's good enough.