Skip to content
Advertisement

grep method appears in class file but not in its human dump

I’m grepping for a method getNumBytes in some class file A.class:

$ grep -rn "getNumBytes"
Binary file A.class matches

When I dump its content with javap I can’t see my method:

$ javap -c -p A.class > A.human
$ grep "getNumBytes" A.human # <--- nothing ... where did it go?!

Here is a complete minimal example:

$ 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"

Advertisement

Answer

UPDATE I’m on Windows, and it runs fine. I believe Thomas Kläger is correct that this is a shell issue:

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"


Unable to reproduce.

javap -c -p -l -s -constants -v Options$Companion.class | grep buildTrieRecursive

Output

  #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"]
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement