Program: 31708
Project: 31708
Buggy source:
@Override public RelationalWriter getRelationalWriter(ClassInfo classInfo,String relationshipType,String relationshipDirection,Object scalarValue){
  if (!relationalWriterCache.containsKey(classInfo)) {
    relationalWriterCache.put(classInfo,new HashMap<DirectedRelationship,RelationalWriter>());
  }
  DirectedRelationship directedRelationship=new DirectedRelationship(relationshipType,relationshipDirection);
  if (relationalWriterCache.get(classInfo).containsKey(directedRelationship)) {
    return relationalWriterCache.get(classInfo).get(directedRelationship);
  }
  MethodInfo methodInfo=classInfo.relationshipSetter(relationshipType,relationshipDirection,STRICT_MODE);
  if (methodInfo != null && !methodInfo.getAnnotations().isEmpty()) {
    if (methodInfo.isTypeOf(scalarValue.getClass()) || methodInfo.isParameterisedTypeOf(scalarValue.getClass()) || methodInfo.isArrayOf(scalarValue.getClass())) {
      MethodWriter methodWriter=new MethodWriter(classInfo,methodInfo);
      relationalWriterCache.get(classInfo).put(directedRelationship,methodWriter);
      return methodWriter;
    }
  }
  FieldInfo fieldInfo=classInfo.relationshipField(relationshipType,relationshipDirection,STRICT_MODE);
  if (fieldInfo != null && !fieldInfo.getAnnotations().isEmpty()) {
    if (fieldInfo.isTypeOf(scalarValue.getClass()) || fieldInfo.isParameterisedTypeOf(scalarValue.getClass()) || fieldInfo.isArrayOf(scalarValue.getClass())) {
      FieldWriter fieldWriter=new FieldWriter(classInfo,fieldInfo);
      relationalWriterCache.get(classInfo).put(directedRelationship,fieldWriter);
      return fieldWriter;
    }
  }
  if (!relationshipDirection.equals(Relationship.INCOMING)) {
    methodInfo=classInfo.relationshipSetter(relationshipType,relationshipDirection,INFERRED_MODE);
    if (methodInfo != null && !methodInfo.getAnnotations().isEmpty()) {
      if (methodInfo.isTypeOf(scalarValue.getClass()) || methodInfo.isParameterisedTypeOf(scalarValue.getClass()) || methodInfo.isArrayOf(scalarValue.getClass())) {
        MethodWriter methodWriter=new MethodWriter(classInfo,methodInfo);
        relationalWriterCache.get(classInfo).put(directedRelationship,methodWriter);
        return methodWriter;
      }
    }
    fieldInfo=classInfo.relationshipField(relationshipType,relationshipDirection,INFERRED_MODE);
    if (fieldInfo != null && !fieldInfo.getAnnotations().isEmpty()) {
      if (fieldInfo.isTypeOf(scalarValue.getClass()) || fieldInfo.isParameterisedTypeOf(scalarValue.getClass()) || fieldInfo.isArrayOf(scalarValue.getClass())) {
        FieldWriter fieldWriter=new FieldWriter(classInfo,fieldInfo);
        relationalWriterCache.get(classInfo).put(directedRelationship,fieldWriter);
        return fieldWriter;
      }
    }
    methodInfo=classInfo.relationshipSetter(relationshipType,relationshipDirection,INFERRED_MODE);
    if (methodInfo != null) {
      if (methodInfo.isTypeOf(scalarValue.getClass()) || methodInfo.isParameterisedTypeOf(scalarValue.getClass()) || methodInfo.isArrayOf(scalarValue.getClass())) {
        MethodWriter methodWriter=new MethodWriter(classInfo,methodInfo);
        relationalWriterCache.get(classInfo).put(directedRelationship,methodWriter);
        return methodWriter;
      }
    }
    fieldInfo=classInfo.relationshipField(relationshipType,relationshipDirection,INFERRED_MODE);
    if (fieldInfo != null) {
      if (fieldInfo.isTypeOf(scalarValue.getClass()) || fieldInfo.isParameterisedTypeOf(scalarValue.getClass()) || fieldInfo.isArrayOf(scalarValue.getClass())) {
        FieldWriter fieldWriter=new FieldWriter(classInfo,fieldInfo);
        relationalWriterCache.get(classInfo).put(directedRelationship,fieldWriter);
        return fieldWriter;
      }
    }
    List<MethodInfo> methodInfos=classInfo.findSetters(scalarValue.getClass());
    if (methodInfos.size() == 1) {
      MethodInfo candidateMethodInfo=methodInfos.iterator().next();
      if (!candidateMethodInfo.relationshipDirection(Relationship.UNDIRECTED).equals(Relationship.INCOMING)) {
        MethodWriter methodWriter=new MethodWriter(classInfo,candidateMethodInfo);
        relationalWriterCache.get(classInfo).put(directedRelationship,methodWriter);
        return methodWriter;
      }
    }
    List<FieldInfo> fieldInfos=classInfo.findFields(scalarValue.getClass());
    if (fieldInfos.size() == 1) {
      FieldInfo candidateFieldInfo=fieldInfos.iterator().next();
      if (!candidateFieldInfo.relationshipDirection(Relationship.UNDIRECTED).equals(Relationship.INCOMING)) {
        FieldWriter fieldWriter=new FieldWriter(classInfo,candidateFieldInfo);
        relationalWriterCache.get(classInfo).put(directedRelationship,fieldWriter);
        return fieldWriter;
      }
    }
  }
  relationalWriterCache.get(classInfo).put(directedRelationship,null);
  return null;
}

