Question

when I run javap -c Address.class > Address.txt on a particular class,

I get a bunch of output, with #<NUMBER> as the index to the constant pool

Compiled from "Address.java"
public class test.Address extends test.Entity {
  public test.Address();
    Code:
       0: aload_0       
       1: invokespecial #1                  // Method test/DefaultEntity."<init>":()V
       4: aload_0       
       5: aconst_null   
       6: putfield      #2                  // Field io:Ljava/lang/String;
       9: aload_0       
      10: aconst_null   
      11: putfield      #3                  // Field zip4:Ljava/lang/String;
      14: aload_0       
      15: aconst_null   
      16: putfield      #4                  // Field zip:Ljava/lang/String;
      19: aload_0 

How would I be able to get the pool in the form of a hashmap? i.e:

{1  "Method test/DefaultEntity."<init>":()"
 2   "Field io:Ljava/lang/String;"}
Was it helpful?

Solution

With ASM, you can use a ClassReader to read a .class file and then use getItemCount() and the various read methods to read all of the constant pool items.

(def cr (clojure.asm.ClassReader "test.Address"))
(.getItemCount cr) 
;; etc
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top