Program: 3662
Project: 3662
Buggy source:
/** 
 * Directly examine contents of classfile binary header.
 * @param verbose
 */
public void readClassInfoFromClassfileHeader(final InputStream inputStream,boolean verbose) throws IOException {
  final DataInputStream inp=new DataInputStream(new BufferedInputStream(inputStream,1024));
  if (inp.readInt() != 0xCAFEBABE) {
    return;
  }
  inp.readUnsignedShort();
  inp.readUnsignedShort();
  final int cpCount=inp.readUnsignedShort();
  final Object[] constantPool=new Object[cpCount];
  final int[] indirectStringRef=new int[cpCount];
  Arrays.fill(indirectStringRef,-1);
  for (int i=1; i < cpCount; ++i) {
    final int tag=inp.readUnsignedByte();
switch (tag) {
case 1:
      constantPool[i]=inp.readUTF();
    break;
case 3:
  constantPool[i]=inp.readInt();
break;
case 4:
constantPool[i]=inp.readFloat();
break;
case 5:
constantPool[i]=inp.readLong();
i++;
break;
case 6:
constantPool[i]=inp.readDouble();
i++;
break;
case 7:
case 8:
indirectStringRef[i]=inp.readUnsignedShort();
break;
case 9:
case 10:
case 11:
case 12:
inp.skipBytes(4);
break;
case 15:
inp.skipBytes(3);
break;
case 16:
inp.skipBytes(2);
break;
case 18:
inp.skipBytes(4);
break;
default :
break;
}
}
for (int i=1; i < cpCount; i++) {
if (indirectStringRef[i] >= 0) {
constantPool[i]=constantPool[indirectStringRef[i]];
}
}
final int flags=inp.readUnsignedShort();
final boolean isInterface=(flags & 0x0200) != 0;
final boolean isAnnotation=(flags & 0x2000) != 0;
final String className=readRefdString(inp,constantPool).replace('/','.');
if (className.equals("String_Node_Str")) {
return;
}
if (!classesEncounteredSoFarDuringScan.add(className)) {
return;
}
final String superclassName=readRefdString(inp,constantPool).replace('/','.');
final HashMap<String,StaticFinalFieldMatchProcessor> staticFieldnameToMatchProcessor=classNameToStaticFieldnameToMatchProcessor.get(className);
final int interfaceCount=inp.readUnsignedShort();
final ArrayList<String> interfaces=interfaceCount > 0 ? new ArrayList<String>() : null;
for (int i=0; i < interfaceCount; i++) {
interfaces.add(readRefdString(inp,constantPool).replace('/','.'));
}
final int fieldCount=inp.readUnsignedShort();
for (int i=0; i < fieldCount; i++) {
final int accessFlags=inp.readUnsignedShort();
final boolean isStaticFinal=(accessFlags & 0x0018) == 0x0018;
final String fieldName=readRefdString(inp,constantPool);
final StaticFinalFieldMatchProcessor staticFinalFieldMatchProcessor=staticFieldnameToMatchProcessor != null ? staticFieldnameToMatchProcessor.get(fieldName) : null;
final String descriptor=readRefdString(inp,constantPool);
final int attributesCount=inp.readUnsignedShort();
if (!isStaticFinal && staticFinalFieldMatchProcessor != null) {
System.err.println(StaticFinalFieldMatchProcessor.class.getSimpleName() + "String_Node_Str" + className+ "String_Node_Str"+ fieldName+ "String_Node_Str");
}
 else if (!isStaticFinal || staticFinalFieldMatchProcessor == null) {
for (int j=0; j < attributesCount; j++) {
inp.skipBytes(2);
final int attributeLength=inp.readInt();
inp.skipBytes(attributeLength);
}
}
 else {
boolean foundConstantValue=false;
for (int j=0; j < attributesCount; j++) {
final String attributeName=readRefdString(inp,constantPool);
final int attributeLength=inp.readInt();
if (attributeName.equals("String_Node_Str")) {
Object constValue=constantPool[inp.readUnsignedShort()];
switch (descriptor) {
case "String_Node_Str":
constValue=((Integer)constValue).byteValue();
break;
case "String_Node_Str":
constValue=(char)((Integer)constValue).intValue();
break;
case "String_Node_Str":
constValue=((Integer)constValue).shortValue();
break;
case "String_Node_Str":
constValue=((Integer)constValue).intValue() != 0;
break;
case "String_Node_Str":
case "String_Node_Str":
case "String_Node_Str":
case "String_Node_Str":
case "String_Node_Str":
break;
default :
break;
}
if (verbose) {
Log.log("String_Node_Str" + className + "String_Node_Str"+ fieldName+ "String_Node_Str"+ constValue);
}
staticFinalFieldMatchProcessor.processMatch(className,fieldName,constValue);
foundConstantValue=true;
}
 else {
inp.skipBytes(attributeLength);
}
if (!foundConstantValue) {
System.err.println(StaticFinalFieldMatchProcessor.class.getSimpleName() + "String_Node_Str" + className+ "String_Node_Str"+ fieldName+ "String_Node_Str"+ "String_Node_Str");
}
}
}
}
final int methodCount=inp.readUnsignedShort();
for (int i=0; i < methodCount; i++) {
inp.skipBytes(6);
final int attributesCount=inp.readUnsignedShort();
for (int j=0; j < attributesCount; j++) {
inp.skipBytes(2);
final int attributeLength=inp.readInt();
inp.skipBytes(attributeLength);
}
}
for (int i=0; i < inp.readUnsignedShort(); i++) {
final String attributeName=readRefdString(inp,constantPool);
final int attributeLength=inp.readInt();
if ("String_Node_Str".equals(attributeName)) {
final int annotationCount=inp.readUnsignedShort();
for (int m=0; m < annotationCount; m++) {
final String annotationName=readAnnotation(inp,constantPool);
linkAnnotation(annotationName,className,isAnnotation);
}
}
 else {
inp.skipBytes(attributeLength);
}
}
if (isAnnotation) {
}
 else if (isInterface) {
linkInterface(interfaces,className);
}
 else {
linkClass(superclassName,interfaces,className);
}
}