Fixed version (ground truth):
@Override public RelationalWriter getRelationalWriter(ClassInfo classInfo,String relationshipType,String relationshipDirection,Object scalarValue){
  if (!relationalWriterCache.containsKey(classInfo)) {
    relationalWriterCache.put(classInfo,new HashMap<DirectedRelationshipForType,RelationalWriter>());
  }
  DirectedRelationshipForType directedRelationship=new DirectedRelationshipForType(relationshipType,relationshipDirection,scalarValue.getClass());
  if (relationalWriterCache.get(classInfo).containsKey(directedRelationship)) {
    return relationalWriterCache.get(classInfo).get(directedRelationship);
  }
  MethodInfo methodInfo=classInfo.relationshipSetter(relationshipType,relationshipDirection,STRICT_MODE);
  if (methodInfo != null && !methodInfo.getAnnotations().isEmpty()) {
    if (methodInfo.isTypeOf(scalarValue.getClass()) || methodInfo.isParameterisedTypeOf(scalarValue.getClass()) || methodInfo.isArrayOf(scalarValue.getClass())) {
      MethodWriter methodWriter=new MethodWriter(classInfo,methodInfo);
      relationalWriterCache.get(classInfo).put(directedRelationship,methodWriter);
      return methodWriter;
    }
  }
  FieldInfo fieldInfo=classInfo.relationshipField(relationshipType,relationshipDirection,STRICT_MODE);
  if (fieldInfo != null && !fieldInfo.getAnnotations().isEmpty()) {
    if (fieldInfo.isTypeOf(scalarValue.getClass()) || fieldInfo.isParameterisedTypeOf(scalarValue.getClass()) || fieldInfo.isArrayOf(scalarValue.getClass())) {
      FieldWriter fieldWriter=new FieldWriter(classInfo,fieldInfo);
      relationalWriterCache.get(classInfo).put(directedRelationship,fieldWriter);
      return fieldWriter;
    }
  }
  if (!relationshipDirection.equals(Relationship.INCOMING)) {
    methodInfo=classInfo.relationshipSetter(relationshipType,relationshipDirection,INFERRED_MODE);
    if (methodInfo != null && !methodInfo.getAnnotations().isEmpty()) {
      if (methodInfo.isTypeOf(scalarValue.getClass()) || methodInfo.isParameterisedTypeOf(scalarValue.getClass()) || methodInfo.isArrayOf(scalarValue.getClass())) {
        MethodWriter methodWriter=new MethodWriter(classInfo,methodInfo);
        relationalWriterCache.get(classInfo).put(directedRelationship,methodWriter);
        return methodWriter;
      }
    }
    fieldInfo=classInfo.relationshipField(relationshipType,relationshipDirection,INFERRED_MODE);
    if (fieldInfo != null && !fieldInfo.getAnnotations().isEmpty()) {
      if (fieldInfo.isTypeOf(scalarValue.getClass()) || fieldInfo.isParameterisedTypeOf(scalarValue.getClass()) || fieldInfo.isArrayOf(scalarValue.getClass())) {
        FieldWriter fieldWriter=new FieldWriter(classInfo,fieldInfo);
        relationalWriterCache.get(classInfo).put(directedRelationship,fieldWriter);
        return fieldWriter;
      }
    }
    methodInfo=classInfo.relationshipSetter(relationshipType,relationshipDirection,INFERRED_MODE);
    if (methodInfo != null) {
      if (methodInfo.isTypeOf(scalarValue.getClass()) || methodInfo.isParameterisedTypeOf(scalarValue.getClass()) || methodInfo.isArrayOf(scalarValue.getClass())) {
        MethodWriter methodWriter=new MethodWriter(classInfo,methodInfo);
        relationalWriterCache.get(classInfo).put(directedRelationship,methodWriter);
        return methodWriter;
      }
    }
    fieldInfo=classInfo.relationshipField(relationshipType,relationshipDirection,INFERRED_MODE);
    if (fieldInfo != null) {
      if (fieldInfo.isTypeOf(scalarValue.getClass()) || fieldInfo.isParameterisedTypeOf(scalarValue.getClass()) || fieldInfo.isArrayOf(scalarValue.getClass())) {
        FieldWriter fieldWriter=new FieldWriter(classInfo,fieldInfo);
        relationalWriterCache.get(classInfo).put(directedRelationship,fieldWriter);
        return fieldWriter;
      }
    }
    List<MethodInfo> methodInfos=classInfo.findSetters(scalarValue.getClass());
    if (methodInfos.size() == 1) {
      MethodInfo candidateMethodInfo=methodInfos.iterator().next();
      if (!candidateMethodInfo.relationshipDirection(Relationship.UNDIRECTED).equals(Relationship.INCOMING)) {
        MethodWriter methodWriter=new MethodWriter(classInfo,candidateMethodInfo);
        relationalWriterCache.get(classInfo).put(directedRelationship,methodWriter);
        return methodWriter;
      }
    }
    List<FieldInfo> fieldInfos=classInfo.findFields(scalarValue.getClass());
    if (fieldInfos.size() == 1) {
      FieldInfo candidateFieldInfo=fieldInfos.iterator().next();
      if (!candidateFieldInfo.relationshipDirection(Relationship.UNDIRECTED).equals(Relationship.INCOMING)) {
        FieldWriter fieldWriter=new FieldWriter(classInfo,candidateFieldInfo);
        relationalWriterCache.get(classInfo).put(directedRelationship,fieldWriter);
        return fieldWriter;
      }
    }
  }
  relationalWriterCache.get(classInfo).put(directedRelationship,null);
  return null;
}