Program: 85301
Project: 85301
Buggy source:
/** 
 * Encodes Annotations Elements from Jimple to Dexlib
 * @param elem Jimple Element
 * @return Dexlib encoded element
 */
private EncodedValue buildEncodedValueForAnnotation(AnnotationElem elem){
switch (elem.getKind()) {
case 'Z':
{
      if (elem instanceof AnnotationIntElem) {
        AnnotationIntElem e=(AnnotationIntElem)elem;
        if (e.getValue() == 0) {
          return ImmutableBooleanEncodedValue.FALSE_VALUE;
        }
 else         if (e.getValue() == 1) {
          return ImmutableBooleanEncodedValue.TRUE_VALUE;
        }
 else {
          throw new RuntimeException("String_Node_Str");
        }
      }
 else       if (elem instanceof AnnotationBooleanElem) {
        AnnotationBooleanElem e=(AnnotationBooleanElem)elem;
        if (e.getValue())         return ImmutableBooleanEncodedValue.TRUE_VALUE;
 else         return ImmutableBooleanEncodedValue.FALSE_VALUE;
      }
 else       throw new RuntimeException("String_Node_Str");
    }
case 'S':
{
    AnnotationIntElem e=(AnnotationIntElem)elem;
    return new ImmutableShortEncodedValue((short)e.getValue());
  }
case 'B':
{
  AnnotationIntElem e=(AnnotationIntElem)elem;
  return new ImmutableByteEncodedValue((byte)e.getValue());
}
case 'C':
{
AnnotationIntElem e=(AnnotationIntElem)elem;
return new ImmutableCharEncodedValue((char)e.getValue());
}
case 'I':
{
AnnotationIntElem e=(AnnotationIntElem)elem;
return new ImmutableIntEncodedValue(e.getValue());
}
case 'J':
{
AnnotationLongElem e=(AnnotationLongElem)elem;
return new ImmutableLongEncodedValue(e.getValue());
}
case 'F':
{
AnnotationFloatElem e=(AnnotationFloatElem)elem;
return new ImmutableFloatEncodedValue(e.getValue());
}
case 'D':
{
AnnotationDoubleElem e=(AnnotationDoubleElem)elem;
return new ImmutableDoubleEncodedValue(e.getValue());
}
case 's':
{
AnnotationStringElem e=(AnnotationStringElem)elem;
return new ImmutableStringEncodedValue(e.getValue());
}
case 'e':
{
AnnotationEnumElem e=(AnnotationEnumElem)elem;
String classT=SootToDexUtils.getDexClassName(e.getTypeName());
String fieldT=classT;
FieldReference fref=dexFile.internFieldReference(new ImmutableFieldReference(classT,e.getConstantName(),fieldT));
return new ImmutableEnumEncodedValue(fref);
}
case 'c':
{
AnnotationClassElem e=(AnnotationClassElem)elem;
return new ImmutableTypeEncodedValue(SootToDexUtils.getDexClassName(e.getDesc()));
}
case '[':
{
AnnotationArrayElem e=(AnnotationArrayElem)elem;
List<EncodedValue> values=new ArrayList<EncodedValue>();
for (int i=0; i < e.getNumValues(); i++) {
EncodedValue val=buildEncodedValueForAnnotation(e.getValueAt(i));
values.add(val);
}
return new ImmutableArrayEncodedValue(values);
}
case '@':
{
AnnotationAnnotationElem e=(AnnotationAnnotationElem)elem;
Set<String> alreadyWritten=new HashSet<String>();
List<AnnotationElement> elements=null;
if (!e.getValue().getElems().isEmpty()) {
elements=new ArrayList<AnnotationElement>();
for (AnnotationElem ae : e.getValue().getElems()) {
if (!alreadyWritten.add(ae.getName())) throw new RuntimeException("String_Node_Str" + ae.getName());
AnnotationElement element=new ImmutableAnnotationElement(ae.getName(),buildEncodedValueForAnnotation(ae));
elements.add(element);
}
}
return new ImmutableAnnotationEncodedValue(SootToDexUtils.getDexClassName(e.getValue().getType()),elements);
}
case 'f':
{
AnnotationStringElem e=(AnnotationStringElem)elem;
String fSig=e.getValue();
String[] sp=fSig.split("String_Node_Str");
String classString=SootToDexUtils.getDexClassName(sp[0].split("String_Node_Str")[0]);
if (classString.isEmpty()) throw new RuntimeException("String_Node_Str");
String typeString=sp[1];
if (typeString.isEmpty()) throw new RuntimeException("String_Node_Str");
String fieldName=sp[2];
FieldReference fref=dexFile.internFieldReference(new ImmutableFieldReference(classString,fieldName,typeString));
return new ImmutableFieldEncodedValue(fref);
}
case 'M':
{
AnnotationStringElem e=(AnnotationStringElem)elem;
String[] sp=e.getValue().split("String_Node_Str");
String classString=SootToDexUtils.getDexClassName(sp[0].split("String_Node_Str")[0]);
if (classString.isEmpty()) throw new RuntimeException("String_Node_Str");
String returnType=sp[1];
String[] sp2=sp[2].split("String_Node_Str");
String methodNameString=sp2[0];
String parameters=sp2[1].replaceAll("String_Node_Str","String_Node_Str");
List<String> paramTypeList=null;
if (!parameters.isEmpty()) {
paramTypeList=new ArrayList<String>();
if (parameters.length() > 0) for (String p : parameters.split("String_Node_Str")) {
paramTypeList.add(p);
}
}
MethodReference mref=dexFile.internMethodReference(new ImmutableMethodReference(classString,methodNameString,paramTypeList,returnType));
return new ImmutableMethodEncodedValue(mref);
}
case 'N':
{
return ImmutableNullEncodedValue.INSTANCE;
}
default :
throw new RuntimeException("String_Node_Str" + elem.getKind());
}
}

