grep 方法出现在 class 文件中,但不在其人工转储中
grep method appears in class file but not in its human dump
我在一些 class 文件中查找方法 getNumBytes
A.class
:
$ grep -rn "getNumBytes"
Binary file A.class matches
当我用 javap
转储它的内容时,我看不到我的方法:
$ javap -c -p A.class > A.human
$ grep "getNumBytes" A.human # <--- nothing ... where did it go?!
这是一个完整的最小示例:
$ wget https://repo1.maven.org/maven2/com/squareup/okio/okio/2.9.0/okio-2.9.0.jar
$ mkdir FRESH_DIR
$ cd FRESH_DIR
$ unzip ../okio-2.9.0.jar
$ grep -rn "buildTrieRecursive"
Binary file okio/Options$Companion.class matches
$ javap -c -p -v -constants -l -s okio/Options$Companion.class | grep "buildTrieRecursive"
更新 我在 Windows,它运行良好。我相信 是正确的,这是一个 shell 问题:
Its probably because of the $Companion
in the class name. The linux shell replaces this with the contents of the Companion
environment variable - which most probably not exists and gets replaced by nothing. Try executing javap -c -p -v -constants -l -s 'okio/Options$Companion.class' | grep "buildTrieRecursive"
无法重现。
javap -c -p -l -s -constants -v Options$Companion.class | grep buildTrieRecursive
输出
#138 = Utf8 buildTrieRecursive$default
#140 = NameAndType #138:#139 // buildTrieRecursive$default:(Lokio/Options$Companion;JLokio/Buffer;ILjava/util/List;IILjava/util/List;ILjava/lang/Object;)V
#141 = Methodref #2.#140 // okio/Options$Companion.buildTrieRecursive$default:(Lokio/Options$Companion;JLokio/Buffer;ILjava/util/List;IILjava/util/List;ILjava/lang/Object;)V
#201 = Utf8 buildTrieRecursive
#214 = NameAndType #201:#202 // buildTrieRecursive:(JLokio/Buffer;ILjava/util/List;IILjava/util/List;)V
#215 = Methodref #2.#214 // okio/Options$Companion.buildTrieRecursive:(JLokio/Buffer;ILjava/util/List;IILjava/util/List;)V
574: invokestatic #141 // Method buildTrieRecursive$default:(Lokio/Options$Companion;JLokio/Buffer;ILjava/util/List;IILjava/util/List;ILjava/lang/Object;)V
private final void buildTrieRecursive(long, okio.Buffer, int, java.util.List<? extends okio.ByteString>, int, int, java.util.List<java.lang.Integer>);
625: invokespecial #215 // Method buildTrieRecursive:(JLokio/Buffer;ILjava/util/List;IILjava/util/List;)V
959: invokespecial #215 // Method buildTrieRecursive:(JLokio/Buffer;ILjava/util/List;IILjava/util/List;)V
static void buildTrieRecursive$default(okio.Options$Companion, long, okio.Buffer, int, java.util.List, int, int, java.util.List, int, java.lang.Object);
60: invokespecial #215 // Method buildTrieRecursive:(JLokio/Buffer;ILjava/util/List;IILjava/util/List;)V
d2=["Lokio/Options$Companion;","","()V","intCount","","Lokio/Buffer;","getIntCount","(Lokio/Buffer;)J","buildTrieRecursive","","nodeOffset","node","byteStringOffset","","byteStrings","","Lokio/ByteString;","fromIndex","toIndex","indexes","of","Lokio/Options;","","([Lokio/ByteString;)Lokio/Options;","okio"]
我在一些 class 文件中查找方法 getNumBytes
A.class
:
$ grep -rn "getNumBytes"
Binary file A.class matches
当我用 javap
转储它的内容时,我看不到我的方法:
$ javap -c -p A.class > A.human
$ grep "getNumBytes" A.human # <--- nothing ... where did it go?!
这是一个完整的最小示例:
$ wget https://repo1.maven.org/maven2/com/squareup/okio/okio/2.9.0/okio-2.9.0.jar
$ mkdir FRESH_DIR
$ cd FRESH_DIR
$ unzip ../okio-2.9.0.jar
$ grep -rn "buildTrieRecursive"
Binary file okio/Options$Companion.class matches
$ javap -c -p -v -constants -l -s okio/Options$Companion.class | grep "buildTrieRecursive"
更新 我在 Windows,它运行良好。我相信
Its probably because of the
$Companion
in the class name. The linux shell replaces this with the contents of theCompanion
environment variable - which most probably not exists and gets replaced by nothing. Try executingjavap -c -p -v -constants -l -s 'okio/Options$Companion.class' | grep "buildTrieRecursive"
无法重现。
javap -c -p -l -s -constants -v Options$Companion.class | grep buildTrieRecursive
输出
#138 = Utf8 buildTrieRecursive$default
#140 = NameAndType #138:#139 // buildTrieRecursive$default:(Lokio/Options$Companion;JLokio/Buffer;ILjava/util/List;IILjava/util/List;ILjava/lang/Object;)V
#141 = Methodref #2.#140 // okio/Options$Companion.buildTrieRecursive$default:(Lokio/Options$Companion;JLokio/Buffer;ILjava/util/List;IILjava/util/List;ILjava/lang/Object;)V
#201 = Utf8 buildTrieRecursive
#214 = NameAndType #201:#202 // buildTrieRecursive:(JLokio/Buffer;ILjava/util/List;IILjava/util/List;)V
#215 = Methodref #2.#214 // okio/Options$Companion.buildTrieRecursive:(JLokio/Buffer;ILjava/util/List;IILjava/util/List;)V
574: invokestatic #141 // Method buildTrieRecursive$default:(Lokio/Options$Companion;JLokio/Buffer;ILjava/util/List;IILjava/util/List;ILjava/lang/Object;)V
private final void buildTrieRecursive(long, okio.Buffer, int, java.util.List<? extends okio.ByteString>, int, int, java.util.List<java.lang.Integer>);
625: invokespecial #215 // Method buildTrieRecursive:(JLokio/Buffer;ILjava/util/List;IILjava/util/List;)V
959: invokespecial #215 // Method buildTrieRecursive:(JLokio/Buffer;ILjava/util/List;IILjava/util/List;)V
static void buildTrieRecursive$default(okio.Options$Companion, long, okio.Buffer, int, java.util.List, int, int, java.util.List, int, java.lang.Object);
60: invokespecial #215 // Method buildTrieRecursive:(JLokio/Buffer;ILjava/util/List;IILjava/util/List;)V
d2=["Lokio/Options$Companion;","","()V","intCount","","Lokio/Buffer;","getIntCount","(Lokio/Buffer;)J","buildTrieRecursive","","nodeOffset","node","byteStringOffset","","byteStrings","","Lokio/ByteString;","fromIndex","toIndex","indexes","of","Lokio/Options;","","([Lokio/ByteString;)Lokio/Options;","okio"]