Incompatible stack heights when checking byte code with CheckClassAdapter

ucorn <[email protected]> Tue, 23 May 2017 14:27:27 +0800
Newsgroups gmane.comp.java.objectweb.asm
Message-ID <[email protected]>
Hi all:
    I need to implement a functionality to trace the file leak, just alike the class FileCloseTest in attachement.
    However, I met the following exceptions when check the byte codes with CheckClassAdapter.
    I seems the issue is caused by the introduction of TryCatchBlockNode by commenting off partial codes.
    Then why, the issue can be reproduced with the attached source code.
    Any help is appreciated.

start the transformation
org.objectweb.asm.tree.analysis.AnalyzerException: Error at instruction 117: Incompatible stack heights
at org.objectweb.asm.tree.analysis.Analyzer.analyze(Unknown Source)
at org.objectweb.asm.util.CheckMethodAdapter$1.visitEnd(Unknown Source)
at org.objectweb.asm.MethodVisitor.visitEnd(Unknown Source)
at org.objectweb.asm.util.CheckMethodAdapter.visitEnd(Unknown Source)
at org.objectweb.asm.tree.MethodNode.accept(Unknown Source)
at org.objectweb.asm.tree.MethodNode.accept(Unknown Source)
at org.objectweb.asm.tree.ClassNode.accept(Unknown Source)
at demo.bi.FileByteModifier.addTraceSource(FileByteModifier.java:77)
at demo.bi.Main.main(Main.java:34)
Caused by: org.objectweb.asm.tree.analysis.AnalyzerException: Incompatible stack heights
at org.objectweb.asm.tree.analysis.Frame.merge(Unknown Source)
at org.objectweb.asm.tree.analysis.Analyzer.merge(Unknown Source)
... 9 more
Exception in thread "main" java.lang.RuntimeException: Error at instruction 117: Incompatible stack heights <init>(Ljava/io/File;)V
00000 R R . . . . . . .  :  :    L0
00001 R R . . . . . . .  :  :     LINENUMBER 123 L0
00002 R R . . . . . . .  :  :     ALOAD 0
00003 R R . . . . . . .  : R  :     INVOKESPECIAL java/io/InputStream.<init> ()V
00004 R R . . . . . . .  :  :    L1
00005 R R . . . . . . .  :  :     LINENUMBER 60 L1
00006 R R . . . . . . .  :  :     ALOAD 0
00007 R R . . . . . . .  : R  :     ACONST_NULL
00008 R R . . . . . . .  : R R  :     PUTFIELD java/io/FileInputStream.channel : Ljava/nio/channels/FileChannel;
00009 R R . . . . . . .  :  :    L2
00010 R R . . . . . . .  :  :     LINENUMBER 62 L2
00011 R R . . . . . . .  :  :     ALOAD 0
00012 R R . . . . . . .  : R  :     NEW java/lang/Object
00013 R R . . . . . . .  : R R  :     DUP
00014 R R . . . . . . .  : R R R  :     INVOKESPECIAL java/lang/Object.<init> ()V
00015 R R . . . . . . .  : R R  :     PUTFIELD java/io/FileInputStream.closeLock : Ljava/lang/Object;
00016 R R . . . . . . .  :  :    L3
00017 R R . . . . . . .  :  :     LINENUMBER 63 L3
00018 R R . . . . . . .  :  :     ALOAD 0
00019 R R . . . . . . .  : R  :     ICONST_0
00020 R R . . . . . . .  : R I  :     PUTFIELD java/io/FileInputStream.closed : Z
00021 R R . . . . . . .  :  :    L4
00022 R R . . . . . . .  :  :     LINENUMBER 124 L4
00023 R R . . . . . . .  :  :     ALOAD 1
00024 R R . . . . . . .  : R  :     IFNULL L5
00025 R R . . . . . . .  :  :     ALOAD 1
00026 ?             :     INVOKEVIRTUAL java/io/File.getPath ()Ljava/lang/String;
00027 ?             :     GOTO L6
00028 R R . . . . . . .  :  :    L5
00029 R R . . . . . . .  :  :    FRAME FULL [java/io/FileInputStream java/io/File] []
00030 R R . . . . . . .  :  :     ACONST_NULL
00031 R R . . . . . . .  : R  :    L6
00032 R R . . . . . . .  : R  :    FRAME SAME1 java/lang/String
00033 R R . . . . . . .  : R  :     ASTORE 2
00034 R R R . . . . . .  :  :    L7
00035 R R R . . . . . .  :  :     LINENUMBER 125 L7
00036 R R R . . . . . .  :  :     INVOKESTATIC java/lang/System.getSecurityManager ()Ljava/lang/SecurityManager;
00037 R R R . . . . . .  : R  :     ASTORE 3
00038 R R R R . . . . .  :  :    L8
00039 R R R R . . . . .  :  :     LINENUMBER 126 L8
00040 R R R R . . . . .  :  :     ALOAD 3
00041 R R R R . . . . .  : R  :     IFNULL L9
00042 R R R R . . . . .  :  :    L10
00043 ?             :     LINENUMBER 127 L10
00044 ?             :     ALOAD 3
00045 ?             :     ALOAD 2
00046 ?             :     INVOKEVIRTUAL java/lang/SecurityManager.checkRead (Ljava/lang/String;)V
00047 R R R R . . . . .  :  :    L9
00048 R R R R . . . . .  :  :     LINENUMBER 129 L9
00049 R R R R . . . . .  :  :    FRAME APPEND [java/lang/String java/lang/SecurityManager]
00050 R R R R . . . . .  :  :     ALOAD 2
00051 R R R R . . . . .  : R  :     IFNONNULL L11
00052 R R R R . . . . .  :  :    L12
00053 ?             :     LINENUMBER 130 L12
00054 ?             :     NEW java/lang/NullPointerException
00055 ?             :     DUP
00056 ?             :     INVOKESPECIAL java/lang/NullPointerException.<init> ()V
00057 ?             :     ATHROW
00058 R R R R . . . . .  :  :    L11
00059 R R R R . . . . .  :  :     LINENUMBER 132 L11
00060 R R R R . . . . .  :  :    FRAME SAME
00061 R R R R . . . . .  :  :     ALOAD 1
00062 R R R R . . . . .  : R  :     INVOKEVIRTUAL java/io/File.isInvalid ()Z
00063 R R R R . . . . .  : I  :     IFEQ L13
00064 R R R R . . . . .  :  :    L14
00065 ?             :     LINENUMBER 133 L14
00066 ?             :     NEW java/io/FileNotFoundException
00067 ?             :     DUP
00068 ?             :     LDC "Invalid file path"
00069 ?             :     INVOKESPECIAL java/io/FileNotFoundException.<init> (Ljava/lang/String;)V
00070 ?             :     ATHROW
00071 R R R R . . . . .  :  :    L13
00072 R R R R . . . . .  :  :     LINENUMBER 135 L13
00073 R R R R . . . . .  :  :    FRAME SAME
00074 R R R R . . . . .  :  :     ALOAD 0
00075 R R R R . . . . .  : R  :     NEW java/io/FileDescriptor
00076 R R R R . . . . .  : R R  :     DUP
00077 R R R R . . . . .  : R R R  :     INVOKESPECIAL java/io/FileDescriptor.<init> ()V
00078 R R R R . . . . .  : R R  :     PUTFIELD java/io/FileInputStream.fd : Ljava/io/FileDescriptor;
00079 R R R R . . . . .  :  :    L15
00080 R R R R . . . . .  :  :     LINENUMBER 136 L15
00081 R R R R . . . . .  :  :     ALOAD 0
00082 R R R R . . . . .  : R  :     GETFIELD java/io/FileInputStream.fd : Ljava/io/FileDescriptor;
00083 R R R R . . . . .  : R  :     ALOAD 0
00084 R R R R . . . . .  : R R  :     INVOKEVIRTUAL java/io/FileDescriptor.attach (Ljava/io/Closeable;)V
00085 R R R R . . . . .  :  :    L16
00086 R R R R . . . . .  :  :     LINENUMBER 137 L16
00087 R R R R . . . . .  :  :     ALOAD 0
00088 R R R R . . . . .  : R  :     ALOAD 2
00089 R R R R . . . . .  : R R  :     PUTFIELD java/io/FileInputStream.path : Ljava/lang/String;
00090 R R R R . . . . .  :  :    L17
00091 R R R R . . . . .  :  :     LINENUMBER 138 L17
00092 R R R R . . . . .  :  :     ALOAD 0
00093 R R R R . . . . .  : R  :     ALOAD 2
00094 R R R R . . . . .  : R R  :     ASTORE 4
00095 R R R R R . . . .  : R  :     ASTORE 5
00096 R R R R R R . . .  :  :    L18
00097 R R R R R R . . .  :  :     ACONST_NULL
00098 R R R R R R . . .  : R  :     ASTORE 6
00099 R R R R R R R . .  :  :     ACONST_NULL
00100 R R R R R R R . .  : R  :     ASTORE 7
00101 R R R R R R R R .  :  :     ALOAD 0
00102 R R R R R R R R .  : R  :     ALOAD 4
00103 R R R R R R R R .  : R R  :     INVOKESTATIC demo/bi/FileTraceHelper.makeFileMeta (Ljava/lang/Object;Ljava/lang/String;)Ldemo/bi/FileMeta;
00104 R R R R R R R R .  : R  :     ASTORE 6
00105 R R R R R R R R .  :  :     ALOAD 6
00106 R R R R R R R R .  : R  :     IFNULL L19
00107 R R R R R R R R .  :  :     ALOAD 0
00108 ?             :     ALOAD 6
00109 ?             :     INVOKESTATIC demo/bi/FileTraceHelper.traceBefore (Ljava/lang/Object;Ldemo/bi/FileMeta;)Ldemo/bi/Entry;
00110 ?             :     ASTORE 7
00111 R R R R R R R R .  :  :    L19
00112 R R R R R R R R .  :  :     ALOAD 5
00113 R R R R R R R R .  : R  :     ALOAD 4
00114 R R R R R R R R .  : R R  :     INVOKESPECIAL java/io/FileInputStream.open (Ljava/lang/String;)V
00115 R R R R R R R R .  :  :     ALOAD 7
00116 R R R R R R R R .  : R  :     ICONST_1
00117 R R R R R R R R .  : R I  :     INVOKESTATIC demo/bi/FileTraceHelper.traceAfter (Ldemo/bi/Entry;Z)V
00118 R R R R R R R R .  : R  :    L20
00119 R R R R R R R R .  : R  :     ASTORE 8
00120 R R R R R R R R R  :  :     ALOAD 7
00121 R R R R R R R R R  : R  :     ICONST_0
00122 R R R R R R R R R  : R I  :     INVOKESTATIC demo/bi/FileTraceHelper.traceAfter (Ldemo/bi/Entry;Z)V
00123 R R R R R R R R R  :  :     ALOAD 8
00124 R R R R R R R R R  : R  :     ATHROW
00125 ?             :    L21
00126 ?             :    L22
00127 ?             :    L23
00128 ?             :     LINENUMBER 139 L23
00129 ?             :     RETURN
     TRYCATCHBLOCK L19 L20 L20 java/lang/Throwable


at org.objectweb.asm.util.CheckMethodAdapter$1.visitEnd(Unknown Source)
at org.objectweb.asm.MethodVisitor.visitEnd(Unknown Source)
at org.objectweb.asm.util.CheckMethodAdapter.visitEnd(Unknown Source)
at org.objectweb.asm.tree.MethodNode.accept(Unknown Source)
at org.objectweb.asm.tree.MethodNode.accept(Unknown Source)
at org.objectweb.asm.tree.ClassNode.accept(Unknown Source)
at demo.bi.FileByteModifier.addTraceSource(FileByteModifier.java:77)
at demo.bi.Main.main(Main.java:34)



ucorn


-- 
You receive this message as a subscriber of the [email protected] mailing list.
To unsubscribe: mailto:[email protected]
For general help: mailto:[email protected]?subject=help
OW2 mailing lists service home page: http://www.ow2.org/wws
BciTest.zip (application/octet-stream, 228.1 KB) - not displayed