Bug 522330 - [9] javax.annotation.PostConstruct cannot be resolved with
javax.annotation-api-1.2.jar on the classpath

Change-Id: I143e45755b119e17513960ad75c8f7b895da621e
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ModuleBuilderTests.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ModuleBuilderTests.java
index 8eb4666..fa0519c 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ModuleBuilderTests.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ModuleBuilderTests.java
@@ -5681,6 +5681,43 @@
 			deleteProject("nonmodular2");
 		}
 	}
+	public void testBug522330() throws CoreException, IOException {
+		if (!isJRE9) return;
+		try {
+			String[] sources = new String[] {
+				"src/javax/net/ServerSocketFactory1.java",
+				"package javax.net;\n" +
+				"\n" +
+				"public class ServerSocketFactory1 {\n" +
+				"}\n" +
+				"\n" +
+				"",
+			};
+			IJavaProject p1 = setupModuleProject("nonmodular1", sources);
+			p1.setOption(JavaCore.COMPILER_COMPLIANCE, "1.8"); // compile with 1.8 compliance to avoid error about package conflict
+			
+			IClasspathEntry dep = JavaCore.newProjectEntry(p1.getPath(), null, false,
+				new IClasspathAttribute[] {},
+				false/*not exported*/);
+			String[] src = new String[] {
+				"src/nonmodular2/Problem.java",
+				"package nonmodular2;\n" +
+				"\n" +
+				"import javax.net.ServerSocketFactory;\n" +
+				"\n" +
+				"public class Problem  {\n" +
+				"	Object o = ServerSocketFactory.getDefault();\n" +
+				"} \n" +
+				"",
+			};
+			IJavaProject p2 = setupModuleProject("nonmodular2", src, new IClasspathEntry[] { dep });
+			p2.getProject().getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, null);
+			assertNoErrors();
+		} finally {
+			deleteProject("nonmodular1");
+			deleteProject("nonmodular2");
+		}
+	}
 	protected void assertNoErrors() throws CoreException {
 		for (IProject p : getWorkspace().getRoot().getProjects()) {
 			int maxSeverity = p.findMaxProblemSeverity(null, true, IResource.DEPTH_INFINITE);
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/ModuleBinding.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/ModuleBinding.java
index 39cb8b0..0e595c1 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/ModuleBinding.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/ModuleBinding.java
@@ -531,7 +531,7 @@
 			IModuleAwareNameEnvironment moduleEnv = (IModuleAwareNameEnvironment) this.environment.nameEnvironment;
 			char[][] declaringModuleNames = moduleEnv.getModulesDeclaringPackage(parentName, name, nameForLookup());
 			if (declaringModuleNames != null) {
-				if (CharOperation.containsEqual(declaringModuleNames, this.moduleName)) {
+				if (!this.isUnnamed() && CharOperation.containsEqual(declaringModuleNames, this.moduleName)) {
 					// declared here, not yet known, so create it now:
 					binding = new PackageBinding(subPkgCompoundName, parent, this.environment, this);
 				} else {