Program: 3673
Project: 3673
Buggy source:
/** 
 * Directly examine contents of classfile binary header.
 */
private void readClassInfoFromClassfileHeader(final InputStream inputStream) throws IOException {
  DataInputStream inp=new DataInputStream(new BufferedInputStream(inputStream,1024));
  if (inp.readInt() != 0xCAFEBABE) {
    return;
  }
  inp.readUnsignedShort();
  inp.readUnsignedShort();
  int cpCount=inp.readUnsignedShort();
  Object[] constantPool=new Object[cpCount];
  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]];
}
}
int flags=inp.readUnsignedShort();
boolean isInterface=(flags & 0x0200) != 0;
String className=readRefdString(inp,constantPool).replace('/','.');
if (!classesEncounteredSoFarDuringScan.add(className)) {
return;
}
String superclassName=readRefdString(inp,constantPool).replace('/','.');
HashMap<String,StaticFinalFieldMatchProcessor> staticFieldnameToMatchProcessor=classNameToStaticFieldnameToMatchProcessor.get(className);
int interfaceCount=inp.readUnsignedShort();
ArrayList<String> interfaces=interfaceCount > 0 ? new ArrayList<String>() : null;
for (int i=0; i < interfaceCount; i++) {
interfaces.add(readRefdString(inp,constantPool).replace('/','.'));
}
int fieldCount=inp.readUnsignedShort();
for (int i=0; i < fieldCount; i++) {
int accessFlags=inp.readUnsignedShort();
boolean isStaticFinal=(accessFlags & 0x0018) == 0x0018;
String fieldName=readRefdString(inp,constantPool);
StaticFinalFieldMatchProcessor staticFinalFieldMatchProcessor=staticFieldnameToMatchProcessor != null ? staticFieldnameToMatchProcessor.get(fieldName) : null;
String descriptor=readRefdString(inp,constantPool);
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);
int attributeLength=inp.readInt();
inp.skipBytes(attributeLength);
}
}
 else {
boolean foundConstantValue=false;
for (int j=0; j < attributesCount; j++) {
String attributeName=readRefdString(inp,constantPool);
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;
}
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");
}
}
}
}
int methodCount=inp.readUnsignedShort();
for (int i=0; i < methodCount; i++) {
inp.skipBytes(6);
int attributesCount=inp.readUnsignedShort();
for (int j=0; j < attributesCount; j++) {
inp.skipBytes(2);
int attributeLength=inp.readInt();
inp.skipBytes(attributeLength);
}
}
HashSet<String> annotations=null;
int attributesCount=inp.readUnsignedShort();
for (int i=0; i < attributesCount; i++) {
String attributeName=readRefdString(inp,constantPool);
int attributeLength=inp.readInt();
if ("String_Node_Str".equals(attributeName)) {
int annotationCount=inp.readUnsignedShort();
for (int m=0; m < annotationCount; m++) {
String annotationName=readAnnotation(inp,constantPool);
if (annotations == null) {
annotations=new HashSet<>();
}
annotations.add(annotationName);
}
}
 else {
inp.skipBytes(attributeLength);
}
}
if (isInterface) {
classGraphBuilder.linkToSuperinterfaces(className,interfaces);
}
 else {
classGraphBuilder.linkToSuperclassAndInterfaces(className,superclassName,interfaces,annotations);
}
}

Fixed version (ground truth):
/** 
 * Directly examine contents of classfile binary header.
 */
private void readClassInfoFromClassfileHeader(final InputStream inputStream) throws IOException {
  DataInputStream inp=new DataInputStream(new BufferedInputStream(inputStream,1024));
  if (inp.readInt() != 0xCAFEBABE) {
    return;
  }
  inp.readUnsignedShort();
  inp.readUnsignedShort();
  int cpCount=inp.readUnsignedShort();
  Object[] constantPool=new Object[cpCount];
  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]];
}
}
int flags=inp.readUnsignedShort();
boolean isInterface=(flags & 0x0200) != 0;
String className=readRefdString(inp,constantPool).replace('/','.');
if (className.equals("String_Node_Str")) {
return;
}
if (!classesEncounteredSoFarDuringScan.add(className)) {
return;
}
String superclassName=readRefdString(inp,constantPool).replace('/','.');
HashMap<String,StaticFinalFieldMatchProcessor> staticFieldnameToMatchProcessor=classNameToStaticFieldnameToMatchProcessor.get(className);
int interfaceCount=inp.readUnsignedShort();
ArrayList<String> interfaces=interfaceCount > 0 ? new ArrayList<String>() : null;
for (int i=0; i < interfaceCount; i++) {
interfaces.add(readRefdString(inp,constantPool).replace('/','.'));
}
int fieldCount=inp.readUnsignedShort();
for (int i=0; i < fieldCount; i++) {
int accessFlags=inp.readUnsignedShort();
boolean isStaticFinal=(accessFlags & 0x0018) == 0x0018;
String fieldName=readRefdString(inp,constantPool);
StaticFinalFieldMatchProcessor staticFinalFieldMatchProcessor=staticFieldnameToMatchProcessor != null ? staticFieldnameToMatchProcessor.get(fieldName) : null;
String descriptor=readRefdString(inp,constantPool);
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);
int attributeLength=inp.readInt();
inp.skipBytes(attributeLength);
}
}
 else {
boolean foundConstantValue=false;
for (int j=0; j < attributesCount; j++) {
String attributeName=readRefdString(inp,constantPool);
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;
}
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");
}
}
}
}
int methodCount=inp.readUnsignedShort();
for (int i=0; i < methodCount; i++) {
inp.skipBytes(6);
int attributesCount=inp.readUnsignedShort();
for (int j=0; j < attributesCount; j++) {
inp.skipBytes(2);
int attributeLength=inp.readInt();
inp.skipBytes(attributeLength);
}
}
HashSet<String> annotations=null;
int attributesCount=inp.readUnsignedShort();
for (int i=0; i < attributesCount; i++) {
String attributeName=readRefdString(inp,constantPool);
int attributeLength=inp.readInt();
if ("String_Node_Str".equals(attributeName)) {
int annotationCount=inp.readUnsignedShort();
for (int m=0; m < annotationCount; m++) {
String annotationName=readAnnotation(inp,constantPool);
if (annotations == null) {
annotations=new HashSet<>();
}
annotations.add(annotationName);
}
}
 else {
inp.skipBytes(attributeLength);
}
}
if (isInterface) {
classGraphBuilder.linkToSuperinterfaces(className,interfaces);
}
 else {
classGraphBuilder.linkToSuperclassAndInterfaces(className,superclassName,interfaces,annotations);
}
}