Storyyeller / Krakatau

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

Incorrect handling of ldc MethodType #109

Open samczsun opened 7 years ago

samczsun commented 7 years ago

Strangely enough, I can ldc a MethodType, and the JVM will let me print it:

.version 52 0 
.class public super Test
super java/lang/Object 

.method public static main : ([Ljava/lang/String;)V 
    .code stack 10 locals 10 
L0:     getstatic Field java/lang/System out Ljava/io/PrintStream; 
L3:     ldc MethodType "(Ljava/lang/Object;)V" 
L5:     invokevirtual Method java/io/PrintStream println (Ljava/lang/Object;)V 
L8:     return 
L9:     
    .end code 
.end method 
.end class 

Output: (Object)void

Decompiled output:

public class proof {
    public static void main(String[] a)
    {
        System.out.println();
    }
}
Storyyeller commented 7 years ago

The decompiler doesn't really attempt to handle method handle/type/invoke dynamic stuff, since I'm not sure if there is a good way to represent it in Java.

samczsun commented 7 years ago

In this case, it seems to just print the simple version of the MethodType. MethodHandles can't be loaded onto the stack. I wonder if this is an oversight in the JVM..?

samczsun commented 7 years ago

It seems that at 3am in the morning I don't function too well. Looking back at that comment I'm not really sure what I was thinking but it obviously isn't correct.

For MethodTypes maybe an artificial MethodType.fromMethodDescriptorString could be inserted? It seems better than not displaying any indication of the value at all