Bug 482254 - Make the array copy conditional
Change-Id: I7cd866263455668a70df8caca676749837c308a1
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 a1aba22..92a4e2e 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
@@ -1661,6 +1661,32 @@
File fileY = new File(packageDir, "Y.java");
String canonicalPath = fileY.getCanonicalPath();
+ packageDir = new File(rootDir, "p");
+ packageDir.mkdir();
+ fileY = new File(packageDir, "Z.java");
+ String canonicalPath2 = fileY.getCanonicalPath();
+
+ contents =
+ "enum X {\n" +
+ " /** */\n" +
+ " FOO\n" +
+ "}";
+
+ File file2 = new File(rootDir, "X.java");
+ writer = null;
+ try {
+ writer = new BufferedWriter(new FileWriter(file2));
+ writer.write(contents);
+ } finally {
+ if (writer != null) {
+ try {
+ writer.close();
+ } catch(IOException e) {
+ // ignore
+ }
+ }
+ }
+
try {
ASTParser parser = ASTParser.newParser(AST_JLS_LATEST);
parser.setKind(ASTParser.K_COMPILATION_UNIT);
@@ -1668,7 +1694,7 @@
parser.setResolveBindings(true);
parser.setCompilerOptions(JavaCore.getOptions());
parser.createASTs(
- new String[] { file.getCanonicalPath(), canonicalPath },
+ new String[] { file.getCanonicalPath(), canonicalPath, canonicalPath2, file2.getCanonicalPath() },
null,
new String[] {},
new FileASTRequestor() {},
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 8fbe1a3..2fa9187 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
@@ -1005,9 +1005,12 @@
}
sourceUnits[count++] = new org.eclipse.jdt.internal.compiler.batch.CompilationUnit(contents, sourceUnitPath, encoding);
}
- 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);
+ if (count < length) {
+ org.eclipse.jdt.internal.compiler.env.ICompilationUnit[] newArray = new org.eclipse.jdt.internal.compiler.env.ICompilationUnit[count];
+ System.arraycopy(sourceUnits, 0, newArray, 0, count);
+ sourceUnits = newArray;
+ }
+ beginToCompile(sourceUnits, 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)) {