Bug 506461 - [9] Full build fails when there multiple source folders in
a Java project
diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/AbstractImageBuilder.java b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/AbstractImageBuilder.java
index c11e270..a4129ab 100644
--- a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/AbstractImageBuilder.java
+++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/AbstractImageBuilder.java
@@ -23,6 +23,7 @@
 import org.eclipse.jdt.internal.compiler.Compiler;
 import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
 import org.eclipse.jdt.internal.compiler.env.ICompilationUnit;
+import org.eclipse.jdt.internal.compiler.env.IModule;
 import org.eclipse.jdt.internal.compiler.env.IModuleLocation;
 import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
 import org.eclipse.jdt.internal.compiler.lookup.TypeConstants;
@@ -62,6 +63,7 @@
 
 protected boolean keepStoringProblemMarkers;
 protected SimpleSet filesWithAnnotations = null;
+IModule module = null;
 
 //2000 is best compromise between space used and speed
 public static int MAX_AT_ONCE = Integer.getInteger(JavaModelManager.MAX_COMPILED_UNITS_AT_ONCE, 2000).intValue();
@@ -214,7 +216,10 @@
 protected void acceptSecondaryType(ClassFile classFile) {
 	// noop
 }
-
+public void acceptModule(IModule mod) {
+	//TODO: If module was already part of another source folder, flag an error?
+	this.module = mod;
+}
 protected void addAllSourceFiles(final ArrayList sourceFiles) throws CoreException {
 	for (int i = 0, l = this.sourceLocations.length; i < l; i++) {
 		final ClasspathMultiDirectory sourceLocation = this.sourceLocations[i];
@@ -236,9 +241,14 @@
 										return false;
 								SourceFile unit = new SourceFile((IFile) resource, sourceLocation);
 								String complianceLevel = AbstractImageBuilder.this.javaBuilder.javaProject.getOption(JavaCore.COMPILER_COMPLIANCE, true);
-								if (CompilerOptions.versionToJdkLevel(complianceLevel) >= ClassFileConstants.JDK9 &&
-										resource.getName().equalsIgnoreCase(IModuleLocation.MODULE_INFO_JAVA)) {
-									sourceLocation.acceptModuleInfo(unit, AbstractImageBuilder.this.compiler.parser);
+								if (AbstractImageBuilder.this.module != null && sourceLocation.getModule() == null) {
+									sourceLocation.resetModule(AbstractImageBuilder.this.module);
+								} else {
+									if (CompilerOptions.versionToJdkLevel(complianceLevel) >= ClassFileConstants.JDK9 &&
+											resource.getName().equalsIgnoreCase(IModuleLocation.MODULE_INFO_JAVA)) {
+										sourceLocation.acceptModuleInfo(unit, AbstractImageBuilder.this.compiler.parser);
+										acceptModule(sourceLocation.getModule());
+									}
 								}
 								sourceFiles.add(unit);
 							}