List<Constant> constants = new ArrayList<>(); byte[] bytecode = ... // reads the class byte code int constantPoolCount = getConstantPoolCount(bytecode); int offset = getConstantPoolStartOffset(bytecode); for(int i = 1; i < constantPoolCount; i++){ int tag = bytecode[offset]; offset++; if(tag == LONG_CONSTANT_TAG) { byte[] highBytes = Arrays.copyOfRange(bytecode, offset, offset+4); offset += 4; byte[] lowBytes = Arrays.copyOfRange(bytecode, offset, offset+4); offset += 4; ConstantLong c = new ConstantLong(highBytes, lowBytes); constants.add(c); // because we are at CONSTANT LONG, the entry at n+1 is not used constants.add(null); i++; } else if(tag == DOUBLE_CONSTANT_TAG) { ... // performs the same, like LONG_CONSTANT_TAG } // read more entries without skip indexes. }
return new ConstantFloat(dataInput); case Const.CONSTANT_Long: return new ConstantLong(dataInput); case Const.CONSTANT_Double: return new ConstantDouble(dataInput);
return new ConstantFloat(file); case Constants.CONSTANT_Long: return new ConstantLong(file); case Constants.CONSTANT_Double: return new ConstantDouble(file);
return new ConstantFloat(file); case Constants.CONSTANT_Long: return new ConstantLong(file); case Constants.CONSTANT_Double: return new ConstantDouble(file);
return new ConstantFloat(file); case Constants.CONSTANT_Long: return new ConstantLong(file); case Constants.CONSTANT_Double: return new ConstantDouble(file);
return new ConstantFloat(file); case Constants.CONSTANT_Long: return new ConstantLong(file); case Constants.CONSTANT_Double: return new ConstantDouble(file);