private int getConstantPoolStringOffset ( final int cpIdx , final int subFieldIdx ) throws ClassfileFormatException { if ( cpIdx < 1 || cpIdx >= cpCount ) { throw new ClassfileFormatException ( "Constant pool index " + cpIdx + ", should be in range [1, " + ( cpCount - 1 ) + "] -- cannot continue reading class. " + "Please report this at https://github.com/classgraph/classgraph/issues" ) ; } final int t = entryTag [ cpIdx ] ; if ( ( t != 12 && subFieldIdx != 0 ) || ( t == 12 && subFieldIdx != 0 && subFieldIdx != 1 ) ) { throw new ClassfileFormatException ( "Bad subfield index " + subFieldIdx + " for tag " + t + ", cannot continue reading class. " + "Please report this at https://github.com/classgraph/classgraph/issues" ) ; } int cpIdxToUse ; if ( t == 0 ) { // Assume this means null return 0 ; } else if ( t == 1 ) { // CONSTANT_Utf8 cpIdxToUse = cpIdx ; } else if ( t == 7 || t == 8 || t == 19 ) { // t == 7 => CONSTANT_Class, e.g. "[[I", "[Ljava/lang/Thread;"; t == 8 => CONSTANT_String; // t == 19 => CONSTANT_Method_Info final int indirIdx = indirectStringRefs [ cpIdx ] ; if ( indirIdx == - 1 ) { // Should not happen throw new ClassfileFormatException ( "Bad string indirection index, cannot continue reading class. " + "Please report this at https://github.com/classgraph/classgraph/issues" ) ; } if ( indirIdx == 0 ) { // I assume this represents a null string, since the zeroeth entry is unused return 0 ; } cpIdxToUse = indirIdx ; } else if ( t == 12 ) { // CONSTANT_NameAndType_info final int compoundIndirIdx = indirectStringRefs [ cpIdx ] ; if ( compoundIndirIdx == - 1 ) { // Should not happen throw new ClassfileFormatException ( "Bad string indirection index, cannot continue reading class. " + "Please report this at https://github.com/classgraph/classgraph/issues" ) ; } final int indirIdx = ( subFieldIdx == 0 ? ( compoundIndirIdx >> 16 ) : compoundIndirIdx ) & 0xffff ; if ( indirIdx == 0 ) { // Should not happen throw new ClassfileFormatException ( "Bad string indirection index, cannot continue reading class. " + "Please report this at https://github.com/classgraph/classgraph/issues" ) ; } cpIdxToUse = indirIdx ; } else { throw new ClassfileFormatException ( "Wrong tag number " + t + " at constant pool index " + cpIdx + ", " + "cannot continue reading class. Please report this at " + "https://github.com/classgraph/classgraph/issues" ) ; } if ( cpIdxToUse < 1 || cpIdxToUse >= cpCount ) { throw new ClassfileFormatException ( "Constant pool index " + cpIdx + ", should be in range [1, " + ( cpCount - 1 ) + "] -- cannot continue reading class. " + "Please report this at https://github.com/classgraph/classgraph/issues" ) ; } return entryOffset [ cpIdxToUse ] ; }
Get the byte offset within the buffer of a string from the constant pool or 0 for a null string .