I was debugging my method and it somehow updates my element variable. Even if I don't work with that variable from within the method.
CODE:
private static List<Mapping> createFormFieldsMapping(ArrayList<String> CDOfields,
List<Mapping> fieldMappings, Element element) {
System.out.println(" - Creating field mappings for "+element.name);
for (Mapping fieldMapping : fieldMappings){
if (fieldMapping.targetEntityFieldId!=null){
String formField = getContactFieldNameById(fieldMapping.targetEntityFieldId);
formField = formField.trim();
formField = formField.replaceAll("-", "");
formField = formField.replaceAll("_", "");
formField = formField.replaceAll(" ", "");
formField = formField.toLowerCase();
Boolean matchFound = false;
for (String cdoField : CDOfields){
String[] cdoFieldSplit = cdoField.split(";",-1);
String cdoFieldModified =cdoFieldSplit[1].trim();
cdoFieldModified = cdoFieldModified.replaceAll("-", "");
cdoFieldModified = cdoFieldModified.replaceAll("_", "");
cdoFieldModified = cdoFieldModified.replaceAll(" ", "");
cdoFieldModified = cdoFieldModified.toLowerCase();
if (cdoFieldModified.equals(formField)){
fieldMapping.targetEntityFieldId = cdoFieldSplit[0];
matchFound = true;
break;
}
if (!matchFound){
// WRITE NOT MATCHED FORM FIELD TO A FILE
}
}
}
}
element.processingSteps.targetEntityFieldId is being changed
This is the way I call the method:
List<Mapping> fieldMapping = new ArrayList<Mapping>();
Iterator<ProcessingStep> i = element.processingSteps.iterator();
while (i.hasNext()) {
ProcessingStep step = i.next();
if (step.type.equals("FormStepCreateUpdateContactFromFormField")){
fieldMapping = step.mappings;
step.execute = "never";
//i.remove();
}
}
// Update contact field IDs with CDO field IDs
fieldMapping = createFormFieldsMapping(CDOfields, fieldMapping, element);
Everything I wanted was to kind of copy field mapping, process it by that method and then return back and add it to list of fieldMappings.
The thing is that step.mappings is part of element, but that step.mappings is being put to an ArrayList fieldMapping. By that I would assume that element should never be edited by anything.
elementvariable is exactly the same as it was before - it's a reference to an object. The data within that object has may have changed (it's not clear where it would within the code you've posted), but that's not the same thing.fieldMappings == element.processingSteps? That is to say, that those two declarations point to the same reference?