Bug fix in TypeReplacementAnalysis occurring when multiple catch blocks use the same name for their exception variables
@@ -30,7 +30,8 @@ public class TypeReplacementAnalysis {
for(VariableDeclaration declaration1 : declarations1) {
for(VariableDeclaration declaration2 : declarations2) {
if(declaration1.getVariableName().equals(declaration2.getVariableName()) &&
- !declaration1.getType().equals(declaration2.getType())) {
+ !declaration1.getType().equals(declaration2.getType()) &&
+ !containsVariableDeclarationWithSameNameAndType(declaration1, declarations2)) {
ChangeVariableTypeRefactoring ref = new ChangeVariableTypeRefactoring(declaration1, declaration2, mapping.getOperation1(), mapping.getOperation2(),
VariableReferenceExtractor.findReferences(declaration1, declaration2, mappings));
changedTypes.add(ref);
@@ -42,4 +43,13 @@ public class TypeReplacementAnalysis {
}
}
}
+
+ private boolean containsVariableDeclarationWithSameNameAndType(VariableDeclaration declaration, List<VariableDeclaration> declarations) {
+ for(VariableDeclaration d : declarations) {
+ if(d.getVariableName().equals(declaration.getVariableName()) && d.getType().equals(declaration.getType())) {
+ return true;
+ }
+ }
+ return false;
+ }
}
