Bug 482254 - java.lang.NullPointerException at
org.eclipse.jdt.internal.compiler.CompilationResult.<init>

Change-Id: I8f272d1daefe38ed378b6e49e7d08c0d44d36dee
Signed-off-by: Jay Arthanareeswaran <jarthana@in.ibm.com>
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/dom/StandAloneASTParserTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/dom/StandAloneASTParserTest.java
index 7cd81bd..a1aba22 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/dom/StandAloneASTParserTest.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/dom/StandAloneASTParserTest.java
@@ -1632,4 +1632,50 @@
 		assertNotNull(type);
 		assertTrue("not a var", type.isVar());
 	}
+	public void testBug482254() throws IOException {
+		File rootDir = new File(System.getProperty("java.io.tmpdir"));
+
+		String contents =
+			"enum X {\n" + 
+			"              /** */\n" + 
+			"    FOO\n" + 
+			"}";
+		
+		File file = new File(rootDir, "X.java");
+		Writer writer = null;
+		try {
+			writer = new BufferedWriter(new FileWriter(file));
+			writer.write(contents);
+		} finally {
+			if (writer != null) {
+				try {
+					writer.close();
+				} catch(IOException e) {
+					// ignore
+				}
+			}
+		}
+
+		File packageDir = new File(rootDir, "p");
+		packageDir.mkdir();
+		File fileY = new File(packageDir, "Y.java");
+		String canonicalPath = fileY.getCanonicalPath();
+
+		try {
+			ASTParser parser = ASTParser.newParser(AST_JLS_LATEST);
+			parser.setKind(ASTParser.K_COMPILATION_UNIT);
+			parser.setEnvironment(null, null, null, true);
+			parser.setResolveBindings(true);
+			parser.setCompilerOptions(JavaCore.getOptions());
+			parser.createASTs(
+					new String[] { file.getCanonicalPath(), canonicalPath },
+					null,
+					new String[] {},
+					new FileASTRequestor() {},
+					null);
+		} finally {
+			file.delete();
+			fileY.delete();
+		}
+	}
 }
\ No newline at end of file
diff --git a/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/CompilationUnitResolver.java b/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/CompilationUnitResolver.java
index 9b6202a..8fbe1a3 100644
--- a/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/CompilationUnitResolver.java
+++ b/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/CompilationUnitResolver.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2000, 2017 IBM Corporation and others.
+ * Copyright (c) 2000, 2018 IBM Corporation and others.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
  * which accompanies this distribution, and is available at
@@ -1005,7 +1005,9 @@
 				}
 				sourceUnits[count++] = new org.eclipse.jdt.internal.compiler.batch.CompilationUnit(contents, sourceUnitPath, encoding);
 			}
-			beginToCompile(sourceUnits, bindingKeys);
+			org.eclipse.jdt.internal.compiler.env.ICompilationUnit[] newArray = new org.eclipse.jdt.internal.compiler.env.ICompilationUnit[count];
+			System.arraycopy(sourceUnits, 0, newArray, 0, count);
+			beginToCompile(newArray, bindingKeys);
 			// process all units (some more could be injected in the loop by the lookup environment)
 			for (int i = 0; i < this.totalUnits; i++) {
 				if (resolvedRequestedSourcesAndKeys(i)) {