Bug 538025 - NP checks for SourceTypeConverter.buildCompilationUnit()

Change-Id: I145fc9ec77870d07e33aec7b027db496c85bb5ff
Signed-off-by: Andrey Loskutov <loskutov@gmx.de>
diff --git a/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/CompletionEngine.java b/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/CompletionEngine.java
index 7b3aa9b..3bc9c01 100644
--- a/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/CompletionEngine.java
+++ b/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/CompletionEngine.java
@@ -2451,7 +2451,7 @@
 					// no need for field initialization
 					this.problemReporter,
 					compilationResult);
-				if (compilationUnit.types != null)
+				if (compilationUnit != null && compilationUnit.types != null)
 					typeDeclaration = compilationUnit.types[0];
 			} else {
 				compilationUnit = new CompilationUnitDeclaration(this.problemReporter, compilationResult, 0);
diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/hierarchy/HierarchyResolver.java b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/hierarchy/HierarchyResolver.java
index f8656fc..95fe10d 100644
--- a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/hierarchy/HierarchyResolver.java
+++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/hierarchy/HierarchyResolver.java
@@ -746,7 +746,7 @@
 					// We would have got all the necessary local types by now and hence there is no further need 
 					// to parse the method bodies. Parser.getMethodBodies, which is called latter in this function, 
 					// will not parse the method statements if ASTNode.HasAllMethodBodies is set. 
-					if (containsLocalType) 	parsedUnit.bits |= ASTNode.HasAllMethodBodies;
+					if (containsLocalType && parsedUnit != null) parsedUnit.bits |= ASTNode.HasAllMethodBodies;
 				} else {
 					// create parsed unit from file
 					IFile file = (IFile) cu.getResource();
diff --git a/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/MatchLocator.java b/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/MatchLocator.java
index d9c575f..1a14ea2 100644
--- a/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/MatchLocator.java
+++ b/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/MatchLocator.java
@@ -400,8 +400,10 @@
 				// no need for field initialization
 				this.lookupEnvironment.problemReporter,
 				result);
-		this.lookupEnvironment.buildTypeBindings(unit, accessRestriction);
-		this.lookupEnvironment.completeTypeBindings(unit, true);
+		if(unit != null) {
+			this.lookupEnvironment.buildTypeBindings(unit, accessRestriction);
+			this.lookupEnvironment.completeTypeBindings(unit, true);
+		}
 	}
 }
 protected Parser basicParser() {