HEAD - Fix for 203454
diff --git a/org.eclipse.jdt.apt.pluggable.tests/resources/targets/filer02a/Parent02.java b/org.eclipse.jdt.apt.pluggable.tests/resources/targets/filer02a/Parent02.java
new file mode 100644
index 0000000..15561b0
--- /dev/null
+++ b/org.eclipse.jdt.apt.pluggable.tests/resources/targets/filer02a/Parent02.java
@@ -0,0 +1,26 @@
+/*******************************************************************************
+ * Copyright (c) 2007 BEA Systems, Inc.
+ * 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
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *    wharley@bea.com - initial API and implementation
+ *******************************************************************************/
+
+package targets.filer;
+
+import org.eclipse.jdt.apt.pluggable.tests.annotations.GenClass6;
+
+/**
+ * Processing this class should result in creation of a source file,
+ * thereby allowing this class to compile
+ */
+@GenClass6(name="Generated02", pkg="gen6")
+public class Parent02 {
+	gen6.Generated02 _gen;
+}
+
+
+
diff --git a/org.eclipse.jdt.apt.pluggable.tests/resources/targets/filer02b/Parent02.java b/org.eclipse.jdt.apt.pluggable.tests/resources/targets/filer02b/Parent02.java
new file mode 100644
index 0000000..a469971
--- /dev/null
+++ b/org.eclipse.jdt.apt.pluggable.tests/resources/targets/filer02b/Parent02.java
@@ -0,0 +1,24 @@
+/*******************************************************************************
+ * Copyright (c) 2007 BEA Systems, Inc.
+ * 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
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *    wharley@bea.com - initial API and implementation
+ *******************************************************************************/
+
+package targets.filer;
+
+import org.eclipse.jdt.apt.pluggable.tests.annotations.GenClass6;
+
+/**
+ * Processing this class should result in removal of the previously
+ * generated type and creation of a new one, resulting in a compilation error.
+ */
+@GenClass6(name="XxxGenerated02", pkg="gen6")
+public class Parent02 {
+	gen6.Generated02 _gen;
+}
+
diff --git a/org.eclipse.jdt.apt.pluggable.tests/src/org/eclipse/jdt/apt/pluggable/tests/FilerTests.java b/org.eclipse.jdt.apt.pluggable.tests/src/org/eclipse/jdt/apt/pluggable/tests/FilerTests.java
index 9aa46bb..93a438d 100644
--- a/org.eclipse.jdt.apt.pluggable.tests/src/org/eclipse/jdt/apt/pluggable/tests/FilerTests.java
+++ b/org.eclipse.jdt.apt.pluggable.tests/src/org/eclipse/jdt/apt/pluggable/tests/FilerTests.java
@@ -11,12 +11,21 @@
 
 package org.eclipse.jdt.apt.pluggable.tests;
 
+import java.util.Map;
+
 import junit.framework.Test;
 import junit.framework.TestSuite;
 
+import org.eclipse.core.resources.IMarker;
 import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.jdt.apt.core.internal.util.FactoryContainer;
+import org.eclipse.jdt.apt.core.internal.util.FactoryPath;
+import org.eclipse.jdt.apt.core.internal.util.FactoryContainer.FactoryType;
 import org.eclipse.jdt.apt.core.util.AptConfig;
 import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jdt.core.compiler.CategorizedProblem;
