From 294ac16e81cb4969beaf6fe07ec06c0ed6f8939c Mon Sep 17 00:00:00 2001 From: Marcel Steinbeck Date: Fri, 7 Oct 2016 16:56:59 +0200 Subject: [PATCH] Fixes potential NullPointerException in JDTTreeBuilderQuery. `currentPackage` of CompilationUnitDeclaration may be null if the corresponding source file does not define a package. Thus, `currentPackage.tokens` may throw a NullPointerException. --- .../java/spoon/support/compiler/jdt/JDTTreeBuilderQuery.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/java/spoon/support/compiler/jdt/JDTTreeBuilderQuery.java b/src/main/java/spoon/support/compiler/jdt/JDTTreeBuilderQuery.java index 24d1ccde79d..24d6b83a56c 100644 --- a/src/main/java/spoon/support/compiler/jdt/JDTTreeBuilderQuery.java +++ b/src/main/java/spoon/support/compiler/jdt/JDTTreeBuilderQuery.java @@ -131,6 +131,9 @@ static String searchType(String typeName, ImportReference[] imports) { static ImportReference searchPackage(char[][] packageName, CompilationUnitDeclaration[] unitsToProcess) { for (CompilationUnitDeclaration unit : unitsToProcess) { final ImportReference currentPackage = unit.currentPackage; + if (currentPackage == null) { + continue; + } final char[][] tokens = currentPackage.tokens; if (packageName.length > tokens.length) { continue;