#485 ArrayCopyWrapper local var possibly not safe

This commit is contained in:
sjaakd 2015-03-03 23:30:37 +01:00
parent a381396839
commit 9b888847ea
2 changed files with 11 additions and 3 deletions

View File

@ -170,7 +170,13 @@ public class PropertyMapping extends ModelElement {
}
else if ( targetType.isArrayType() && sourceType.isArrayType() && assignment.getType() == DIRECT ) {
Type arrayType = ctx.getTypeFactory().getType( Arrays.class );
assignment = new ArrayCopyWrapper( assignment, targetPropertyName, arrayType, targetType );
assignment = new ArrayCopyWrapper(
assignment,
targetPropertyName,
arrayType,
targetType,
existingVariableNames
);
assignment = new NullCheckWrapper( assignment );
}
else {

View File

@ -18,11 +18,13 @@
*/
package org.mapstruct.ap.model.assignment;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
import org.mapstruct.ap.model.common.Type;
import org.mapstruct.ap.util.Strings;
import static org.mapstruct.ap.util.Strings.decapitalize;
import static org.mapstruct.ap.util.Strings.getSaveVariableName;
@ -38,9 +40,9 @@ public class ArrayCopyWrapper extends AssignmentWrapper {
private final Type targetType;
public ArrayCopyWrapper(Assignment decoratedAssignment, String targetPropertyName, Type arraysType,
Type targetType) {
Type targetType, Collection<String> existingVariableNames ) {
super( decoratedAssignment );
this.targetPropertyName = targetPropertyName;
this.targetPropertyName = Strings.getSaveVariableName( targetPropertyName, existingVariableNames );
this.arraysType = arraysType;
this.targetType = targetType;
}