diff --git a/src/main/java/org/refactoringminer/astDiff/matchers/wrappers/FieldDeclarationMatcher.java b/src/main/java/org/refactoringminer/astDiff/matchers/wrappers/FieldDeclarationMatcher.java index 5de0b7639c..17387ee51a 100644 --- a/src/main/java/org/refactoringminer/astDiff/matchers/wrappers/FieldDeclarationMatcher.java +++ b/src/main/java/org/refactoringminer/astDiff/matchers/wrappers/FieldDeclarationMatcher.java @@ -98,10 +98,12 @@ private void processFieldDeclaration(Tree srcTree, Tree dstTree, UMLAttribute sr new JavaDocMatcher(optimizationData, srcUMLAttribute.getJavadoc(), dstUMLAttribute.getJavadoc(), umlJavadocDiff) .match(srcTree, dstTree, mappingStore); if (srcVarDeclaration != null && dstVarDeclaration != null) - mappingStore.addMapping(srcVarDeclaration.getChild(0),dstVarDeclaration.getChild(0)); + if (!srcVarDeclaration.getChildren().isEmpty() && !dstVarDeclaration.getChildren().isEmpty()) + mappingStore.addMapping(srcVarDeclaration.getChild(0),dstVarDeclaration.getChild(0)); } private void matchFieldAllModifiers(Tree srcFieldDeclaration, Tree dstFieldDeclaration, UMLAttribute srcUMLAttribute, UMLAttribute dstUMLAttribute, ExtendedMultiMappingStore mappingStore) { + if (srcFieldDeclaration == null || dstFieldDeclaration == null) return; matchModifiersForField(srcFieldDeclaration,dstFieldDeclaration,srcUMLAttribute.getVisibility().toString(),dstUMLAttribute.getVisibility().toString(),mappingStore); if (srcUMLAttribute.isFinal() && dstUMLAttribute.isFinal()) matchModifierForField(srcFieldDeclaration,dstFieldDeclaration,Constants.FINAL,mappingStore); diff --git a/src/main/java/org/refactoringminer/astDiff/utils/TreeUtilFunctions.java b/src/main/java/org/refactoringminer/astDiff/utils/TreeUtilFunctions.java index bbe33ca14b..28b714615a 100644 --- a/src/main/java/org/refactoringminer/astDiff/utils/TreeUtilFunctions.java +++ b/src/main/java/org/refactoringminer/astDiff/utils/TreeUtilFunctions.java @@ -298,9 +298,10 @@ public static boolean isFromType(Tree t1, String type) { return t1.getType().name.equals(type); } - public static Tree findFirstByType(Tree srcFieldDeclaration, String typeName) { + public static Tree findFirstByType(Tree inputTree, String typeName) { + if (inputTree == null) return null; Tree fieldAnnotation = null; - for (Tree child : srcFieldDeclaration.getChildren()) { + for (Tree child : inputTree.getChildren()) { if (isFromType(child, typeName)) { fieldAnnotation = child; break;