Fixed version (ground truth):
/** 
 * Directly examine contents of classfile binary header.
 * @param verbose
 */
public void readClassInfoFromClassfileHeader(final InputStream inputStream,boolean verbose) throws IOException {
  final DataInputStream inp=new DataInputStream(new BufferedInputStream(inputStream,1024));
  if (inp.readInt() != 0xCAFEBABE) {
    return;
  }
  inp.readUnsignedShort();
  inp.readUnsignedShort();
  final int cpCount=inp.readUnsignedShort();
  final Object[] constantPool=new Object[cpCount];
  final int[] indirectStringRef=new int[cpCount];
  Arrays.fill(indirectStringRef,-1);
  for (int i=1; i < cpCount; ++i) {
    final int tag=inp.readUnsignedByte();
switch (tag) {
case 1:
      constantPool[i]=inp.readUTF();
    break;
case 3:
  constantPool[i]=inp.readInt();
break;
case 4:
constantPool[i]=inp.readFloat();
break;
case 5:
constantPool[i]=inp.readLong();
i++;
break;
case 6:
constantPool[i]=inp.readDouble();
i++;
break;
case 7:
case 8:
indirectStringRef[i]=inp.readUnsignedShort();
break;
case 9:
case 10:
case 11:
case 12:
inp.skipBytes(4);
break;
case 15:
inp.skipBytes(3);
break;
case 16:
inp.skipBytes(2);
break;
case 18:
inp.skipBytes(4);
break;
default :
break;
}
}
for (int i=1; i < cpCount; i++) {
if (indirectStringRef[i] >= 0) {
constantPool[i]=constantPool[indirectStringRef[i]];
}
}
final int flags=inp.readUnsignedShort();
final boolean isInterface=(flags & 0x0200) != 0;
final boolean isAnnotation=(flags & 0x2000) != 0;
final String className=readRefdString(inp,constantPool).replace('/','.');
if (className.equals("String_Node_Str")) {
return;
}
if (!classesEncounteredSoFarDuringScan.add(className)) {
return;
}
final String superclassName=readRefdString(inp,constantPool).replace('/','.');
final HashMap<String,StaticFinalFieldMatchProcessor> staticFieldnameToMatchProcessor=classNameToStaticFieldnameToMatchProcessor.get(className);
final int interfaceCount=inp.readUnsignedShort();
final ArrayList<String> interfaces=interfaceCount > 0 ? new ArrayList<String>() : null;
for (int i=0; i < interfaceCount; i++) {
interfaces.add(readRefdString(inp,constantPool).replace('/','.'));
}
final int fieldCount=inp.readUnsignedShort();
for (int i=0; i < fieldCount; i++) {
final int accessFlags=inp.readUnsignedShort();
final boolean isStaticFinal=(accessFlags & 0x0018) == 0x0018;
final String fieldName=readRefdString(inp,constantPool);
final StaticFinalFieldMatchProcessor staticFinalFieldMatchProcessor=staticFieldnameToMatchProcessor != null ? staticFieldnameToMatchProcessor.get(fieldName) : null;
final String descriptor=readRefdString(inp,constantPool);
final int attributesCount=inp.readUnsignedShort();
if (!isStaticFinal && staticFinalFieldMatchProcessor != null) {
System.err.println(StaticFinalFieldMatchProcessor.class.getSimpleName() + "String_Node_Str" + className+ "String_Node_Str"+ fieldName+ "String_Node_Str");
}
 else if (!isStaticFinal || staticFinalFieldMatchProcessor == null) {
for (int j=0; j < attributesCount; j++) {
inp.skipBytes(2);
final int attributeLength=inp.readInt();
inp.skipBytes(attributeLength);
}
}
 else {
boolean foundConstantValue=false;
for (int j=0; j < attributesCount; j++) {
final String attributeName=readRefdString(inp,constantPool);
final int attributeLength=inp.readInt();
if (attributeName.equals("String_Node_Str")) {
Object constValue=constantPool[inp.readUnsignedShort()];
switch (descriptor) {
case "String_Node_Str":
constValue=((Integer)constValue).byteValue();
break;
case "String_Node_Str":
constValue=(char)((Integer)constValue).intValue();
break;
case "String_Node_Str":
constValue=((Integer)constValue).shortValue();
break;
case "String_Node_Str":
constValue=((Integer)constValue).intValue() != 0;
break;
case "String_Node_Str":
case "String_Node_Str":
case "String_Node_Str":
case "String_Node_Str":
case "String_Node_Str":
break;
default :
break;
}
if (verbose) {
Log.log("String_Node_Str" + className + "String_Node_Str"+ fieldName+ "String_Node_Str"+ constValue);
}
staticFinalFieldMatchProcessor.processMatch(className,fieldName,constValue);
foundConstantValue=true;
}
 else {
inp.skipBytes(attributeLength);
}
if (!foundConstantValue) {
System.err.println(StaticFinalFieldMatchProcessor.class.getSimpleName() + "String_Node_Str" + className+ "String_Node_Str"+ fieldName+ "String_Node_Str"+ "String_Node_Str");
}
}
}
}
final int methodCount=inp.readUnsignedShort();
for (int i=0; i < methodCount; i++) {
inp.skipBytes(6);
final int attributesCount=inp.readUnsignedShort();
for (int j=0; j < attributesCount; j++) {
inp.skipBytes(2);
final int attributeLength=inp.readInt();
inp.skipBytes(attributeLength);
}
}
int attributesCount=inp.readUnsignedShort();
for (int i=0; i < attributesCount; i++) {
final String attributeName=readRefdString(inp,constantPool);
final int attributeLength=inp.readInt();
if ("String_Node_Str".equals(attributeName)) {
final int annotationCount=inp.readUnsignedShort();
for (int m=0; m < annotationCount; m++) {
final String annotationName=readAnnotation(inp,constantPool);
linkAnnotation(annotationName,className,isAnnotation);
}
}
 else {
inp.skipBytes(attributeLength);
}
}
if (isAnnotation) {
}
 else if (isInterface) {
linkInterface(interfaces,className);
}
 else {
linkClass(superclassName,interfaces,className);
}
}