+import org.eclipse.jdt.core.tests.builder.Problem;
 
 /**
  * Basic tests for the Filer interface in the IDE.
@@ -78,4 +87,57 @@
 		expectingNoFile( proj, ".apt_generated/summary.txt" );
 	}
 
+	/**
+	 * Test generation of a source file that is referenced by the parent, using the GenClass6 annotation
+	 * @see javax.annotation.processing.Filer#createSourceFile(CharSequence, javax.lang.model.element.Element...)
+	 */
+	public void testCreateSourceFileWithGenReference() throws Throwable
+	{
+		// Temporary workaround for https://bugs.eclipse.org/bugs/show_bug.cgi?id=201931
+		// Bail out on Linux
+		String osName = System.getProperty("os.name");
+		if (null == osName || !osName.contains("Windows")) {
+			return;
+		}
+
+		IJavaProject jproj = createJavaProject(_projectName);
+		IProject proj = jproj.getProject();
+		IdeTestUtils.copyResources(proj, "targets/filer02a", "src/targets/filer");
+		
+		// Make sure that there are no Java 5 processors on the factory path - see comment below.
+		FactoryPath fp = (FactoryPath) AptConfig.getFactoryPath(jproj);
+		for (Map.Entry<FactoryContainer, FactoryPath.Attributes> entry : fp.getAllContainers().entrySet()) {
+			if (entry.getKey().getType() == FactoryType.PLUGIN) {
+				String id = entry.getKey().getId();
+				if (!Apt6TestsPlugin.PLUGIN_ID.equals(id)) {
+					fp.disablePlugin(id);
+				}
+			}
+		}
+		AptConfig.setFactoryPath(jproj, fp);
+		AptConfig.setEnabled(jproj, true);
+		fullBuild();
+		expectingNoProblems();
+		
+		// Check whether generated sources were generated and compiled
+		expectingFile(proj, ".apt_generated/gen6/Generated02.java");
+		final String[] expectedClasses = { "targets.filer.Parent02", "gen6.Generated02" };
+		expectingUniqueCompiledClasses(expectedClasses);
+		
+		// Modify target file to change name of generated file and incrementally rebuild; 
+		// generated file should be deleted.
+		IdeTestUtils.copyResources(proj, "targets/filer02b", "src/targets/filer");
+		incrementalBuild();
+		
+		IPath parentPath = proj.getFullPath().append("src/targets/filer/Parent02.java");
+		expectingOnlySpecificProblemFor(parentPath, new Problem("Parent02", "gen6.Generated02 cannot be resolved to a type", parentPath, 842, 858, CategorizedProblem.CAT_TYPE, IMarker.SEVERITY_ERROR));
+		
+		// This test only works if there are no Java 5 processors (e.g., apt.tests plugin) in the factory path.
+		// If Java 5 processors are present, then gen6.Generated02 will also be recompiled, before it's deleted.
+		final String[] expectedClasses2 = { "gen6.XxxGenerated02", "targets.filer.Parent02" };
+		expectingUniqueCompiledClasses(expectedClasses2);
+
+		expectingNoFile(proj, ".apt_generated/gen6/Generated02.java");
+	}
+
 }
diff --git a/org.eclipse.jdt.core/buildnotes_jdt-core.html b/org.eclipse.jdt.core/buildnotes_jdt-core.html
index 13ec85f..71b6303 100644
--- a/org.eclipse.jdt.core/buildnotes_jdt-core.html
+++ b/org.eclipse.jdt.core/buildnotes_jdt-core.html
@@ -52,7 +52,9 @@
 </ul>
 
 <h3>Problem Reports Fixed</h3>
-<a href="http://bugs.eclipse.org/bugs/show_bug.cgi?id=203342">203342</a>
+<a href="http://bugs.eclipse.org/bugs/show_bug.cgi?id=203454">203454</a>
+NPE in compiler when processing annotations
+<br><a href="http://bugs.eclipse.org/bugs/show_bug.cgi?id=203342">203342</a>
 AST of a NumberLiteral has wrong source code range
 <br><a href="http://bugs.eclipse.org/bugs/show_bug.cgi?id=203089">203089</a>
 getDefaultOptions misses option
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/Compiler.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/Compiler.java
index 2cb3a2e..5c10a48 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/Compiler.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/Compiler.java
@@ -670,7 +670,7 @@
 				// we reset the compiler in order to restart with the new units
 				internalBeginToCompile(newUnits, newUnitSize);
 				bottom = top;
-				top = this.unitsToProcess.length;
+				top = this.totalUnits; // last unit added
 			} else {
 				bottom = top;
 			}