Program: 87130
Project: 87130
Buggy source:
private void validateFile(final String path,final String profile,final List<String> columns,final JsonArray existExternalId,final String charset,final Handler<JsonObject> handler){
  final Validator validator=profiles.get(profile);
  getStructure(path.substring(0,path.lastIndexOf(File.separator)),new Handler<Structure>(){
    @Override public void handle(    final Structure structure){
      if (structure == null) {
        addError(profile,"String_Node_Str");
        handler.handle(result);
        return;
      }
      try {
        CSVReader csvParser=getCsvReader(path,charset,1);
        String[] strings;
        int i=0;
        while ((strings=csvParser.readNext()) != null) {
          final JsonArray classesNames=new JsonArray();
          JsonObject user=new JsonObject();
          user.putArray("String_Node_Str",new JsonArray().add(structure.getExternalId()));
          user.putArray("String_Node_Str",new JsonArray().add(profile));
          List<String[]> classes=new ArrayList<>();
          for (int j=0; j < strings.length; j++) {
            if (j >= columns.size()) {
              addErrorByFile(profile,"String_Node_Str","String_Node_Str" + i);
              return;
            }
            final String c=columns.get(j);
            final String v=strings[j].trim();
            if ((v.isEmpty() && !"String_Node_Str".equals(c)) || (v.isEmpty() && "String_Node_Str".equals(c) && strings[j + 1].trim().isEmpty()))             continue;
switch (validator.getType(c)) {
case "String_Node_Str":
              if ("String_Node_Str".equals(c)) {
                Matcher m=frenchDatePatter.matcher(v);
                if (m.find()) {
                  user.putString(c,m.group(3) + "String_Node_Str" + m.group(2)+ "String_Node_Str"+ m.group(1));
                }
 else {
                  user.putString(c,v);
                }
              }
 else {
                user.putString(c,v);
              }
            break;
case "String_Node_Str":
          JsonArray a=user.getArray(c);
        if (a == null) {
          a=new JsonArray();
          user.putArray(c,a);
        }
      if (("String_Node_Str".equals(c) || "String_Node_Str".equals(c) || "String_Node_Str".equals(c)) && !v.startsWith(structure.getExternalId() + "String_Node_Str")) {
        a.add(structure.getExternalId() + "String_Node_Str" + v);
      }
 else {
        a.add(v);
      }
    break;
case "String_Node_Str":
  user.putBoolean(c,"String_Node_Str".equals(v.toLowerCase()));
break;
default :
Object o=user.getValue(c);
final String v2;
if ("String_Node_Str".equals(c) && !v.startsWith(structure.getExternalId() + "String_Node_Str")) {
v2=structure.getExternalId() + "String_Node_Str" + v;
}
 else {
v2=v;
}
if (o != null) {
if (o instanceof JsonArray) {
((JsonArray)o).add(v2);
}
 else {
JsonArray array=new JsonArray();
array.add(o).add(v2);
user.putArray(c,array);
}
}
 else {
user.putString(c,v2);
}
}
if ("String_Node_Str".equals(c)) {
String eId=structure.getExternalId() + '$' + v;
String[] classId=new String[2];
classId[0]=structure.getExternalId();
classId[1]=eId;
classes.add(classId);
classesNames.addString(v);
}
}
String ca;
long seed;
JsonArray classesA;
Object co=user.getValue("String_Node_Str");
if (co != null && co instanceof JsonArray) {
classesA=(JsonArray)co;
}
 else if (co instanceof String) {
classesA=new JsonArray().add(co);
}
 else {
classesA=null;
}
if ("String_Node_Str".equals(profile) && classesA != null && classesA.size() == 1) {
seed=CsvFeeder.DEFAULT_STUDENT_SEED;
ca=classesA.get(0);
}
 else {
ca=String.valueOf(i);
seed=System.currentTimeMillis();
}
final State state;
final String externalId=user.getString("String_Node_Str");
if (externalId == null || externalId.trim().isEmpty()) {
generateUserExternalId(user,ca,structure,seed);
state=State.NEW;
}
 else {
if (existExternalId.contains(externalId)) {
state=State.UPDATED;
}
 else {
state=State.NEW;
}
}
switch (profile) {
case "String_Node_Str":
JsonArray linkStudents=new JsonArray();
user.putArray("String_Node_Str",linkStudents);
for (String attr : user.getFieldNames()) {
if ("String_Node_Str".equals(attr)) {
Object o=user.getValue(attr);
if (o instanceof JsonArray) {
for (Object c : (JsonArray)o) {
linkStudents.add(c);
}
}
 else {
linkStudents.add(o);
}
}
 else if ("String_Node_Str".equals(attr)) {
Object childUsername=user.getValue(attr);
Object childLastName=user.getValue("String_Node_Str");
Object childFirstName=user.getValue("String_Node_Str");
Object childClasses=user.getValue("String_Node_Str");
if (childUsername instanceof JsonArray && childLastName instanceof JsonArray && childFirstName instanceof JsonArray&& childClasses instanceof JsonArray&& ((JsonArray)childClasses).size() == ((JsonArray)childLastName).size() && ((JsonArray)childFirstName).size() == ((JsonArray)childLastName).size()) {
for (int j=0; j < ((JsonArray)childUsername).size(); j++) {
String mapping=structure.getExternalId() + ((JsonArray)childUsername).<String>get(j).trim() + ((JsonArray)childLastName).<String>get(j).trim()+ ((JsonArray)childFirstName).<String>get(j).trim()+ ((JsonArray)childClasses).<String>get(j).trim()+ CsvFeeder.DEFAULT_STUDENT_SEED;
relativeStudentMapping(linkStudents,mapping);
}
}
 else if (childUsername instanceof String && childLastName instanceof String && childFirstName instanceof String&& childClasses instanceof String) {
String mapping=structure.getExternalId() + childLastName.toString().trim() + childFirstName.toString().trim()+ childClasses.toString().trim()+ CsvFeeder.DEFAULT_STUDENT_SEED;
relativeStudentMapping(linkStudents,mapping);
}
 else {
addError(profile,"String_Node_Str");
handler.handle(result);
return;
}
}
 else if ("String_Node_Str".equals(attr) && !user.getFieldNames().contains("String_Node_Str")) {
Object childLastName=user.getValue(attr);
Object childFirstName=user.getValue("String_Node_Str");
Object childClasses=user.getValue("String_Node_Str");
if (childLastName instanceof JsonArray && childFirstName instanceof JsonArray && childClasses instanceof JsonArray&& ((JsonArray)childClasses).size() == ((JsonArray)childLastName).size() && ((JsonArray)childFirstName).size() == ((JsonArray)childLastName).size()) {
for (int j=0; j < ((JsonArray)childLastName).size(); j++) {
String mapping=structure.getExternalId() + ((JsonArray)childLastName).<String>get(j) + ((JsonArray)childFirstName).<String>get(j)+ ((JsonArray)childClasses).<String>get(j)+ CsvFeeder.DEFAULT_STUDENT_SEED;
relativeStudentMapping(linkStudents,mapping);
}
}
 else if (childLastName instanceof String && childFirstName instanceof String && childClasses instanceof String) {
String mapping=structure.getExternalId() + childLastName.toString().trim() + childFirstName.toString().trim()+ childClasses.toString().trim()+ CsvFeeder.DEFAULT_STUDENT_SEED;
relativeStudentMapping(linkStudents,mapping);
}
 else {
addError(profile,"String_Node_Str");
handler.handle(result);
return;
}
}
}
for (Object o : linkStudents) {
if (!(o instanceof String)) continue;
if (classesNamesMapping.get(o) != null) {
classesNames.addString(classesNamesMapping.get(o));
}
}
break;
}
String error=validator.validate(user,acceptLanguage);
if (error != null) {
log.warn(error);
addError(profile,error);
}
 else {
final String classesStr=Joiner.on("String_Node_Str").join(classesNames);
classesNamesMapping.put(user.getString("String_Node_Str"),classesStr);
addUser(profile,user.putString("String_Node_Str",translate(state.name())).putString("String_Node_Str",translate(profile)).putString("String_Node_Str",classesStr));
}
i++;
}
}
 catch (Exception e) {
addError(profile,"String_Node_Str");
log.error("String_Node_Str",e);
}
handler.handle(result);
}
}
);
}