Fixed version (ground truth):
/** 
 * Encodes Annotations Elements from Jimple to Dexlib
 * @param elem Jimple Element
 * @return Dexlib encoded element
 */
private EncodedValue buildEncodedValueForAnnotation(AnnotationElem elem){
switch (elem.getKind()) {
case 'Z':
{
      if (elem instanceof AnnotationIntElem) {
        AnnotationIntElem e=(AnnotationIntElem)elem;
        if (e.getValue() == 0) {
          return ImmutableBooleanEncodedValue.FALSE_VALUE;
        }
 else         if (e.getValue() == 1) {
          return ImmutableBooleanEncodedValue.TRUE_VALUE;
        }
 else {
          throw new RuntimeException("String_Node_Str");
        }
      }
 else       if (elem instanceof AnnotationBooleanElem) {
        AnnotationBooleanElem e=(AnnotationBooleanElem)elem;
        if (e.getValue())         return ImmutableBooleanEncodedValue.TRUE_VALUE;
 else         return ImmutableBooleanEncodedValue.FALSE_VALUE;
      }
 else       throw new RuntimeException("String_Node_Str");
    }
case 'S':
{
    AnnotationIntElem e=(AnnotationIntElem)elem;
    return new ImmutableShortEncodedValue((short)e.getValue());
  }
case 'B':
{
  AnnotationIntElem e=(AnnotationIntElem)elem;
  return new ImmutableByteEncodedValue((byte)e.getValue());
}
case 'C':
{
AnnotationIntElem e=(AnnotationIntElem)elem;
return new ImmutableCharEncodedValue((char)e.getValue());
}
case 'I':
{
AnnotationIntElem e=(AnnotationIntElem)elem;
return new ImmutableIntEncodedValue(e.getValue());
}
case 'J':
{
AnnotationLongElem e=(AnnotationLongElem)elem;
return new ImmutableLongEncodedValue(e.getValue());
}
case 'F':
{
AnnotationFloatElem e=(AnnotationFloatElem)elem;
return new ImmutableFloatEncodedValue(e.getValue());
}
case 'D':
{
AnnotationDoubleElem e=(AnnotationDoubleElem)elem;
return new ImmutableDoubleEncodedValue(e.getValue());
}
case 's':
{
AnnotationStringElem e=(AnnotationStringElem)elem;
return new ImmutableStringEncodedValue(e.getValue());
}
case 'e':
{
AnnotationEnumElem e=(AnnotationEnumElem)elem;
String classT=SootToDexUtils.getDexClassName(e.getTypeName());
String fieldT=classT;
FieldReference fref=dexFile.internFieldReference(new ImmutableFieldReference(classT,e.getConstantName(),fieldT));
return new ImmutableEnumEncodedValue(fref);
}
case 'c':
{
AnnotationClassElem e=(AnnotationClassElem)elem;
return new ImmutableTypeEncodedValue(e.getDesc());
}
case '[':
{
AnnotationArrayElem e=(AnnotationArrayElem)elem;
List<EncodedValue> values=new ArrayList<EncodedValue>();
for (int i=0; i < e.getNumValues(); i++) {
EncodedValue val=buildEncodedValueForAnnotation(e.getValueAt(i));
values.add(val);
}
return new ImmutableArrayEncodedValue(values);
}
case '@':
{
AnnotationAnnotationElem e=(AnnotationAnnotationElem)elem;
Set<String> alreadyWritten=new HashSet<String>();
List<AnnotationElement> elements=null;
if (!e.getValue().getElems().isEmpty()) {
elements=new ArrayList<AnnotationElement>();
for (AnnotationElem ae : e.getValue().getElems()) {
if (!alreadyWritten.add(ae.getName())) throw new RuntimeException("String_Node_Str" + ae.getName());
AnnotationElement element=new ImmutableAnnotationElement(ae.getName(),buildEncodedValueForAnnotation(ae));
elements.add(element);
}
}
return new ImmutableAnnotationEncodedValue(SootToDexUtils.getDexClassName(e.getValue().getType()),elements);
}
case 'f':
{
AnnotationStringElem e=(AnnotationStringElem)elem;
String fSig=e.getValue();
String[] sp=fSig.split("String_Node_Str");
String classString=SootToDexUtils.getDexClassName(sp[0].split("String_Node_Str")[0]);
if (classString.isEmpty()) throw new RuntimeException("String_Node_Str");
String typeString=sp[1];
if (typeString.isEmpty()) throw new RuntimeException("String_Node_Str");
String fieldName=sp[2];
FieldReference fref=dexFile.internFieldReference(new ImmutableFieldReference(classString,fieldName,typeString));
return new ImmutableFieldEncodedValue(fref);
}
case 'M':
{
AnnotationStringElem e=(AnnotationStringElem)elem;
String[] sp=e.getValue().split("String_Node_Str");
String classString=SootToDexUtils.getDexClassName(sp[0].split("String_Node_Str")[0]);
if (classString.isEmpty()) throw new RuntimeException("String_Node_Str");
String returnType=sp[1];
String[] sp2=sp[2].split("String_Node_Str");
String methodNameString=sp2[0];
String parameters=sp2[1].replaceAll("String_Node_Str","String_Node_Str");
List<String> paramTypeList=null;
if (!parameters.isEmpty()) {
paramTypeList=new ArrayList<String>();
if (parameters.length() > 0) for (String p : parameters.split("String_Node_Str")) {
paramTypeList.add(p);
}
}
MethodReference mref=dexFile.internMethodReference(new ImmutableMethodReference(classString,methodNameString,paramTypeList,returnType));
return new ImmutableMethodEncodedValue(mref);
}
case 'N':
{
return ImmutableNullEncodedValue.INSTANCE;
}
default :
throw new RuntimeException("String_Node_Str" + elem.getKind());
}
}