ASM のクラス Verifier を使用して検証しようとしているバイトコードのスニペットを次に示します。
public <init>(Ljava/io/InputStream;)V
ALOAD 0
ALOAD 1
SIPUSH 2048
NEW org/apache/xerces/impl/msg/XMLMessageFormatter
DUP
INVOKESPECIAL org/apache/xerces/impl/msg/XMLMessageFormatter.<init> ()V
INVOKESTATIC java/util/Locale.getDefault ()Ljava/util/Locale;
INVOKESPECIAL org/apache/xerces/impl/io/UTF8Reader.<init> (Ljava/io/InputStream;ILorg/apache/xerces/util/MessageFormatter;Ljava/util/Locale;)V
RETURN
MAXSTACK = 5
MAXLOCALS = 2
これは、より大きなクラス org/apache/xerces/impl/io/UTF8Reader の一部です。ここで、ASM が提供する Class verifier を介してこのクラスのバイトコードを実行すると、次の結果が得られます。
org.objectweb.asm.tree.analysis.AnalyzerException: **Error at instruction 7: java.lang.ClassNotFoundException: org.apache.xerces.util.MessageFormatter**
at org.objectweb.asm.tree.analysis.Analyzer.analyze(Unknown Source)
at org.objectweb.asm.util.CheckClassAdapter.verify(Unknown Source)
at org.objectweb.asm.util.CheckClassAdapter.verify(Unknown Source)
at org.objectweb.asm.util.CheckClassAdapter.main(Unknown Source)
Caused by: java.lang.RuntimeException: java.lang.ClassNotFoundException: org.apache.xerces.util.MessageFormatter
at org.objectweb.asm.tree.analysis.SimpleVerifier.getClass(Unknown Source)
at org.objectweb.asm.tree.analysis.SimpleVerifier.isAssignableFrom(Unknown Source)
at org.objectweb.asm.tree.analysis.SimpleVerifier.isSubTypeOf(Unknown Source)
at org.objectweb.asm.tree.analysis.BasicVerifier.naryOperation(Unknown Source)
at org.objectweb.asm.tree.analysis.BasicVerifier.naryOperation(Unknown Source)
at org.objectweb.asm.tree.analysis.Frame.execute(Unknown Source)
... 4 more
<init>(Ljava/io/InputStream;)V
00000 UTF8Reader InputStream : : ALOAD 0
00001 UTF8Reader InputStream : UTF8Reader : ALOAD 1
00002 UTF8Reader InputStream : UTF8Reader InputStream : SIPUSH 2048
00003 UTF8Reader InputStream : UTF8Reader InputStream I : NEW org/apache/xerces/impl/msg/XMLMessageFormatter
00004 UTF8Reader InputStream : UTF8Reader InputStream I XMLMessageFormatter : DUP
00005 UTF8Reader InputStream : UTF8Reader InputStream I XMLMessageFormatter XMLMessageFormatter : INVOKESPECIAL org/apache/xerces/impl/msg/XMLMessageFormatter.<init> ()V
00006 UTF8Reader InputStream : UTF8Reader InputStream I XMLMessageFormatter : INVOKESTATIC java/util/Locale.getDefault ()Ljava/util/Locale;
00007 UTF8Reader InputStream : UTF8Reader InputStream I XMLMessageFormatter Locale : INVOKESPECIAL org/apache/xerces/impl/io/UTF8Reader.<init> (Ljava/io/InputStream;ILorg/apache/xerces/util/MessageFormatter;Ljava/util/Locale;)V
00008 ? : RETURN
私はこの最後のビットに非常に混乱しています... なぜ org/apache/xerces/util/MessageFormatter オブジェクトの 7 行目で ClassNotFound 例外を出すのですか?
ありがとう。