Fixed version (ground truth):
private void validateFile(final String path,final String profile,final List<String> columns,final JsonArray existExternalId,final String charset,final Handler<JsonObject> handler){
  final Validator validator=profiles.get(profile);
  getStructure(path.substring(0,path.lastIndexOf(File.separator)),new Handler<Structure>(){
    @Override public void handle(    final Structure structure){
      if (structure == null) {
        addError(profile,"String_Node_Str");
        handler.handle(result);
        return;
      }
      try {
        CSVReader csvParser=getCsvReader(path,charset,1);
        String[] strings;
        int i=0;
        while ((strings=csvParser.readNext()) != null) {
          final JsonArray classesNames=new JsonArray();
          JsonObject user=new JsonObject();
          user.putArray("String_Node_Str",new JsonArray().add(structure.getExternalId()));
          user.putArray("String_Node_Str",new JsonArray().add(profile));
          List<String[]> classes=new ArrayList<>();
          for (int j=0; j < strings.length; j++) {
            if (j >= columns.size()) {
              addErrorByFile(profile,"String_Node_Str","String_Node_Str" + i);
              return;
            }
            final String c=columns.get(j);
            final String v=strings[j].trim();
            if ((v.isEmpty() && !"String_Node_Str".equals(c)) || (v.isEmpty() && "String_Node_Str".equals(c) && strings[j + 1].trim().isEmpty()))             continue;
switch (validator.getType(c)) {
case "String_Node_Str":
              if ("String_Node_Str".equals(c)) {
                Matcher m=frenchDatePatter.matcher(v);
                if (m.find()) {
                  user.putString(c,m.group(3) + "String_Node_Str" + m.group(2)+ "String_Node_Str"+ m.group(1));
                }
 else {
                  user.putString(c,v);
                }
              }
 else {
                user.putString(c,v);
              }
            break;
case "String_Node_Str":
          JsonArray a=user.getArray(c);
        if (a == null) {
          a=new JsonArray();
          user.putArray(c,a);
        }
      if (("String_Node_Str".equals(c) || "String_Node_Str".equals(c) || "String_Node_Str".equals(c)) && !v.startsWith(structure.getExternalId() + "String_Node_Str")) {
        a.add(structure.getExternalId() + "String_Node_Str" + v);
      }
 else {
        a.add(v);
      }
    break;
case "String_Node_Str":
  user.putBoolean(c,"String_Node_Str".equals(v.toLowerCase()));
break;
default :
Object o=user.getValue(c);
final String v2;
if ("String_Node_Str".equals(c) && !v.startsWith(structure.getExternalId() + "String_Node_Str")) {
v2=structure.getExternalId() + "String_Node_Str" + v;
}
 else {
v2=v;
}
if (o != null) {
if (o instanceof JsonArray) {
((JsonArray)o).add(v2);
}
 else {
JsonArray array=new JsonArray();
array.add(o).add(v2);
user.putArray(c,array);
}
}
 else {
user.putString(c,v2);
}
}
if ("String_Node_Str".equals(c)) {
String eId=structure.getExternalId() + '$' + v;
String[] classId=new String[2];
classId[0]=structure.getExternalId();
classId[1]=eId;
classes.add(classId);
classesNames.addString(v);
}
}
String ca;
long seed;
JsonArray classesA;
Object co=user.getValue("String_Node_Str");
if (co != null && co instanceof JsonArray) {
classesA=(JsonArray)co;
}
 else if (co instanceof String) {
classesA=new JsonArray().add(co);
}
 else {
classesA=null;
}
if ("String_Node_Str".equals(profile) && classesA != null && classesA.size() == 1) {
seed=defaultStudentSeed;
ca=classesA.get(0);
}
 else {
ca=String.valueOf(i);
seed=System.currentTimeMillis();
}
final State state;
final String externalId=user.getString("String_Node_Str");
if (externalId == null || externalId.trim().isEmpty()) {
generateUserExternalId(user,ca,structure,seed);
state=State.NEW;
}
 else {
if (existExternalId.contains(externalId)) {
state=State.UPDATED;
studentExternalIdMapping.put(getHashMapping(user,ca,structure,seed),externalId);
}
 else {
state=State.NEW;
}
}
switch (profile) {
case "String_Node_Str":
JsonArray linkStudents=new JsonArray();
user.putArray("String_Node_Str",linkStudents);
for (String attr : user.getFieldNames()) {
if ("String_Node_Str".equals(attr)) {
Object o=user.getValue(attr);
if (o instanceof JsonArray) {
for (Object c : (JsonArray)o) {
linkStudents.add(c);
}
}
 else {
linkStudents.add(o);
}
}
 else if ("String_Node_Str".equals(attr)) {
Object childUsername=user.getValue(attr);
Object childLastName=user.getValue("String_Node_Str");
Object childFirstName=user.getValue("String_Node_Str");
Object childClasses=user.getValue("String_Node_Str");
if (childUsername instanceof JsonArray && childLastName instanceof JsonArray && childFirstName instanceof JsonArray&& childClasses instanceof JsonArray&& ((JsonArray)childClasses).size() == ((JsonArray)childLastName).size() && ((JsonArray)childFirstName).size() == ((JsonArray)childLastName).size()) {
for (int j=0; j < ((JsonArray)childUsername).size(); j++) {
String mapping=structure.getExternalId() + ((JsonArray)childUsername).<String>get(j).trim() + ((JsonArray)childLastName).<String>get(j).trim()+ ((JsonArray)childFirstName).<String>get(j).trim()+ ((JsonArray)childClasses).<String>get(j).trim()+ defaultStudentSeed;
relativeStudentMapping(linkStudents,mapping);
}
}
 else if (childUsername instanceof String && childLastName instanceof String && childFirstName instanceof String&& childClasses instanceof String) {
String mapping=structure.getExternalId() + childLastName.toString().trim() + childFirstName.toString().trim()+ childClasses.toString().trim()+ defaultStudentSeed;
relativeStudentMapping(linkStudents,mapping);
}
 else {
addError(profile,"String_Node_Str");
handler.handle(result);
return;
}
}
 else if ("String_Node_Str".equals(attr) && !user.getFieldNames().contains("String_Node_Str")) {
Object childLastName=user.getValue(attr);
Object childFirstName=user.getValue("String_Node_Str");
Object childClasses=user.getValue("String_Node_Str");
if (childLastName instanceof JsonArray && childFirstName instanceof JsonArray && childClasses instanceof JsonArray&& ((JsonArray)childClasses).size() == ((JsonArray)childLastName).size() && ((JsonArray)childFirstName).size() == ((JsonArray)childLastName).size()) {
for (int j=0; j < ((JsonArray)childLastName).size(); j++) {
String mapping=structure.getExternalId() + ((JsonArray)childLastName).<String>get(j) + ((JsonArray)childFirstName).<String>get(j)+ ((JsonArray)childClasses).<String>get(j)+ defaultStudentSeed;
relativeStudentMapping(linkStudents,mapping);
}
}
 else if (childLastName instanceof String && childFirstName instanceof String && childClasses instanceof String) {
String mapping=structure.getExternalId() + childLastName.toString().trim() + childFirstName.toString().trim()+ childClasses.toString().trim()+ defaultStudentSeed;
relativeStudentMapping(linkStudents,mapping);
}
 else {
addError(profile,"String_Node_Str");
handler.handle(result);
return;
}
}
}
for (Object o : linkStudents) {
if (!(o instanceof String)) continue;
if (classesNamesMapping.get(o) != null) {
classesNames.addString(classesNamesMapping.get(o));
}
}
break;
}
String error=validator.validate(user,acceptLanguage);
if (error != null) {
log.warn(error);
addError(profile,error);
}
 else {
final String classesStr=Joiner.on("String_Node_Str").join(classesNames);
classesNamesMapping.put(user.getString("String_Node_Str"),classesStr);
addUser(profile,user.putString("String_Node_Str",translate(state.name())).putString("String_Node_Str",translate(profile)).putString("String_Node_Str",classesStr));
}
i++;
}
}
 catch (Exception e) {
addError(profile,"String_Node_Str");
log.error("String_Node_Str",e);
}
handler.handle(result);
}
}
);
}