1 /*******************************************************************************
2  * Copyright (c) 2016, 2019 IBM Corporation and others.
3  *
4  * This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License 2.0
6  * which accompanies this distribution, and is available at
7  * https://www.eclipse.org/legal/epl-2.0/
8  *
9  * SPDX-License-Identifier: EPL-2.0
10  *
11  * Contributors:
12  *     IBM Corporation - initial API and implementation
13  *******************************************************************************/
14 package org.eclipse.jdt.core.tests.model;
15 
16 import java.io.File;
17 import java.io.IOException;
18 import java.util.Arrays;
19 import java.util.Comparator;
20 import java.util.HashMap;
21 import java.util.Hashtable;
22 import java.util.Map;
23 
24 import org.eclipse.core.resources.IFile;
25 import org.eclipse.core.resources.IFolder;
26 import org.eclipse.core.resources.IMarker;
27 import org.eclipse.core.resources.IProject;
28 import org.eclipse.core.resources.IResource;
29 import org.eclipse.core.resources.IWorkspaceDescription;
30 import org.eclipse.core.resources.IncrementalProjectBuilder;
31 import org.eclipse.core.resources.ResourcesPlugin;
32 import org.eclipse.core.runtime.CoreException;
33 import org.eclipse.core.runtime.IPath;
34 import org.eclipse.core.runtime.Path;
35 import org.eclipse.jdt.core.IAccessRule;
36 import org.eclipse.jdt.core.IClasspathAttribute;
37 import org.eclipse.jdt.core.IClasspathEntry;
38 import org.eclipse.jdt.core.ICompilationUnit;
39 import org.eclipse.jdt.core.IJavaModelMarker;
40 import org.eclipse.jdt.core.IJavaProject;
41 import org.eclipse.jdt.core.IModuleDescription;
42 import org.eclipse.jdt.core.IPackageFragmentRoot;
43 import org.eclipse.jdt.core.IProblemRequestor;
44 import org.eclipse.jdt.core.JavaCore;
45 import org.eclipse.jdt.core.WorkingCopyOwner;
46 import org.eclipse.jdt.core.dom.AST;
47 import org.eclipse.jdt.core.dom.CompilationUnit;
48 import org.eclipse.jdt.core.tests.util.Util;
49 import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
50 import org.eclipse.jdt.internal.compiler.lookup.TypeConstants;
51 import org.eclipse.jdt.internal.core.ClasspathAttribute;
52 import org.eclipse.jdt.internal.core.ClasspathEntry;
53 import org.eclipse.jdt.internal.core.builder.ClasspathJrt;
54 import org.eclipse.jdt.internal.core.util.Messages;
55 
56 import junit.framework.Test;
57 
58 public class ModuleBuilderTests extends ModifyingResourceTests {
ModuleBuilderTests(String name)59 	public ModuleBuilderTests(String name) {
60 		super(name);
61 	}
62 
63 	static {
64 //		 TESTS_NAMES = new String[] { "testReleaseOption8" };
65 	}
66 	private String sourceWorkspacePath = null;
67 	protected ProblemRequestor problemRequestor;
suite()68 	public static Test suite() {
69 		if (!isJRE9) {
70 			// almost empty suite, since we need JRE9+
71 			Suite suite = new Suite(ModuleBuilderTests.class.getName());
72 			suite.addTest(new ModuleBuilderTests("thisSuiteRunsOnJRE9plus"));
73 			return suite;
74 		}
75 		return buildModelTestSuite(ModuleBuilderTests.class, BYTECODE_DECLARATION_ORDER);
76 	}
thisSuiteRunsOnJRE9plus()77 	public void thisSuiteRunsOnJRE9plus() {}
78 
79 	@Override
getSourceWorkspacePath()80 	public String getSourceWorkspacePath() {
81 		return this.sourceWorkspacePath == null ? super.getSourceWorkspacePath() : this.sourceWorkspacePath;
82 	}
83 	@Override
setUp()84 	public void setUp() throws Exception {
85 		super.setUp();
86 		this.problemRequestor =  new ProblemRequestor();
87 		this.wcOwner = new WorkingCopyOwner() {
88 			public IProblemRequestor getProblemRequestor(ICompilationUnit unit) {
89 				return ModuleBuilderTests.this.problemRequestor;
90 			}
91 		};
92 	}
93 	@Override
setUpSuite()94 	public void setUpSuite() throws Exception {
95 		super.setUpSuite();
96 		this.currentProject = createJava9Project("P1");
97 		this.createFile("P1/src/module-info.java", "");
98 		this.createFolder("P1/src/com/greetings");
99 		this.createFile("P1/src/com/greetings/Main.java", "");
100 		waitForManualRefresh();
101 		waitForAutoBuild();
102 	}
103 
104 	@Override
tearDownSuite()105 	public void tearDownSuite() throws Exception {
106 		super.tearDownSuite();
107 		deleteProject("P1");
108 	}
109 
110 	// Test that the java.base found as a module package fragment root in the project
test001()111 	public void test001() throws CoreException {
112 		try {
113 			IJavaProject project = createJava9Project("Test01", new String[]{"src"});
114 			this.createFile("Test01/src/module-info.java", "");
115 			this.createFolder("Test01/src/com/greetings");
116 			this.createFile("Test01/src/com/greetings/Main.java", "");
117 			waitForManualRefresh();
118 			waitForAutoBuild();
119 			project.getProject().build(IncrementalProjectBuilder.FULL_BUILD, null);
120 			IPackageFragmentRoot[] roots = project.getPackageFragmentRoots();
121 			IPackageFragmentRoot base = null;
122 			for (IPackageFragmentRoot iRoot : roots) {
123 				IModuleDescription moduleDescription = iRoot.getModuleDescription();
124 				if (moduleDescription != null && moduleDescription.getElementName().equals("java.base")) {
125 					base = iRoot;
126 					break;
127 				}
128 			}
129 			assertNotNull("Java.base module should not null", base);
130 			assertProblemMarkers("Unexpected markers", "", project.getProject());
131 		} finally {
132 			deleteProject("Test01");
133 		}
134 	}
135 	// Test the project compiles without errors with a simple module-info.java
test002()136 	public void test002() throws CoreException {
137 		try {
138 			this.editFile("P1/src/module-info.java",
139 							"module M1 {\n" +
140 							"	exports com.greetings;\n" +
141 							"	requires java.base;\n" +
142 							"}");
143 			this.createFile("P1/src/com/greetings/Greet.java", "package com.greetings; public class Greet {}\n");
144 			waitForManualRefresh();
145 			this.currentProject.getProject().build(IncrementalProjectBuilder.FULL_BUILD, null);
146 			assertProblemMarkers("Unexpected markers", "", this.currentProject.getProject());
147 		} finally {
148 			deleteFile("P1/src/com/greetings/Greet.java");
149 		}
150 	}
151 	// Test that types from java.base module are seen by the compiler
152 	// even without an explicit 'requires java.base' declaration.
test003()153 	public void test003() throws CoreException {
154 		try {
155 			this.editFile("P1/src/module-info.java",
156 					"module M1 {\n" +
157 							"	exports com.greetings;\n" +
158 					"}");
159 			this.editFile("P1/src/com/greetings/Main.java",
160 					"package com.greetings;\n" +
161 					"public class Main {\n" +
162 					"	public static void main(String[] args) {\n" +
163 					"	}\n" +
164 					"}");
165 			waitForManualRefresh();
166 			this.currentProject.getProject().build(IncrementalProjectBuilder.FULL_BUILD, null);
167 			IMarker[] markers = this.currentProject.getProject().findMarkers(null, true, IResource.DEPTH_INFINITE);
168 			assertMarkers("Unexpected markers", "", markers);
169 		} finally {
170 		}
171 	}
172 	// Test that a type that is present in the JDK, but not observable to the source module,
173 	// is reported as a compilation error.
test004()174 	public void test004() throws CoreException {
175 		try {
176 			this.editFile("P1/src/module-info.java",
177 					"module M1 {\n" +
178 					"	exports com.greetings;\n" +
179 					"	requires java.base;\n" +
180 					"}");
181 			this.editFile("P1/src/com/greetings/Main.java",
182 					"package com.greetings;\n" +
183 					"import java.sql.Connection;\n" +
184 					"public class Main {\n" +
185 					"	public Connection con = null;\n" +
186 					"}");
187 			waitForManualRefresh();
188 			this.currentProject.getProject().build(IncrementalProjectBuilder.FULL_BUILD, null);
189 			IMarker[] markers = this.currentProject.getProject().findMarkers(null, true, IResource.DEPTH_INFINITE);
190 			sortMarkers(markers);
191 			assertMarkers("Unexpected markers",
192 					"The type java.sql.Connection is not accessible\n" +
193 					"Connection cannot be resolved to a type", markers);
194 		} finally {
195 		}
196 	}
197 	// Test that a type that is outside java.base module is available to the compiler
198 	// when the module is specified as 'requires'.
test005()199 	public void test005() throws CoreException {
200 		try {
201 			this.editFile("P1/src/module-info.java",
202 					"module M1 {\n" +
203 					"	exports com.greetings;\n" +
204 					"	requires java.base;\n" +
205 					"	requires java.sql;\n" +
206 					"}");
207 			waitForManualRefresh();
208 			this.currentProject.getProject().build(IncrementalProjectBuilder.FULL_BUILD, null);
209 			IMarker[] markers = this.currentProject.getProject().findMarkers(null, true, IResource.DEPTH_INFINITE);
210 			assertMarkers("Unexpected markers",
211 					// just an API leak warning:
212 					"The type Connection from module java.sql may not be accessible to clients due to missing \'requires transitive\'",
213 					markers);
214 		} finally {
215 		}
216 	}
217 	// Test that a module that doesn't exist but specified as requires in module-info
218 	// doesn't affect rest of the compilation.
_test006()219 	public void _test006() throws CoreException {
220 		try {
221 			this.editFile("P1/src/module-info.java",
222 					"module M1 {\n" +
223 					"	exports com.greetings;\n" +
224 					"	requires java.base;\n" +
225 					"	requires java.sql;\n" +
226 					"	requires java.idontexist;\n" +
227 					"}");
228 			this.editFile("P1/src/com/greetings/Main.java",
229 					"package com.greetings;\n" +
230 					"public class Main {\n" +
231 					"}");
232 			waitForManualRefresh();
233 			this.currentProject.getProject().build(IncrementalProjectBuilder.FULL_BUILD, null);
234 			IMarker[] markers = this.currentProject.getProject().findMarkers(null, true, IResource.DEPTH_INFINITE);
235 			assertMarkers("Unexpected markers", "", markers);
236 		} finally {
237 		}
238 	}
setupP2()239 	private IJavaProject setupP2() throws CoreException {
240 		IJavaProject project = createJava9Project("P2");
241 		IClasspathAttribute modAttr = new ClasspathAttribute("module", "true");
242 		IClasspathEntry projectEntry = JavaCore.newProjectEntry(new Path("/P1"), null, false,
243 			new IClasspathAttribute[] {modAttr},
244 			true);
245 		IClasspathEntry[] old = project.getRawClasspath();
246 		IClasspathEntry[] newPath = new IClasspathEntry[old.length +1];
247 		System.arraycopy(old, 0, newPath, 0, old.length);
248 		newPath[old.length] = projectEntry;
249 		project.setRawClasspath(newPath, null);
250 		this.editFile("P1/src/module-info.java",
251 				"module M1 {\n" +
252 				"	exports com.greetings;\n" +
253 				"	requires java.base;\n" +
254 				"}");
255 		this.editFile("P1/src/com/greetings/Main.java",
256 				"package com.greetings;\n" +
257 				"public class Main {\n" +
258 				"	public static void main(String[] args) {\n" +
259 				"	}\n" +
260 				"}");
261 		this.createFile("P2/src/module-info.java",
262 				"module M2 {\n" +
263 				"	exports org.astro;\n" +
264 				"	requires M1;\n" +
265 				"}");
266 		this.createFolder("P2/src/org/astro");
267 		this.createFile("P2/src/org/astro/Test.java",
268 				"package org.astro;\n" +
269 				"import com.greetings.Main;\n" +
270 				"public class Test {\n" +
271 				"	public static void main(String[] args) {\n" +
272 				"		Main.main(args);\n" +
273 				"	}\n" +
274 				"}");
275 		return project;
276 	}
277 	/*
278 	 * Two Java projects, each with one module. P2 has P1 in its build path but
279 	 * module M2 has no 'requires' M1. Should report unresolved type, import etc.
280 	 *
281 	 */
test007()282 	public void test007() throws Exception {
283 		try {
284 			IJavaProject project = setupP2();
285 			this.editFile("P1/src/module-info.java",
286 					"module M1 {\n" +
287 					"	exports com.greetings;\n" +
288 					"}");
289 			this.editFile("P2/src/module-info.java",
290 					"module M2 {\n" +
291 					"	exports org.astro;\n" +
292 					"	//requires M1;\n" +
293 					"}");
294 			waitForManualRefresh();
295 			project.getProject().getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, null);
296 			IMarker[] markers = project.getProject().findMarkers(null, true, IResource.DEPTH_INFINITE);
297 			sortMarkers(markers);
298 			assertMarkers("Unexpected markers",
299 					"The type com.greetings.Main is not accessible\n" +
300 					"Main cannot be resolved",
301 					markers);
302 		} finally {
303 			deleteProject("P2");
304 		}
305 	}
306 	/*
307 	 * Two Java project, each with one module. P2 has P1 in its build path and
308 	 * module M2 'requires' M1. Should report unresolved type, import etc. But M1
309 	 * does not export the package that is used by M2. Test that M2 does not see
310 	 * the types in unexported packages.
311 	 *
312 	 */
test008()313 	public void test008() throws Exception {
314 		try {
315 			IJavaProject project = setupP2();
316 			this.editFile("P1/src/module-info.java",
317 					"module M1 {\n" +
318 					"	//exports com.greetings;\n" +
319 					"}");
320 			this.editFile("P2/src/module-info.java",
321 					"module M2 {\n" +
322 					"	exports org.astro;\n" +
323 					"	requires M1;\n" +
324 					"}");
325 			waitForManualRefresh();
326 			project.getProject().getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, null);
327 			IMarker[] markers = project.getProject().findMarkers(null, true, IResource.DEPTH_INFINITE);
328 			sortMarkers(markers);
329 			assertMarkers("Unexpected markers",
330 					"The type com.greetings.Main is not accessible\n" +
331 					"Main cannot be resolved",
332 					markers);
333 		} finally {
334 			deleteProject("P2");
335 		}
336 	}
337 	/*
338 	 * Two Java projects, each with one module. P2 has P1 in its build path.
339 	 * Module M2 has "requires M1" in module-info and all packages used by M2
340 	 * are exported by M1. No errors expected.
341 	 */
test009()342 	public void test009() throws Exception {
343 		try {
344 			IJavaProject project = setupP2();
345 			this.editFile("P1/src/module-info.java",
346 					"module M1 {\n" +
347 					"	exports com.greetings;\n" +
348 					"}");
349 			this.editFile("P2/src/module-info.java",
350 					"module M2 {\n" +
351 					"	exports org.astro;\n" +
352 					"	requires M1;\n" +
353 					"}");
354 			waitForManualRefresh();
355 			project.getProject().getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, null);
356 			IMarker[] markers = project.getProject().findMarkers(null, true, IResource.DEPTH_INFINITE);
357 			assertMarkers("Unexpected markers",
358 					"", markers);
359 		} finally {
360 			deleteProject("P2");
361 		}
362 	}
363 	/*
364 	 * Two Java projects, each with a module. Project P2 depends on P1.
365 	 * Module M1 exports a package to a specific module, which is not M2.
366 	 * Usage of types from M1 in M2 should be reported.
367 	 */
_test010()368 	public void _test010() throws Exception {
369 		try {
370 			IJavaProject project = setupP2();
371 			this.editFile("P1/src/module-info.java",
372 					"module M1 {\n" +
373 					"	exports com.greetings to org.main;\n" +
374 					"}");
375 			this.editFile("P2/src/module-info.java",
376 					"module M2 {\n" +
377 					"	exports org.astro;\n" +
378 					"	requires M1;\n" +
379 					"}");
380 			waitForManualRefresh();
381 			project.getProject().getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, null);
382 			IMarker[] markers = project.getProject().findMarkers(null, true, IResource.DEPTH_INFINITE);
383 			sortMarkers(markers);
384 			assertMarkers("Unexpected markers",
385 					"The import com.greetings.Main cannot be resolved\n" +
386 					"Main cannot be resolved",
387 					markers);
388 		} finally {
389 			deleteProject("P2");
390 		}
391 	}
setupP3()392 	private IJavaProject setupP3() throws CoreException {
393 		IJavaProject project = createJava9Project("P3");
394 		IClasspathAttribute modAttr = new ClasspathAttribute("module", "true");
395 		IClasspathEntry projectEntry = JavaCore.newProjectEntry(new Path("/P2"), null, false,
396 			new IClasspathAttribute[] {modAttr},
397 			true);
398 		IClasspathEntry[] old = project.getRawClasspath();
399 		IClasspathEntry[] newPath = new IClasspathEntry[old.length +1];
400 		System.arraycopy(old, 0, newPath, 0, old.length);
401 		newPath[old.length] = projectEntry;
402 		project.setRawClasspath(newPath, null);
403 		this.createFile("P3/src/module-info.java",
404 				"module M3 {\n" +
405 				"	exports org.main;\n" +
406 				"	requires M2;\n" +
407 				"}");
408 		this.createFolder("P3/src/org/main");
409 		this.createFile("P3/src/org/main/TestMain.java",
410 				"package org.main;\n" +
411 				"import com.greetings.*;\n" +
412 				"public class TestMain {\n" +
413 				"	public static void main(String[] args) {\n" +
414 				"		Main.main(args);\n" +
415 				"	}\n" +
416 				"}");
417 		return project;
418 	}
419 	/*
420 	 * Three Java projects, each with one module. Project P3 depends on P2, which depends on P1.
421 	 * Module M1 exports a package (to all), M2 requires M1 and M3 requires M2. Usage of types from
422 	 * M1 in M3 should be reported as errors.
423 	 */
test011()424 	public void test011() throws Exception {
425 		try {
426 			this.editFile("P1/src/module-info.java",
427 					"module M1 {\n" +
428 					"	exports com.greetings;\n" +
429 					"}");
430 			IJavaProject p2 = setupP2();
431 			IJavaProject p3 = setupP3();
432 			waitForManualRefresh();
433 			p2.getProject().getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, null);
434 			IMarker[] markers = p3.getProject().findMarkers(null, true, IResource.DEPTH_INFINITE);
435 			sortMarkers(markers);
436 			assertMarkers("Unexpected markers",
437 					"The package com.greetings is not accessible\n" +
438 					"Main cannot be resolved",
439 					markers);
440 		} finally {
441 			deleteProject("P2");
442 			deleteProject("P3");
443 		}
444 	}
445 	/*
446 	 * Three Java projects, each with one module. Project P3 depends on P2, which depends on P1.
447 	 * Module M1 exports a package only to M2, M2 requires M1 and M3 requires M2. Usage of types from
448 	 * M1 in M3 should not be allowed.
449 	 */
test012()450 	public void test012() throws Exception {
451 		try {
452 			this.editFile("P1/src/module-info.java",
453 					"module M1 {\n" +
454 					"	exports com.greetings to M2;\n" +
455 					"}");
456 			IJavaProject p2 = setupP2();
457 			IJavaProject p3 = setupP3();
458 			this.editFile("P2/src/module-info.java",
459 					"module M2 {\n" +
460 					"	exports org.astro;\n" +
461 					"	requires M1;\n" +
462 					"}");
463 			waitForManualRefresh();
464 			p2.getProject().getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, null);
465 			IMarker[] markers = p2.getProject().findMarkers(null, true, IResource.DEPTH_INFINITE);
466 			assertMarkers("Unexpected markers", "",  markers);
467 			markers = p3.getProject().findMarkers(null, true, IResource.DEPTH_INFINITE);
468 			sortMarkers(markers);
469 			assertMarkers("Unexpected markers",
470 					"The package com.greetings is not accessible\n" +
471 					"Main cannot be resolved",
472 					markers);
473 		} finally {
474 			deleteProject("P2");
475 			deleteProject("P3");
476 		}
477 	}
478 	/*
479 	 * Three Java projects, each with one module. Project P3 depends on P2, which depends on P1.
480 	 * Module M1 exports a package (to all), M2 requires 'transitive' M1 and M3 requires M2. Usage of types from
481 	 * M1 in M3 should be allowed.
482 	 */
test013()483 	public void test013() throws Exception {
484 		try {
485 			IJavaProject p2 = setupP2();
486 			IJavaProject p3 = setupP3();
487 			this.editFile("P2/src/module-info.java",
488 					"module M2 {\n" +
489 					"	exports org.astro;\n" +
490 					"	requires transitive M1;\n" +
491 					"}");
492 			waitForManualRefresh();
493 			p2.getProject().getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, null);
494 			IMarker[] markers = p3.getProject().findMarkers(null, true, IResource.DEPTH_INFINITE);
495 			assertMarkers("Unexpected markers", "",  markers);
496 		} finally {
497 			deleteProject("P2");
498 			deleteProject("P3");
499 		}
500 	}
501 	/*
502 	 * Three Java projects, each with one module. Project P3 depends on P2, which depends on P1.
503 	 * Module M1 exports a package only to M2, M2 requires 'public' M1 and M3 requires M2. Usage of types from
504 	 * M1 in M3 should be allowed. And no errors reported on M2.
505 	 */
test014()506 	public void test014() throws Exception {
507 		try {
508 			this.editFile("P1/src/module-info.java",
509 					"module M1 {\n" +
510 					"	exports com.greetings to M2;\n" +
511 					"}");
512 			IJavaProject p2 = setupP2();
513 			IJavaProject p3 = setupP3();
514 			this.editFile("P2/src/module-info.java",
515 					"module M2 {\n" +
516 					"	exports org.astro;\n" +
517 					"	requires transitive M1;\n" +
518 					"}");
519 			waitForManualRefresh();
520 			p2.getProject().getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, null);
521 			IMarker[] markers = p2.getProject().findMarkers(null, true, IResource.DEPTH_INFINITE);
522 			assertMarkers("Unexpected markers", "",  markers);
523 			markers = p3.getProject().findMarkers(null, true, IResource.DEPTH_INFINITE);
524 			assertMarkers("Unexpected markers", "",  markers);
525 		} finally {
526 			deleteProject("P2");
527 			deleteProject("P3");
528 		}
529 	}
test015()530 	public void test015() throws CoreException, IOException {
531 		try {
532 			this.editFile("P1/src/module-info.java",
533 					"module M1 {\n" +
534 					"	exports com.greetings to M2;\n" +
535 					"}");
536 			IJavaProject p2 = setupP2();
537 			this.editFile("P2/src/module-info.java",
538 					"module M2 {\n" +
539 					"	exports org.astro;\n" +
540 					"	requires transitive M1;\n" +
541 					"}");
542 			waitForManualRefresh();
543 			p2.getProject().getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, null);
544 			IFolder folder = getFolder("P1/src");
545 			assertNotNull("Should be a module", this.currentProject.getModuleDescription());
546 			folder = getFolder("P2/src");
547 			folder = getFolder("P1/bin");
548 			IPath jarPath = p2.getResource().getLocation().append("m0.jar");
549 			org.eclipse.jdt.core.tests.util.Util.zip(new File(folder.getLocation().toOSString()), jarPath.toOSString());
550 			IClasspathEntry[] old = p2.getRawClasspath();
551 			for (int i = 0; i < old.length; i++) {
552 				if (old[i].isExported()) {
553 					old[i] = JavaCore.newLibraryEntry(new Path("/P2/m0.jar"), null, null);
554 					break;
555 				}
556 			}
557 			p2.setRawClasspath(old, null);
558 			p2.getProject().refreshLocal(IResource.DEPTH_INFINITE, null);
559 			p2.getProject().getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, null);
560 			assertNotNull("Should be a module", p2.getModuleDescription());
561 		} finally {
562 			deleteProject("P2");
563 			deleteProject("P3");
564 		}
565 	}
566 	/*
567 	 * Change the module-info and wait for autobuild to
568 	 * report expected errors.
569 	 */
test016()570 	public void test016() throws CoreException, IOException {
571 		try {
572 			IJavaProject p2 = setupP2();
573 			this.editFile("P2/src/module-info.java",
574 					"module M2 {\n" +
575 					"	exports org.astro;\n" +
576 					"	requires java.base;\n" +
577 					"	requires transitive M1;\n" +
578 					"}");
579 			waitForManualRefresh();
580 			p2.getProject().getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, null);
581 			IMarker[] markers = p2.getProject().findMarkers(null, true, IResource.DEPTH_INFINITE);
582 			assertMarkers("Unexpected markers", "",  markers);
583 			this.editFile("P2/src/module-info.java",
584 					"module M2 {\n" +
585 					"	exports org.astro;\n" +
586 					"}");
587 			waitForManualRefresh();
588 			p2.getProject().getWorkspace().build(IncrementalProjectBuilder.AUTO_BUILD, null);
589 			markers = p2.getProject().findMarkers(null, true, IResource.DEPTH_INFINITE);
590 			sortMarkers(markers);
591 			assertMarkers("Unexpected markers",
592 					"The type com.greetings.Main is not accessible\n" +
593 					"Main cannot be resolved",  markers);
594 		} finally {
595 			deleteProject("P2");
596 		}
597 	}
598 	/*
599 	 * Change the module-info of a required module and wait for autobuild to
600 	 * report expected errors.
601 	 */
test017()602 	public void test017() throws CoreException, IOException {
603 		try {
604 			IJavaProject p2 = setupP2();
605 			this.editFile("P2/src/module-info.java",
606 					"module M2 {\n" +
607 					"	exports org.astro;\n" +
608 					"	requires java.base;\n" +
609 					"	requires transitive M1;\n" +
610 					"}");
611 			waitForManualRefresh();
612 			p2.getProject().getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, null);
613 			IMarker[] markers = p2.getProject().findMarkers(null, true, IResource.DEPTH_INFINITE);
614 			assertMarkers("Unexpected markers", "",  markers);
615 			this.editFile("P1/src/module-info.java",
616 					"module M1 {\n" +
617 					"	requires java.base;\n" +
618 					"}");
619 			waitForManualRefresh();
620 			p2.getProject().getWorkspace().build(IncrementalProjectBuilder.AUTO_BUILD, null);
621 			markers = p2.getProject().findMarkers(null, true, IResource.DEPTH_INFINITE);
622 			sortMarkers(markers);
623 			assertMarkers("Unexpected markers",
624 					"The type com.greetings.Main is not accessible\n" +
625 					"Main cannot be resolved",  markers);
626 		} finally {
627 			deleteProject("P2");
628 			this.editFile("P1/src/module-info.java",
629 					"module M1 {\n" +
630 					"	exports com.greetings;\n" +
631 					"	requires java.base;\n" +
632 					"}");
633 		}
634 	}
635 	/*
636 	 * Change the module-info of a required module and wait for autobuild to
637 	 * report expected errors.
638 	 */
test018()639 	public void test018() throws CoreException, IOException {
640 		try {
641 			String wkspEncoding = System.getProperty("file.encoding");
642 			final String encoding = "UTF-8".equals(wkspEncoding) ? "Cp1252" : "UTF-8";
643 			IJavaProject p2 = setupP2();
644 			this.editFile("P2/src/module-info.java",
645 					"module M2 {\n" +
646 					"	exports org.astro;\n" +
647 					"	requires java.base;\n" +
648 					"	requires transitive M1;\n" +
649 					"}");
650 			waitForManualRefresh();
651 			p2.getProject().getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, null);
652 			IMarker[] markers = p2.getProject().findMarkers(null, true, IResource.DEPTH_INFINITE);
653 			assertMarkers("Unexpected markers", "",  markers);
654 			IFile bin = getFile("P1/bin/com/greetings/Main.class");
655 			long old = bin.getLocalTimeStamp();
656 			IFile file = getFile("P1/src/module-info.java");
657 			file.setCharset(encoding, null);
658 			waitForManualRefresh();
659 			p2.getProject().getWorkspace().build(IncrementalProjectBuilder.AUTO_BUILD, null);
660 			markers = p2.getProject().findMarkers(null, true, IResource.DEPTH_INFINITE);
661 			assertMarkers("Unexpected markers",
662 					"",  markers);
663 			long latest = getFile("P1/bin/com/greetings/Main.class").getLocalTimeStamp();
664 			assertTrue("Should not have been recompiled", old == latest);
665 		} finally {
666 			deleteProject("P2");
667 		}
668 	}
669 	/*
670 	 * Test that adding or removing java.base does not result in
671 	 * re-compilation of module.
672 	 */
_test019()673 	public void _test019() throws CoreException, IOException {
674 		try {
675 			this.editFile("P1/src/module-info.java",
676 					"module M1 {\n" +
677 					"	exports com.greetings;\n" +
678 					"	requires java.base;\n" +
679 					"}");
680 			waitForManualRefresh();
681 			this.currentProject.getProject().getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, null);
682 			IMarker[] markers = this.currentProject.getProject().findMarkers(null, true, IResource.DEPTH_INFINITE);
683 			assertMarkers("Unexpected markers", "",  markers);
684 			IFile bin = getFile("P1/bin/com/greetings/Main.class");
685 			long old = bin.getLocalTimeStamp();
686 			waitForManualRefresh();
687 			this.editFile("P1/src/module-info.java",
688 					"module M1 {\n" +
689 					"	exports com.greetings;\n" +
690 					"}");
691 			this.currentProject.getProject().getWorkspace().build(IncrementalProjectBuilder.AUTO_BUILD, null);
692 			long latest = getFile("P1/bin/com/greetings/Main.class").getLocalTimeStamp();
693 			assertTrue("Should not have been recompiled", old == latest);
694 		} finally {
695 			deleteProject("P2");
696 			this.editFile("P1/src/module-info.java",
697 					"module M1 {\n" +
698 					"	exports com.greetings;\n" +
699 					"	requires java.base;\n" +
700 					"}");
701 		}
702 	}
testConvertToModule()703 	public void testConvertToModule() throws CoreException, IOException {
704 		Hashtable<String, String> javaCoreOptions = JavaCore.getOptions();
705 		try {
706 			IJavaProject project = setUpJavaProject("ConvertToModule");
707 			Map<String, String> options = new HashMap<>();
708 			// Make sure the new options map doesn't reset.
709 			options.put(CompilerOptions.OPTION_Compliance, "9");
710 			options.put(CompilerOptions.OPTION_Source, "9");
711 			options.put(CompilerOptions.OPTION_TargetPlatform, "9");
712 			options.put(CompilerOptions.OPTION_Release, "enabled");
713 			project.setOptions(options);
714 			project.getProject().build(IncrementalProjectBuilder.FULL_BUILD, null);
715 			IPackageFragmentRoot[] roots = project.getPackageFragmentRoots();
716 			IPackageFragmentRoot theRoot = null;
717 			for (IPackageFragmentRoot root : roots) {
718 				if (root.getElementName().equals("jdt.test")) {
719 					theRoot = root;
720 					break;
721 				}
722 			}
723 			assertNotNull("should not be null", theRoot);
724 			String[] modules = JavaCore.getReferencedModules(project);
725 			if (isJRE12)
726 				assertStringsEqual("incorrect result", new String[]{"java.desktop", "java.rmi", "java.sql"}, modules);
727 			else if (isJRE11)
728 				assertStringsEqual("incorrect result", new String[]{"java.datatransfer", "java.desktop", "java.net.http", "java.rmi", "java.sql"}, modules);
729 			else if (isJRE10)
730 				assertStringsEqual("incorrect result", new String[]{"java.datatransfer", "java.desktop", "java.rmi", "java.sql"}, modules);
731 			else // 9
732 				assertStringsEqual("incorrect result", new String[]{"java.desktop", "java.rmi", "java.sql"}, modules);
733 		} finally {
734 			this.deleteProject("ConvertToModule");
735 			 JavaCore.setOptions(javaCoreOptions);
736 		}
737 	}
test_services_abstractImpl()738 	public void test_services_abstractImpl() throws CoreException {
739 		try {
740 			String[] sources = new String[] {
741 					"src/module-info.java",
742 					"module org.astro {\n" +
743 					"	exports org.astro;\n" +
744 					"}",
745 					"src/org/astro/World.java",
746 					"package org.astro;\n" +
747 					"public interface World {\n" +
748 					"	public String name();\n" +
749 					"}"
750 			};
751 			IJavaProject p1 = setupModuleProject("org.astro", sources);
752 			IClasspathAttribute modAttr = new ClasspathAttribute("module", "true");
753 			IClasspathEntry dep = JavaCore.newProjectEntry(p1.getPath(), null, false,
754 				new IClasspathAttribute[] {modAttr},
755 				false/*not exported*/);
756 			String[] src = new String[] {
757 					"src/module-info.java",
758 					"module com.greetings {\n" +
759 					"	requires org.astro;\n" +
760 					"	exports com.greetings;\n" +
761 					"	provides org.astro.World with com.greetings.MyWorld;\n" +
762 					"}",
763 					"src/com/greetings/MyWorld.java",
764 					"package com.greetings;\n" +
765 					"import org.astro.World;\n"	+
766 					"public abstract class MyWorld implements World { }\n"
767 			};
768 			IJavaProject p2 = setupModuleProject("com.greetings", src, new IClasspathEntry[] { dep });
769 			p2.getProject().getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, null);
770 			IMarker[] markers = p2.getProject().findMarkers(null, true, IResource.DEPTH_INFINITE);
771 			assertMarkers("Unexpected markers",
772 					"Invalid service implementation, the type com.greetings.MyWorld is abstract", markers);
773 		} finally {
774 			deleteProject("org.astro");
775 			deleteProject("com.greetings");
776 		}
777 	}
test_services_invalidImpl()778 	public void test_services_invalidImpl() throws CoreException {
779 		try {
780 			String[] sources = new String[] {
781 					"src/module-info.java",
782 					"module org.astro {\n" +
783 					"	exports org.astro;\n" +
784 					"}",
785 					"src/org/astro/World.java",
786 					"package org.astro;\n" +
787 					"public interface World {\n" +
788 					"	public String name();\n" +
789 					"}"
790 			};
791 			IJavaProject p1 = setupModuleProject("org.astro", sources);
792 			IClasspathAttribute modAttr = new ClasspathAttribute("module", "true");
793 			IClasspathEntry dep = JavaCore.newProjectEntry(p1.getPath(), null, false,
794 				new IClasspathAttribute[] {modAttr},
795 				false/*not exported*/);
796 			String[] src = new String[] {
797 					"src/module-info.java",
798 					"module com.greetings {\n" +
799 					"	requires org.astro;\n" +
800 					"	exports com.greetings;\n" +
801 					"	provides org.astro.World with com.greetings.MyWorld;\n" +
802 					"}",
803 					"src/com/greetings/MyWorld.java",
804 					"package com.greetings;\n" +
805 					"public class MyWorld { }\n"
806 			};
807 			IJavaProject p2 = setupModuleProject("com.greetings", src, new IClasspathEntry[] { dep });
808 			p2.getProject().getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, null);
809 			IMarker[] markers = p2.getProject().findMarkers(null, true, IResource.DEPTH_INFINITE);
810 			assertMarkers("Unexpected markers",
811 					"Type mismatch: cannot convert from MyWorld to World", markers);
812 		} finally {
813 			deleteProject("org.astro");
814 			deleteProject("com.greetings");
815 		}
816 	}
test_services_NoDefaultConstructor()817 	public void test_services_NoDefaultConstructor() throws CoreException {
818 		try {
819 			String[] sources = new String[] {
820 				"src/module-info.java",
821 				"module org.astro {\n" +
822 				"	exports org.astro;\n" +
823 				"}",
824 				"src/org/astro/World.java",
825 				"package org.astro;\n" +
826 				"public interface World {\n" +
827 				"	public String name();\n" +
828 				"}"
829 			};
830 			IJavaProject p1 = setupModuleProject("org.astro", sources);
831 			IClasspathAttribute modAttr = new ClasspathAttribute("module", "true");
832 			IClasspathEntry dep = JavaCore.newProjectEntry(p1.getPath(), null, false,
833 				new IClasspathAttribute[] {modAttr},
834 				false/*not exported*/);
835 			String[] src = new String[] {
836 				"src/module-info.java",
837 				"module com.greetings {\n" +
838 				"	requires org.astro;\n" +
839 				"	exports com.greetings;\n" +
840 				"	provides org.astro.World with com.greetings.MyWorld;\n" +
841 				"}",
842 				"src/com/greetings/MyWorld.java",
843 				"package com.greetings;\n" +
844 				"import org.astro.World;\n" +
845 				"public class MyWorld implements World {\n" +
846 				"	public MyWorld(String name) { }\n" +
847 				"	public String name() {\n" +
848 				"		return \" My World!!\";\n" +
849 				"	}\n" +
850 				"}"
851 			};
852 			IJavaProject p2 = setupModuleProject("com.greetings", src, new IClasspathEntry[] { dep });
853 			p2.getProject().getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, null);
854 			IMarker[] markers = p2.getProject().findMarkers(null, true, IResource.DEPTH_INFINITE);
855 			assertMarkers("Unexpected markers",
856 					"The service implementation com.greetings.MyWorld must define a public static provider method or a no-arg constructor",  markers);
857 		} finally {
858 			deleteProject("org.astro");
859 			deleteProject("com.greetings");
860 		}
861 	}
test_services_DefaultConstructorNotVisible()862 	public void test_services_DefaultConstructorNotVisible() throws CoreException {
863 		try {
864 			String[] sources = new String[] {
865 				"src/module-info.java",
866 				"module org.astro {\n" +
867 				"	exports org.astro;\n" +
868 				"}",
869 				"src/org/astro/World.java",
870 				"package org.astro;\n" +
871 				"public interface World {\n" +
872 				"	public String name();\n" +
873 				"}"
874 			};
875 			IJavaProject p1 = setupModuleProject("org.astro", sources);
876 			IClasspathAttribute modAttr = new ClasspathAttribute("module", "true");
877 			IClasspathEntry dep = JavaCore.newProjectEntry(p1.getPath(), null, false,
878 				new IClasspathAttribute[] {modAttr},
879 				false/*not exported*/);
880 			String[] src = new String[] {
881 				"src/module-info.java",
882 				"module com.greetings {\n" +
883 				"	requires org.astro;\n" +
884 				"	exports com.greetings;\n" +
885 				"	provides org.astro.World with com.greetings.MyWorld;\n" +
886 				"}",
887 				"src/com/greetings/MyWorld.java",
888 				"package com.greetings;\n" +
889 				"import org.astro.World;\n" +
890 				"public class MyWorld implements World {\n" +
891 				"	MyWorld() { }\n" +
892 				"	public String name() {\n" +
893 				"		return \" My World!!\";\n" +
894 				"	}\n" +
895 				"}"
896 			};
897 			IJavaProject p2 = setupModuleProject("com.greetings", src, new IClasspathEntry[] { dep });
898 			p2.getProject().getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, null);
899 			IMarker[] markers = p2.getProject().findMarkers(null, true, IResource.DEPTH_INFINITE);
900 			assertMarkers("Unexpected markers",
901 					"The no-arg constructor of service implementation com.greetings.MyWorld is not public",  markers);
902 		} finally {
903 			deleteProject("org.astro");
904 			deleteProject("com.greetings");
905 		}
906 	}
test_services_DuplicateEntries()907 	public void test_services_DuplicateEntries() throws CoreException {
908 		try {
909 			String[] sources = new String[] {
910 				"src/module-info.java",
911 				"module org.astro {\n" +
912 				"	exports org.astro;\n" +
913 				"}",
914 				"src/org/astro/World.java",
915 				"package org.astro;\n" +
916 				"public interface World {\n" +
917 				"	public String name();\n" +
918 				"}"
919 			};
920 			IJavaProject p1 = setupModuleProject("org.astro", sources);
921 			IClasspathAttribute modAttr = new ClasspathAttribute("module", "true");
922 			IClasspathEntry dep = JavaCore.newProjectEntry(p1.getPath(), null, false,
923 				new IClasspathAttribute[] {modAttr},
924 				false/*not exported*/);
925 			String[] src = new String[] {
926 				"src/module-info.java",
927 				"module com.greetings {\n" +
928 				"	requires org.astro;\n" +
929 				"	exports com.greetings;\n" +
930 				"	provides org.astro.World with com.greetings.MyWorld;\n" +
931 				"	provides org.astro.World with com.greetings.MyWorld;\n" +
932 				"}",
933 				"src/com/greetings/MyWorld.java",
934 				"package com.greetings;\n" +
935 				"import org.astro.World;\n" +
936 				"public class MyWorld implements World {\n" +
937 				"	public String name() {\n" +
938 				"		return \" My World!!\";\n" +
939 				"	}\n" +
940 				"}"
941 			};
942 			IJavaProject p2 = setupModuleProject("com.greetings", src, new IClasspathEntry[] { dep });
943 			p2.getProject().getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, null);
944 			IMarker[] markers = p2.getProject().findMarkers(null, true, IResource.DEPTH_INFINITE);
945 			assertMarkers("Unexpected markers",
946 					"Duplicate service entry: org.astro.World",  markers);
947 		} finally {
948 			deleteProject("org.astro");
949 			deleteProject("com.greetings");
950 		}
951 	}
test_services_NestedClass()952 	public void test_services_NestedClass() throws CoreException {
953 		try {
954 			String[] sources = new String[] {
955 				"src/module-info.java",
956 				"module org.astro {\n" +
957 				"	exports org.astro;\n" +
958 				"}",
959 				"src/org/astro/World.java",
960 				"package org.astro;\n" +
961 				"public interface World {\n" +
962 				"	public String name();\n" +
963 				"}"
964 			};
965 			IJavaProject p1 = setupModuleProject("org.astro", sources);
966 			IClasspathAttribute modAttr = new ClasspathAttribute("module", "true");
967 			IClasspathEntry dep = JavaCore.newProjectEntry(p1.getPath(), null, false,
968 				new IClasspathAttribute[] {modAttr},
969 				false/*not exported*/);
970 			String[] src = new String[] {
971 				"src/module-info.java",
972 				"module com.greetings {\n" +
973 				"	requires org.astro;\n" +
974 				"	exports com.greetings;\n" +
975 				"	provides org.astro.World with com.greetings.MyWorld.Nested;\n" +
976 				"}",
977 				"src/com/greetings/MyWorld.java",
978 				"package com.greetings;\n" +
979 				"import org.astro.World;\n" +
980 				"public class MyWorld {\n" +
981 				"	public static class Nested implements World {\n" +
982 				"		public String name() {\n" +
983 				"			return \" My World!!\";\n" +
984 				"		}\n" +
985 				"	}\n" +
986 				"}"
987 			};
988 			IJavaProject p2 = setupModuleProject("com.greetings", src, new IClasspathEntry[] { dep });
989 			p2.getProject().getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, null);
990 			IMarker[] markers = p2.getProject().findMarkers(null, true, IResource.DEPTH_INFINITE);
991 			assertMarkers("Unexpected markers",	"",  markers);
992 		} finally {
993 			deleteProject("org.astro");
994 			deleteProject("com.greetings");
995 		}
996 	}
test_services_NonStatic_NestedClass()997 	public void test_services_NonStatic_NestedClass() throws CoreException {
998 		try {
999 			String[] sources = new String[] {
1000 				"src/module-info.java",
1001 				"module org.astro {\n" +
1002 				"	exports org.astro;\n" +
1003 				"}",
1004 				"src/org/astro/World.java",
1005 				"package org.astro;\n" +
1006 				"public interface World {\n" +
1007 				"	public String name();\n" +
1008 				"}"
1009 			};
1010 			IJavaProject p1 = setupModuleProject("org.astro", sources);
1011 			IClasspathAttribute modAttr = new ClasspathAttribute("module", "true");
1012 			IClasspathEntry dep = JavaCore.newProjectEntry(p1.getPath(), null, false,
1013 				new IClasspathAttribute[] {modAttr},
1014 				false/*not exported*/);
1015 			String[] src = new String[] {
1016 				"src/module-info.java",
1017 				"module com.greetings {\n" +
1018 				"	requires org.astro;\n" +
1019 				"	exports com.greetings;\n" +
1020 				"	provides org.astro.World with com.greetings.MyWorld.Nested;\n" +
1021 				"}",
1022 				"src/com/greetings/MyWorld.java",
1023 				"package com.greetings;\n" +
1024 				"import org.astro.World;\n" +
1025 				"public class MyWorld {\n" +
1026 				"	public class Nested implements World {\n" +
1027 				"		public String name() {\n" +
1028 				"			return \" My World!!\";\n" +
1029 				"		}\n" +
1030 				"	}\n" +
1031 				"}"
1032 			};
1033 			IJavaProject p2 = setupModuleProject("com.greetings", src, new IClasspathEntry[] { dep });
1034 			p2.getProject().getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, null);
1035 			IMarker[] markers = p2.getProject().findMarkers(null, true, IResource.DEPTH_INFINITE);
1036 			assertMarkers("Unexpected markers",
1037 					"Invalid service implementation, the type com.greetings.MyWorld.Nested is an inner class",  markers);
1038 		} finally {
1039 			deleteProject("org.astro");
1040 			deleteProject("com.greetings");
1041 		}
1042 	}
test_services_ImplDefinedInAnotherModule()1043 	public void test_services_ImplDefinedInAnotherModule() throws CoreException {
1044 		try {
1045 			String[] sources = new String[] {
1046 				"src/module-info.java",
1047 				"module org.astro {\n" +
1048 				"	exports org.astro;\n" +
1049 				"}",
1050 				"src/org/astro/World.java",
1051 				"package org.astro;\n" +
1052 				"public interface World {\n" +
1053 				"	public String name();\n" +
1054 				"}",
1055 				"src/org/astro/AstroWorld.java",
1056 				"package org.astro;\n" +
1057 				"public class AstroWorld implements World{\n" +
1058 				"}"
1059 			};
1060 			IJavaProject p1 = setupModuleProject("org.astro", sources);
1061 			IClasspathAttribute modAttr = new ClasspathAttribute("module", "true");
1062 			IClasspathEntry dep = JavaCore.newProjectEntry(p1.getPath(), null, false,
1063 				new IClasspathAttribute[] {modAttr},
1064 				false/*not exported*/);
1065 			String[] src = new String[] {
1066 				"src/module-info.java",
1067 				"module com.greetings {\n" +
1068 				"	requires org.astro;\n" +
1069 				"	provides org.astro.World with org.astro.AstroWorld;\n" +
1070 				"}"
1071 			};
1072 			IJavaProject p2 = setupModuleProject("com.greetings", src, new IClasspathEntry[] { dep });
1073 			p2.getProject().getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, null);
1074 			IMarker[] markers = p2.getProject().findMarkers(null, true, IResource.DEPTH_INFINITE);
1075 			assertMarkers("Unexpected markers",
1076 					"Service implementation org.astro.AstroWorld is not defined in the module with the provides directive",  markers);
1077 		} finally {
1078 			deleteProject("org.astro");
1079 			deleteProject("com.greetings");
1080 		}
1081 	}
test_services_ProviderMethod()1082 	public void test_services_ProviderMethod() throws CoreException {
1083 		try {
1084 			String[] sources = new String[] {
1085 				"src/module-info.java",
1086 				"module org.astro {\n" +
1087 				"	exports org.astro;\n" +
1088 				"}",
1089 				"src/org/astro/World.java",
1090 				"package org.astro;\n" +
1091 				"public interface World {\n" +
1092 				"	public String name();\n" +
1093 				"}"
1094 			};
1095 			IJavaProject p1 = setupModuleProject("org.astro", sources);
1096 			IClasspathAttribute modAttr = new ClasspathAttribute("module", "true");
1097 			IClasspathEntry dep = JavaCore.newProjectEntry(p1.getPath(), null, false,
1098 				new IClasspathAttribute[] {modAttr},
1099 				false/*not exported*/);
1100 			String[] src = new String[] {
1101 				"src/module-info.java",
1102 				"module com.greetings {\n" +
1103 				"	requires org.astro;\n" +
1104 				"	exports com.greetings;\n" +
1105 				"	provides org.astro.World with com.greetings.MyImpl;\n" +
1106 				"}",
1107 				"src/com/greetings/MyImpl.java",
1108 				"package com.greetings;\n" +
1109 				"public class MyImpl {\n" +
1110 				"	public static MyWorld provider() {\n" +
1111 				"		return new MyWorld(\"Name\");\n" +
1112 				"	}\n" +
1113 				"}",
1114 				"src/com/greetings/MyWorld.java",
1115 				"package com.greetings;\n" +
1116 				"import org.astro.World;\n" +
1117 				"public class MyWorld implements World {\n" +
1118 				"	public MyWorld(String name) { }\n" +
1119 				"	public String name() {\n" +
1120 				"		return \" My World!!\";\n" +
1121 				"	}\n" +
1122 				"}"
1123 			};
1124 			IJavaProject p2 = setupModuleProject("com.greetings", src, new IClasspathEntry[] { dep });
1125 			p2.getProject().getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, null);
1126 			IMarker[] markers = p2.getProject().findMarkers(null, true, IResource.DEPTH_INFINITE);
1127 			assertMarkers("Unexpected markers",	"",  markers);
1128 		} finally {
1129 			deleteProject("org.astro");
1130 			deleteProject("com.greetings");
1131 		}
1132 	}
test_services_ProviderMethod_ReturnTypeFromAnotherModule()1133 	public void test_services_ProviderMethod_ReturnTypeFromAnotherModule() throws CoreException {
1134 		try {
1135 			String[] sources = new String[] {
1136 				"src/module-info.java",
1137 				"module org.astro {\n" +
1138 				"	exports org.astro;\n" +
1139 				"}",
1140 				"src/org/astro/World.java",
1141 				"package org.astro;\n" +
1142 				"public interface World {\n" +
1143 				"	public String name();\n" +
1144 				"}"
1145 			};
1146 			setupModuleProject("org.astro", sources, true);
1147 			sources = new String[] {
1148 				"src/module-info.java",
1149 				"module other.mod {\n" +
1150 				"	requires org.astro;\n" +
1151 				"	exports org.impl;\n" +
1152 				"}",
1153 				"src/org/impl/MyWorld.java",
1154 				"package org.impl;\n" +
1155 				"import org.astro.World;\n" +
1156 				"public class MyWorld implements World {\n" +
1157 				"	public String name() {\n" +
1158 				"		return \" My World!!\";\n" +
1159 				"	}\n" +
1160 				"}"
1161 			};
1162 			setupModuleProject("other.mod", sources, true);
1163 			String[] src = new String[] {
1164 				"src/module-info.java",
1165 				"module com.greetings {\n" +
1166 				"	requires org.astro;\n" +
1167 				"	requires transitive other.mod;\n" +
1168 				"	exports com.greetings;\n" +
1169 				"	provides org.astro.World with com.greetings.MyImpl;\n" +
1170 				"}",
1171 				"src/com/greetings/MyImpl.java",
1172 				"package com.greetings;\n" +
1173 				"import org.impl.MyWorld;\n" +
1174 				"public class MyImpl {\n" +
1175 				"	public static MyWorld provider() {\n" +
1176 				"		return new MyWorld();\n" +
1177 				"	}\n" +
1178 				"}"
1179 			};
1180 			IJavaProject p3 = setupModuleProject("com.greetings", src, true);
1181 			p3.getProject().getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, null);
1182 			IMarker[] markers = p3.getProject().findMarkers(null, true, IResource.DEPTH_INFINITE);
1183 			assertMarkers("Unexpected markers",	"",  markers);
1184 		} finally {
1185 			deleteProject("org.astro");
1186 			deleteProject("other.mod");
1187 			deleteProject("com.greetings");
1188 		}
1189 	}
test_services_ProviderMethod_ReturnTypeInvisible()1190 	public void test_services_ProviderMethod_ReturnTypeInvisible() throws CoreException {
1191 		try {
1192 			String[] sources = new String[] {
1193 				"src/module-info.java",
1194 				"module org.astro {\n" +
1195 				"	exports org.astro;\n" +
1196 				"}",
1197 				"src/org/astro/World.java",
1198 				"package org.astro;\n" +
1199 				"public interface World {\n" +
1200 				"	public String name();\n" +
1201 				"}"
1202 			};
1203 			setupModuleProject("org.astro", sources, true);
1204 			sources = new String[] {
1205 				"src/module-info.java",
1206 				"module other.mod {\n" +
1207 				"	requires org.astro;\n" +
1208 				"}",
1209 				"src/org/impl/MyWorld.java",
1210 				"package org.impl;\n" +
1211 				"import org.astro.World;\n" +
1212 				"public class MyWorld implements World {\n" +
1213 				"	public String name() {\n" +
1214 				"		return \" My World!!\";\n" +
1215 				"	}\n" +
1216 				"}"
1217 			};
1218 			setupModuleProject("other.mod", sources, true);
1219 			String[] src = new String[] {
1220 				"src/module-info.java",
1221 				"module com.greetings {\n" +
1222 				"	requires org.astro;\n" +
1223 				"	requires other.mod;\n" +
1224 				"	exports com.greetings;\n" +
1225 				"	provides org.astro.World with com.greetings.MyImpl;\n" +
1226 				"}",
1227 				"src/com/greetings/MyImpl.java",
1228 				"package com.greetings;\n" +
1229 				"import org.impl.MyWorld;\n" +
1230 				"public class MyImpl {\n" +
1231 				"	public static MyWorld provider() {\n" +
1232 				"		return new MyWorld();\n" +
1233 				"	}\n" +
1234 				"}"
1235 			};
1236 			IJavaProject p3 = setupModuleProject("com.greetings", src, true);
1237 			p3.getProject().getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, null);
1238 			IMarker[] markers = p3.getProject().getFile(new Path("src/module-info.java")).findMarkers(null, true, IResource.DEPTH_INFINITE);
1239 			assertMarkers("Unexpected markers",	"MyWorld cannot be resolved to a type",  markers);
1240 		} finally {
1241 			deleteProject("org.astro");
1242 			deleteProject("other.mod");
1243 			deleteProject("com.greetings");
1244 		}
1245 	}
test_services_ProviderMethod_InvalidReturnType()1246 	public void test_services_ProviderMethod_InvalidReturnType() throws CoreException {
1247 		try {
1248 			String[] sources = new String[] {
1249 				"src/module-info.java",
1250 				"module org.astro {\n" +
1251 				"	exports org.astro;\n" +
1252 				"}",
1253 				"src/org/astro/World.java",
1254 				"package org.astro;\n" +
1255 				"public interface World {\n" +
1256 				"	public String name();\n" +
1257 				"}"
1258 			};
1259 			IJavaProject p1 = setupModuleProject("org.astro", sources);
1260 			IClasspathAttribute modAttr = new ClasspathAttribute("module", "true");
1261 			IClasspathEntry dep = JavaCore.newProjectEntry(p1.getPath(), null, false,
1262 				new IClasspathAttribute[] {modAttr},
1263 				false/*not exported*/);
1264 			String[] src = new String[] {
1265 				"src/module-info.java",
1266 				"module com.greetings {\n" +
1267 				"	requires org.astro;\n" +
1268 				"	exports com.greetings;\n" +
1269 				"	provides org.astro.World with com.greetings.MyImpl;\n" +
1270 				"}",
1271 				"src/com/greetings/MyImpl.java",
1272 				"package com.greetings;\n" +
1273 				"public class MyImpl {\n" +
1274 				"	public static MyWorld provider() {\n" +
1275 				"		return new MyWorld(\"Name\");\n" +
1276 				"	}\n" +
1277 				"}",
1278 				"src/com/greetings/MyWorld.java",
1279 				"package com.greetings;\n" +
1280 				"public class MyWorld {\n" +
1281 				"	public MyWorld(String name) { }\n" +
1282 				"	public String name() {\n" +
1283 				"		return \" My World!!\";\n" +
1284 				"	}\n" +
1285 				"}"
1286 			};
1287 			IJavaProject p2 = setupModuleProject("com.greetings", src, new IClasspathEntry[] { dep });
1288 			p2.getProject().getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, null);
1289 			IMarker[] markers = p2.getProject().findMarkers(null, true, IResource.DEPTH_INFINITE);
1290 			assertMarkers("Unexpected markers",	"Type mismatch: cannot convert from MyWorld to World",  markers);
1291 		} finally {
1292 			deleteProject("org.astro");
1293 			deleteProject("com.greetings");
1294 		}
1295 	}
test_services_DuplicateImplEntries()1296 	public void test_services_DuplicateImplEntries() throws CoreException {
1297 		try {
1298 			String[] sources = new String[] {
1299 				"src/module-info.java",
1300 				"module org.astro {\n" +
1301 				"	exports org.astro;\n" +
1302 				"}",
1303 				"src/org/astro/World.java",
1304 				"package org.astro;\n" +
1305 				"public interface World {\n" +
1306 				"	public String name();\n" +
1307 				"}"
1308 			};
1309 			IJavaProject p1 = setupModuleProject("org.astro", sources);
1310 			IClasspathAttribute modAttr = new ClasspathAttribute("module", "true");
1311 			IClasspathEntry dep = JavaCore.newProjectEntry(p1.getPath(), null, false,
1312 				new IClasspathAttribute[] {modAttr},
1313 				false/*not exported*/);
1314 			String[] src = new String[] {
1315 				"src/module-info.java",
1316 				"module com.greetings {\n" +
1317 				"	requires org.astro;\n" +
1318 				"	exports com.greetings;\n" +
1319 				"	provides org.astro.World with com.greetings.MyWorld, com.greetings.MyWorld;\n" +
1320 				"}",
1321 				"src/com/greetings/MyWorld.java",
1322 				"package com.greetings;\n" +
1323 				"import org.astro.World;\n" +
1324 				"public class MyWorld implements World {\n" +
1325 				"	public String name() {\n" +
1326 				"		return \" My World!!\";\n" +
1327 				"	}\n" +
1328 				"}"
1329 			};
1330 			IJavaProject p2 = setupModuleProject("com.greetings", src, new IClasspathEntry[] { dep });
1331 			p2.getProject().getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, null);
1332 			IMarker[] markers = p2.getProject().findMarkers(null, true, IResource.DEPTH_INFINITE);
1333 			assertMarkers("Unexpected markers",
1334 					"Duplicate service entry: com.greetings.MyWorld",  markers);
1335 		} finally {
1336 			deleteProject("org.astro");
1337 			deleteProject("com.greetings");
1338 		}
1339 	}
test_services_InvalidIntfType()1340 	public void test_services_InvalidIntfType() throws CoreException {
1341 		try {
1342 			String[] src = new String[] {
1343 				"src/module-info.java",
1344 				"module com.greetings {\n" +
1345 				"	exports com.greetings;\n" +
1346 				"	provides com.greetings.MyEnum with com.greetings.MyEnum;\n" +
1347 				"}",
1348 				"src/com/greetings/MyEnum.java",
1349 				"package com.greetings;\n" +
1350 				"public enum MyEnum {}"
1351 			};
1352 			IJavaProject p2 = setupModuleProject("com.greetings", src);
1353 			p2.getProject().getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, null);
1354 			IMarker[] markers = p2.getProject().findMarkers(null, true, IResource.DEPTH_INFINITE);
1355 			sortMarkers(markers);
1356 			assertMarkers("Unexpected markers",
1357 					"Invalid service interface com.greetings.MyEnum, must be a class, interface or annotation type\n" +
1358 					"Invalid service implementation com.greetings.MyEnum, must be a public class or interface type",  markers);
1359 		} finally {
1360 			deleteProject("com.greetings");
1361 		}
1362 	}
test_services_InvalidImplType()1363 	public void test_services_InvalidImplType() throws CoreException {
1364 		try {
1365 			String[] sources = new String[] {
1366 				"src/module-info.java",
1367 				"module org.astro {\n" +
1368 				"	exports org.astro;\n" +
1369 				"}",
1370 				"src/org/astro/World.java",
1371 				"package org.astro;\n" +
1372 				"public interface World {\n" +
1373 				"	public String name();\n" +
1374 				"}"
1375 			};
1376 			IJavaProject p1 = setupModuleProject("org.astro", sources);
1377 			IClasspathAttribute modAttr = new ClasspathAttribute("module", "true");
1378 			IClasspathEntry dep = JavaCore.newProjectEntry(p1.getPath(), null, false,
1379 				new IClasspathAttribute[] {modAttr},
1380 				false/*not exported*/);
1381 			String[] src = new String[] {
1382 				"src/module-info.java",
1383 				"module com.greetings {\n" +
1384 				"	requires org.astro;\n" +
1385 				"	exports com.greetings;\n" +
1386 				"	provides org.astro.World with com.greetings.MyEnum;\n" +
1387 				"}",
1388 				"src/com/greetings/MyEnum.java",
1389 				"package com.greetings;\n" +
1390 				"public enum MyEnum implements org.astro.World {}"
1391 			};
1392 			IJavaProject p2 = setupModuleProject("com.greetings", src, new IClasspathEntry[] { dep });
1393 			p2.getProject().getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, null);
1394 			IMarker[] markers = p2.getProject().findMarkers(null, true, IResource.DEPTH_INFINITE);
1395 			assertMarkers("Unexpected markers",
1396 					"Invalid service implementation com.greetings.MyEnum, must be a public class or interface type",  markers);
1397 		} finally {
1398 			deleteProject("org.astro");
1399 			deleteProject("com.greetings");
1400 		}
1401 	}
test_services_nonPublicImpl()1402 	public void test_services_nonPublicImpl() throws CoreException {
1403 		try {
1404 			String[] sources = new String[] {
1405 				"src/module-info.java",
1406 				"module org.astro {\n" +
1407 				"	exports org.astro;\n" +
1408 				"}",
1409 				"src/org/astro/World.java",
1410 				"package org.astro;\n" +
1411 				"public interface World {\n" +
1412 				"	public String name();\n" +
1413 				"}"
1414 			};
1415 			IJavaProject p1 = setupModuleProject("org.astro", sources);
1416 			IClasspathAttribute modAttr = new ClasspathAttribute("module", "true");
1417 			IClasspathEntry dep = JavaCore.newProjectEntry(p1.getPath(), null, false,
1418 				new IClasspathAttribute[] {modAttr},
1419 				false/*not exported*/);
1420 			String[] src = new String[] {
1421 				"src/module-info.java",
1422 				"module com.greetings {\n" +
1423 				"	requires org.astro;\n" +
1424 				"	exports com.greetings;\n" +
1425 				"	provides org.astro.World with com.greetings.MyWorld;\n" +
1426 				"}",
1427 				"src/com/greetings/MyWorld.java",
1428 				"package com.greetings;\n" +
1429 				"import org.astro.World;\n" +
1430 				"class MyWorld implements World {\n" +
1431 				"	public String name() {\n" +
1432 				"		return \" My World!!\";\n" +
1433 				"	}\n" +
1434 				"}"
1435 			};
1436 			IJavaProject p2 = setupModuleProject("com.greetings", src, new IClasspathEntry[] { dep });
1437 			p2.getProject().getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, null);
1438 			IMarker[] markers = p2.getProject().findMarkers(null, true, IResource.DEPTH_INFINITE);
1439 			assertMarkers("Unexpected markers",
1440 					"The type com.greetings.MyWorld is not visible",  markers);
1441 		} finally {
1442 			deleteProject("org.astro");
1443 			deleteProject("com.greetings");
1444 		}
1445 	}
test_Exports_Error()1446 	public void test_Exports_Error() throws CoreException {
1447 		try {
1448 			String[] src = new String[] {
1449 				"src/module-info.java",
1450 				"module com.greetings {\n" +
1451 				"	exports com.greetings;\n" +
1452 				"}"
1453 			};
1454 			IJavaProject p2 = setupModuleProject("com.greetings", src);
1455 			p2.getProject().getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, null);
1456 			IMarker[] markers = p2.getProject().findMarkers(null, true, IResource.DEPTH_INFINITE);
1457 			assertMarkers("Unexpected markers",
1458 					"The package com.greetings does not exist or is empty",  markers);
1459 		} finally {
1460 			deleteProject("com.greetings");
1461 		}
1462 	}
test_Exports_foreign_package1()1463 	public void test_Exports_foreign_package1() throws CoreException {
1464 		try {
1465 			String[] src = new String[] {
1466 				"src/module-info.java",
1467 				"module com.greetings {\n" +
1468 				"	exports java.util;\n" +
1469 				"}"
1470 			};
1471 			IJavaProject p2 = setupModuleProject("com.greetings", src);
1472 			p2.getProject().getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, null);
1473 			IMarker[] markers = p2.getProject().findMarkers(null, true, IResource.DEPTH_INFINITE);
1474 			assertMarkers("Unexpected markers",
1475 					"Cannot export the package java.util which belongs to module java.base",  markers);
1476 		} finally {
1477 			deleteProject("com.greetings");
1478 		}
1479 	}
test_Exports_foreign_package2()1480 	public void test_Exports_foreign_package2() throws CoreException {
1481 		try {
1482 			String[] src = new String[] {
1483 				"src/module-info.java",
1484 				"module com.greetings {\n" +
1485 				"	exports java.util;\n" +
1486 				"}",
1487 				"src/java/util/Wrong.java",
1488 				"package java.util;\n" +
1489 				"public class Wrong {}\n"
1490 			};
1491 			IJavaProject p2 = setupModuleProject("com.greetings", src);
1492 			p2.getProject().getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, null);
1493 			IMarker[] markers = p2.getProject().findMarkers(null, true, IResource.DEPTH_INFINITE);
1494 			sortMarkers(markers);
1495 			assertMarkers("Unexpected markers",
1496 					"The package java.util conflicts with a package accessible from another module: java.base",
1497 					markers);
1498 		} finally {
1499 			deleteProject("com.greetings");
1500 		}
1501 	}
test_DuplicateExports()1502 	public void test_DuplicateExports() throws CoreException {
1503 		try {
1504 			String[] sources = new String[] {
1505 				"src/module-info.java",
1506 				"module org.astro {\n" +
1507 				"	exports org.astro;\n" +
1508 				"	exports org.astro;\n" +
1509 				"}",
1510 				"src/org/astro/World.java",
1511 				"package org.astro;\n" +
1512 				"public interface World {\n" +
1513 				"	public String name();\n" +
1514 				"}"
1515 			};
1516 			IJavaProject p1 = setupModuleProject("org.astro", sources);
1517 			p1.getProject().getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, null);
1518 			IMarker[] markers = p1.getProject().findMarkers(null, true, IResource.DEPTH_INFINITE);
1519 			assertMarkers("Unexpected markers",
1520 					"Duplicate exports entry: org.astro",  markers);
1521 		} finally {
1522 			deleteProject("org.astro");
1523 		}
1524 	}
test_TargetedExports_Duplicates()1525 	public void test_TargetedExports_Duplicates() throws CoreException {
1526 		try {
1527 			String[] sources = new String[] {
1528 				"src/module-info.java",
1529 				"module org.astro {\n" +
1530 				"	exports org.astro to com.greetings, com.greetings;\n" +
1531 				"}",
1532 				"src/org/astro/World.java",
1533 				"package org.astro;\n" +
1534 				"public interface World {\n" +
1535 				"	public String name();\n" +
1536 				"}"
1537 			};
1538 			IJavaProject p1 = setupModuleProject("org.astro", sources);
1539 			IClasspathEntry dep = JavaCore.newProjectEntry(p1.getPath());
1540 			String[] src = new String[] {
1541 				"src/module-info.java",
1542 				"module com.greetings {\n" +
1543 				"	requires org.astro;\n" +
1544 				"	exports com.greetings;\n" +
1545 				"}",
1546 				"src/com/greetings/MyWorld.java",
1547 				"package com.greetings;\n" +
1548 				"import org.astro.World;\n" +
1549 				"public class MyWorld implements World {\n" +
1550 				"	public String name() {\n" +
1551 				"		return \" My World!!\";\n" +
1552 				"	}\n" +
1553 				"}"
1554 			};
1555 			setupModuleProject("com.greetings", src, new IClasspathEntry[] { dep });
1556 			p1.getProject().getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, null);
1557 			IMarker[] markers = p1.getProject().findMarkers(null, true, IResource.DEPTH_INFINITE);
1558 			assertMarkers("Unexpected markers",
1559 					"Duplicate module name: com.greetings",  markers);
1560 		} finally {
1561 			deleteProject("org.astro");
1562 			deleteProject("com.greetings");
1563 		}
1564 	}
1565 	// Types from source module should be resolved in target module
1566 	// when package is exported specifically to the target module
test_TargetedExports()1567 	public void test_TargetedExports() throws CoreException {
1568 		try {
1569 			String[] sources = new String[] {
1570 				"src/module-info.java",
1571 				"module org.astro {\n" +
1572 				"	exports org.astro to com.greetings;\n" +
1573 				"}",
1574 				"src/org/astro/World.java",
1575 				"package org.astro;\n" +
1576 				"public interface World {\n" +
1577 				"	public String name();\n" +
1578 				"}"
1579 			};
1580 			IJavaProject p1 = setupModuleProject("org.astro", sources);
1581 			IClasspathAttribute modAttr = new ClasspathAttribute("module", "true");
1582 			IClasspathEntry dep = JavaCore.newProjectEntry(p1.getPath(), null, false,
1583 				new IClasspathAttribute[] {modAttr},
1584 				false/*not exported*/);
1585 			String[] src = new String[] {
1586 				"src/module-info.java",
1587 				"module com.greetings {\n" +
1588 				"	requires org.astro;\n" +
1589 				"	exports com.greetings;\n" +
1590 				"}",
1591 				"src/com/greetings/MyWorld.java",
1592 				"package com.greetings;\n" +
1593 				"import org.astro.World;\n" +
1594 				"public class MyWorld implements World {\n" +
1595 				"	public String name() {\n" +
1596 				"		return \" My World!!\";\n" +
1597 				"	}\n" +
1598 				"}"
1599 			};
1600 			IJavaProject p2 = setupModuleProject("com.greetings", src, new IClasspathEntry[] { dep });
1601 			p2.getProject().getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, null);
1602 			IMarker[] markers = p2.getProject().findMarkers(null, true, IResource.DEPTH_INFINITE);
1603 			assertMarkers("Unexpected markers",	"",  markers);
1604 		} finally {
1605 			deleteProject("org.astro");
1606 			deleteProject("com.greetings");
1607 		}
1608 	}
1609 	// Types in one module should not be visible in target module when
1610 	// source module exports packages to a specific module which is not
1611 	// the same as the target module
test_TargetedExports_Error()1612 	public void test_TargetedExports_Error() throws CoreException {
1613 		try {
1614 			String[] sources = new String[] {
1615 				"src/module-info.java",
1616 				"module some.mod { }",
1617 			};
1618 			setupModuleProject("some.mod", sources);
1619 			sources = new String[] {
1620 				"src/module-info.java",
1621 				"module org.astro {\n" +
1622 				"	exports org.astro to some.mod;\n" +
1623 				"}",
1624 				"src/org/astro/World.java",
1625 				"package org.astro;\n" +
1626 				"public interface World {\n" +
1627 				"	public String name();\n" +
1628 				"}"
1629 			};
1630 			IJavaProject p1 = setupModuleProject("org.astro", sources);
1631 			IClasspathAttribute modAttr = new ClasspathAttribute("module", "true");
1632 			IClasspathEntry dep = JavaCore.newProjectEntry(p1.getPath(), null, false,
1633 				new IClasspathAttribute[] {modAttr},
1634 				false/*not exported*/);
1635 			String[] src = new String[] {
1636 				"src/module-info.java",
1637 				"module com.greetings {\n" +
1638 				"	requires org.astro;\n" +
1639 				"	exports com.greetings;\n" +
1640 				"}",
1641 				"src/com/greetings/MyWorld.java",
1642 				"package com.greetings;\n" +
1643 				"import org.astro.World;\n" +
1644 				"public class MyWorld implements World {\n" +
1645 				"	public String name() {\n" +
1646 				"		return \" My World!!\";\n" +
1647 				"	}\n" +
1648 				"}"
1649 			};
1650 			IJavaProject p2 = setupModuleProject("com.greetings", src, new IClasspathEntry[] { dep });
1651 			p2.getProject().getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, null);
1652 			IMarker[] markers = p2.getProject().findMarkers(null, true, IResource.DEPTH_INFINITE);
1653 			sortMarkers(markers);
1654 			assertMarkers("Unexpected markers",
1655 					"The type org.astro.World is not accessible\n" +
1656 					"World cannot be resolved to a type",
1657 					markers);
1658 		} finally {
1659 			deleteProject("some.mod");
1660 			deleteProject("org.astro");
1661 			deleteProject("com.greetings");
1662 		}
1663 	}
1664 	// It is permitted for the to clause of an exports or opens statement to
1665 	// specify a module which is not observable
test_TargetedExports_Unresolved()1666 	public void test_TargetedExports_Unresolved() throws CoreException {
1667 		try {
1668 			String[] sources = new String[] {
1669 				"src/module-info.java",
1670 				"module org.astro {\n" +
1671 				"	exports org.astro to some.mod;\n" +
1672 				"}",
1673 				"src/org/astro/World.java",
1674 				"package org.astro;\n" +
1675 				"public interface World {\n" +
1676 				"	public String name();\n" +
1677 				"}"
1678 			};
1679 			IJavaProject p1 = setupModuleProject("org.astro", sources);
1680 			p1.getProject().getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, null);
1681 			IMarker[] markers = p1.getProject().findMarkers(null, true, IResource.DEPTH_INFINITE);
1682 			assertMarkers("Unexpected markers",	"",  markers);
1683 		} finally {
1684 			deleteProject("org.astro");
1685 		}
1686 	}
1687 	// Target module of an exports statement should be resolved without having an explicit
1688 	// dependency to the project that defines the module
test_TargetedExports_Resolution()1689 	public void test_TargetedExports_Resolution() throws CoreException {
1690 		try {
1691 			String[] sources = new String[] {
1692 				"src/module-info.java",
1693 				"module some.mod {\n" +
1694 				"}"
1695 			};
1696 			setupModuleProject("some.mod", sources);
1697 			sources = new String[] {
1698 				"src/module-info.java",
1699 				"module org.astro {\n" +
1700 				"	exports org.astro to some.mod;\n" +
1701 				"}",
1702 				"src/org/astro/World.java",
1703 				"package org.astro;\n" +
1704 				"public interface World {\n" +
1705 				"	public String name();\n" +
1706 				"}"
1707 			};
1708 			IJavaProject p1 = setupModuleProject("org.astro", sources);
1709 			p1.getProject().getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, null);
1710 			IMarker[] markers = p1.getProject().findMarkers(null, true, IResource.DEPTH_INFINITE);
1711 			assertMarkers("Unexpected markers", "",  markers);
1712 		} finally {
1713 			deleteProject("org.astro");
1714 			deleteProject("some.mod");
1715 		}
1716 	}
1717 	// Make sure modules in the workspace are resolved via the module source path container
1718 	// without needing to add a dependency to the project explicitly
test_ModuleSourcePathContainer()1719 	public void test_ModuleSourcePathContainer() throws CoreException {
1720 		try {
1721 			String[] sources = new String[] {
1722 				"src/module-info.java",
1723 				"module org.astro {\n" +
1724 				"	exports org.astro;\n" +
1725 				"}",
1726 				"src/org/astro/World.java",
1727 				"package org.astro;\n" +
1728 				"public interface World {\n" +
1729 				"	public String name();\n" +
1730 				"}"
1731 			};
1732 			setupModuleProject("org.astro", sources);
1733 			String[] src = new String[] {
1734 				"src/module-info.java",
1735 				"module com.greetings {\n" +
1736 				"	requires org.astro;\n" +
1737 				"	exports com.greetings;\n" +
1738 				"}",
1739 				"src/com/greetings/MyWorld.java",
1740 				"package com.greetings;\n" +
1741 				"import org.astro.World;\n" +
1742 				"public class MyWorld implements World {\n" +
1743 				"	public String name() {\n" +
1744 				"		return \" My World!!\";\n" +
1745 				"	}\n" +
1746 				"}"
1747 			};
1748 			IClasspathEntry dep = JavaCore.newContainerEntry(new Path(JavaCore.MODULE_PATH_CONTAINER_ID));
1749 			IJavaProject p2 = setupModuleProject("com.greetings", src, new IClasspathEntry[] { dep });
1750 			p2.getProject().getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, null);
1751 			IMarker[] markers = p2.getProject().findMarkers(null, true, IResource.DEPTH_INFINITE);
1752 			assertMarkers("Unexpected markers", "",  markers);
1753 		} finally {
1754 			deleteProject("org.astro");
1755 			deleteProject("com.greetings");
1756 		}
1757 	}
1758 	// Make sure module path container picks up changes to module-info
_test_ModuleSourcePath_update()1759 	public void _test_ModuleSourcePath_update() throws CoreException {
1760 		try {
1761 			String[] sources = new String[] {
1762 				"src/module-info.java",
1763 				"module some.mod {\n" +
1764 				"}"
1765 			};
1766 			setupModuleProject("some.mod", sources);
1767 			sources = new String[] {
1768 				"src/module-info.java",
1769 				"module org.astro {\n" +
1770 				"	exports org.astro;\n" +
1771 				"}",
1772 				"src/org/astro/World.java",
1773 				"package org.astro;\n" +
1774 				"public interface World {\n" +
1775 				"	public String name();\n" +
1776 				"}"
1777 			};
1778 			setupModuleProject("org.astro", sources);
1779 			String[] src = new String[] {
1780 				"src/module-info.java",
1781 				"module com.greetings {\n" +
1782 				"	requires org.astro;\n" +
1783 				"	exports com.greetings;\n" +
1784 				"}",
1785 				"src/com/greetings/MyWorld.java",
1786 				"package com.greetings;\n" +
1787 				"import org.astro.World;\n" +
1788 				"public class MyWorld implements World {\n" +
1789 				"	public String name() {\n" +
1790 				"		return \" My World!!\";\n" +
1791 				"	}\n" +
1792 				"}"
1793 			};
1794 			IClasspathEntry dep = JavaCore.newContainerEntry(new Path(JavaCore.MODULE_PATH_CONTAINER_ID));
1795 			IJavaProject p2 = setupModuleProject("com.greetings", src, new IClasspathEntry[] { dep });
1796 			this.editFile("com.greetings/src/module-info.java",
1797 				"module com.greetings {\n" +
1798 				"	requires org.astro;\n" +
1799 				"	requires some.mod;\n" +
1800 				"	exports com.greetings;\n" +
1801 				"}");
1802 			p2.getProject().getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, null);
1803 			IMarker[] markers = p2.getProject().findMarkers(null, true, IResource.DEPTH_INFINITE);
1804 			assertMarkers("Unexpected markers", "",  markers);
1805 		} finally {
1806 			deleteProject("org.astro");
1807 			deleteProject("some.mod");
1808 			deleteProject("com.greetings");
1809 		}
1810 	}
1811 	// Implicit module dependencies via the 'requires transitive' directive should be
1812 	// resolved via the module path container
test_ModuleSourcePath_implicitdeps()1813 	public void test_ModuleSourcePath_implicitdeps() throws CoreException {
1814 		try {
1815 			String[] sources = new String[] {
1816 				"src/module-info.java",
1817 				"module org.astro {\n" +
1818 				"	exports org.astro;\n" +
1819 				"}",
1820 				"src/org/astro/World.java",
1821 				"package org.astro;\n" +
1822 				"public interface World {\n" +
1823 				"	public String name();\n" +
1824 				"}"
1825 			};
1826 			IClasspathEntry dep = JavaCore.newContainerEntry(new Path(JavaCore.MODULE_PATH_CONTAINER_ID));
1827 			setupModuleProject("org.astro", sources, new IClasspathEntry[]{dep});
1828 			sources = new String[] {
1829 				"src/module-info.java",
1830 				"module some.mod {\n" +
1831 				"	requires transitive org.astro;\n" +
1832 				"}"
1833 			};
1834 			setupModuleProject("some.mod", sources, new IClasspathEntry[]{dep});
1835 			String[] src = new String[] {
1836 				"src/module-info.java",
1837 				"module com.greetings {\n" +
1838 				"	requires some.mod;\n" +
1839 				"	exports com.greetings;\n" +
1840 				"}",
1841 				"src/com/greetings/MyWorld.java",
1842 				"package com.greetings;\n" +
1843 				"import org.astro.World;\n" +
1844 				"public class MyWorld implements World {\n" +
1845 				"	public String name() {\n" +
1846 				"		return \" My World!!\";\n" +
1847 				"	}\n" +
1848 				"}"
1849 			};
1850 
1851 			IJavaProject p2 = setupModuleProject("com.greetings", src, new IClasspathEntry[] { dep });
1852 			p2.getProject().getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, null);
1853 			IMarker[] markers = p2.getProject().findMarkers(null, true, IResource.DEPTH_INFINITE);
1854 			assertMarkers("Unexpected markers", "",  markers);
1855 		} finally {
1856 			deleteProject("org.astro");
1857 			deleteProject("some.mod");
1858 			deleteProject("com.greetings");
1859 		}
1860 	}
1861 	// Changes to implicit dependencies should be reflected // FIXME: container JavaCore.MODULE_PATH_CONTAINER_ID is unreliable
_test_ModuleSourcePath_implicitdeps2()1862 	public void _test_ModuleSourcePath_implicitdeps2() throws CoreException {
1863 		try {
1864 			String[] sources = new String[] {
1865 				"src/module-info.java",
1866 				"module some.mod {\n" +
1867 				"	requires transitive org.astro;\n" +
1868 				"}"
1869 			};
1870 			IClasspathEntry dep = JavaCore.newContainerEntry(new Path(JavaCore.MODULE_PATH_CONTAINER_ID));
1871 			setupModuleProject("some.mod", sources, new IClasspathEntry[]{dep});
1872 			sources = new String[] {
1873 				"src/module-info.java",
1874 				"module org.astro {\n" +
1875 				"	exports org.astro;\n" +
1876 				"}",
1877 				"src/org/astro/World.java",
1878 				"package org.astro;\n" +
1879 				"public interface World {\n" +
1880 				"	public String name();\n" +
1881 				"}"
1882 			};
1883 			setupModuleProject("org.astro", sources, new IClasspathEntry[]{dep});
1884 			String[] src = new String[] {
1885 				"src/module-info.java",
1886 				"module com.greetings {\n" +
1887 				"	requires some.mod;\n" +
1888 				"	exports com.greetings;\n" +
1889 				"}",
1890 				"src/com/greetings/MyWorld.java",
1891 				"package com.greetings;\n" +
1892 				"import org.astro.World;\n" +
1893 				"public class MyWorld implements World {\n" +
1894 				"	public String name() {\n" +
1895 				"		return \" My World!!\";\n" +
1896 				"	}\n" +
1897 				"}"
1898 			};
1899 
1900 			IJavaProject p2 = setupModuleProject("com.greetings", src, new IClasspathEntry[] { dep });
1901 			this.editFile("some.mod/src/module-info.java",
1902 				"module some.mod {\n" +
1903 				"	requires org.astro;\n" +
1904 				"}");
1905 			p2.getProject().getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, null);
1906 			IMarker[] markers = p2.getProject().findMarkers(null, true, IResource.DEPTH_INFINITE);
1907 			sortMarkers(markers);
1908 			assertMarkers("Unexpected markers",
1909 					"The type org.astro.World is not accessible\n" +
1910 					"World cannot be resolved to a type",  markers);
1911 		} finally {
1912 			deleteProject("org.astro");
1913 			deleteProject("some.mod");
1914 			deleteProject("com.greetings");
1915 		}
1916 	}
1917 	// Changes to implicit dependencies should be reflected
1918 	//TODO enable once we know how to update project cache
_test_ModuleSourcePath_implicitdeps3()1919 	public void _test_ModuleSourcePath_implicitdeps3() throws CoreException {
1920 		try {
1921 			String[] sources = new String[] {
1922 				"src/module-info.java",
1923 				"module some.mod {\n" +
1924 				"	requires org.astro;\n" +
1925 				"}"
1926 			};
1927 			IClasspathEntry dep = JavaCore.newContainerEntry(new Path(JavaCore.MODULE_PATH_CONTAINER_ID));
1928 			setupModuleProject("some.mod", sources, new IClasspathEntry[]{dep});
1929 			sources = new String[] {
1930 				"src/module-info.java",
1931 				"module org.astro {\n" +
1932 				"	exports org.astro;\n" +
1933 				"}",
1934 				"src/org/astro/World.java",
1935 				"package org.astro;\n" +
1936 				"public interface World {\n" +
1937 				"	public String name();\n" +
1938 				"}"
1939 			};
1940 			setupModuleProject("org.astro", sources, new IClasspathEntry[]{dep});
1941 			String[] src = new String[] {
1942 				"src/module-info.java",
1943 				"module com.greetings {\n" +
1944 				"	requires some.mod;\n" +
1945 				"	exports com.greetings;\n" +
1946 				"}",
1947 				"src/com/greetings/MyWorld.java",
1948 				"package com.greetings;\n" +
1949 				"import org.astro.World;\n" +
1950 				"public class MyWorld implements World {\n" +
1951 				"	public String name() {\n" +
1952 				"		return \" My World!!\";\n" +
1953 				"	}\n" +
1954 				"}"
1955 			};
1956 
1957 			IJavaProject p2 = setupModuleProject("com.greetings", src, new IClasspathEntry[] { dep });
1958 			this.editFile("some.mod/src/module-info.java",
1959 				"module some.mod {\n" +
1960 				"	requires transitive org.astro;\n" +
1961 				"}");
1962 			p2.getProject().getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, null);
1963 			IMarker[] markers = p2.getProject().findMarkers(null, true, IResource.DEPTH_INFINITE);
1964 			assertMarkers("Unexpected markers", "",  markers);
1965 		} finally {
1966 			deleteProject("org.astro");
1967 			deleteProject("some.mod");
1968 			deleteProject("com.greetings");
1969 		}
1970 	}
test_Cycle_In_Module_Dependency()1971 	public void test_Cycle_In_Module_Dependency() throws CoreException {
1972 		try {
1973 			String[] sources = new String[] {
1974 				"src/module-info.java",
1975 				"module org.astro {\n" +
1976 				"	exports org.astro;\n" +
1977 				"}",
1978 				"src/org/astro/World.java",
1979 				"package org.astro;\n" +
1980 				"public interface World {\n" +
1981 				"	public String name();\n" +
1982 				"}"
1983 			};
1984 			IClasspathEntry dep = JavaCore.newContainerEntry(new Path(JavaCore.MODULE_PATH_CONTAINER_ID));
1985 			setupModuleProject("org.astro", sources, new IClasspathEntry[]{dep});
1986 			sources = new String[] {
1987 				"src/module-info.java",
1988 				"module some.mod {\n" +
1989 				"	requires org.astro;\n" +
1990 				"}"
1991 			};
1992 			setupModuleProject("some.mod", sources, new IClasspathEntry[]{dep});
1993 			String[] src = new String[] {
1994 				"src/module-info.java",
1995 				"module com.greetings {\n" +
1996 				"	requires some.mod;\n" +
1997 				"	exports com.greetings;\n" +
1998 				"}"
1999 			};
2000 
2001 			IJavaProject p2 = setupModuleProject("com.greetings", src, new IClasspathEntry[] { dep });
2002 			editFile("org.astro/src/module-info.java",
2003 					"module org.astro {\n" +
2004 					"	exports org.astro;\n" +
2005 					"	requires com.greetings;\n" +
2006 					"}");
2007 			waitForAutoBuild();
2008 			getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, null);
2009 			assertTrue("Should detect cycle", p2.hasClasspathCycle(null));
2010 		} finally {
2011 			deleteProject("org.astro");
2012 			deleteProject("some.mod");
2013 			deleteProject("com.greetings");
2014 		}
2015 	}
test_Cycle_In_Implicit_Module_Dependency()2016 	public void test_Cycle_In_Implicit_Module_Dependency() throws CoreException {
2017 		try {
2018 			String[] sources = new String[] {
2019 				"src/module-info.java",
2020 				"module org.astro {\n" +
2021 				"	exports org.astro;\n" +
2022 				"}",
2023 				"src/org/astro/World.java",
2024 				"package org.astro;\n" +
2025 				"public interface World {\n" +
2026 				"	public String name();\n" +
2027 				"}"
2028 			};
2029 			IClasspathEntry dep = JavaCore.newContainerEntry(new Path(JavaCore.MODULE_PATH_CONTAINER_ID));
2030 			setupModuleProject("org.astro", sources, new IClasspathEntry[]{dep});
2031 			sources = new String[] {
2032 				"src/module-info.java",
2033 				"module some.mod {\n" +
2034 				"	requires transitive org.astro;\n" +
2035 				"}"
2036 			};
2037 			setupModuleProject("some.mod", sources, new IClasspathEntry[]{dep});
2038 			String[] src = new String[] {
2039 				"src/module-info.java",
2040 				"module com.greetings {\n" +
2041 				"	requires some.mod;\n" +
2042 				"	exports com.greetings;\n" +
2043 				"}"
2044 			};
2045 			IJavaProject p2 = setupModuleProject("com.greetings", src, new IClasspathEntry[] { dep });
2046 			editFile("org.astro/src/module-info.java",
2047 				"module org.astro {\n" +
2048 				"	exports org.astro;\n" +
2049 				"	requires transitive com.greetings;\n" +
2050 				"}");
2051 			waitForAutoBuild();
2052 			getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, null);
2053 			assertTrue("Should detect cycle", p2.hasClasspathCycle(null));
2054 		} finally {
2055 			deleteProject("org.astro");
2056 			deleteProject("some.mod");
2057 			deleteProject("com.greetings");
2058 		}
2059 	}
test_bug506479()2060 	public void test_bug506479() throws CoreException {
2061 		try {
2062 			String[] sources = new String[] {
2063 					"src/module-info.java",
2064 					"module org.astro {\n" +
2065 					"	exports org.astro;\n" +
2066 					"}",
2067 					"src/org/astro/World.java",
2068 					"package org.astro;\n" +
2069 					"public interface World {\n" +
2070 					"	public String name();\n" +
2071 					"}"
2072 				};
2073 			IClasspathEntry dep = JavaCore.newContainerEntry(new Path(JavaCore.MODULE_PATH_CONTAINER_ID));
2074 			IJavaProject p1 = setupModuleProject("org.astro", sources, new IClasspathEntry[]{dep});
2075 			IWorkspaceDescription desc = p1.getProject().getWorkspace().getDescription();
2076 			desc.setAutoBuilding(false);
2077 			p1.getProject().getWorkspace().setDescription(desc);
2078 			this.deleteFile("org.astro/src/module-info.java");
2079 			this.createFile(
2080 					"org.astro/src/module-info.java",
2081 					"module org.astro {\n" +
2082 					"	exports org.astro;\n" +
2083 					"}");
2084 			p1.getProject().getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, null);
2085 		} finally {
2086 			deleteProject("org.astro");
2087 		}
2088 	}
test_Multiple_SourceFolders()2089 	public void test_Multiple_SourceFolders() throws CoreException {
2090 		try {
2091 			String[] sources = new String[] {
2092 				"src/module-info.java",
2093 				"module org.astro {\n" +
2094 				"	exports org.astro;\n" +
2095 				"}",
2096 				"src/org/astro/World.java",
2097 				"package org.astro;\n" +
2098 				"public interface World {\n" +
2099 				"	public String name();\n" +
2100 				"}",
2101 				"othersrc/org/astro/OtherWorld.java",
2102 				"package org.astro;\n" +
2103 				"import org.astro.World;\n" +
2104 				"public interface OtherWorld {\n" +
2105 				"	default public String name() {\n" +
2106 				"		return \" Other World!!\";\n" +
2107 				"	}\n" +
2108 				"}"
2109 			};
2110 			setupModuleProject("org.astro", new String[]{"src", "othersrc"}, sources, null);
2111 			String[] src = new String[] {
2112 				"src/module-info.java",
2113 				"module com.greetings {\n" +
2114 				"	requires org.astro;\n" +
2115 				"	exports com.greetings;\n" +
2116 				"}",
2117 				"src/com/greetings/MyWorld.java",
2118 				"package com.greetings;\n" +
2119 				"import org.astro.World;\n" +
2120 				"public class MyWorld implements World {\n" +
2121 				"	public String name() {\n" +
2122 				"		return \" My World!!\";\n" +
2123 				"	}\n" +
2124 				"}",
2125 				"othersrc/com/greetings/AnotherWorld.java",
2126 				"package com.greetings;\n" +
2127 				"import org.astro.OtherWorld;\n" +
2128 				"public class AnotherWorld implements OtherWorld {\n" +
2129 				"	public String name() {\n" +
2130 				"		return \" Another World!!\";\n" +
2131 				"	}\n" +
2132 				"}"
2133 			};
2134 			IClasspathEntry dep = JavaCore.newContainerEntry(new Path(JavaCore.MODULE_PATH_CONTAINER_ID));
2135 			IJavaProject p2 = setupModuleProject("com.greetings", new String[]{"src", "othersrc"}, src, new IClasspathEntry[] { dep });
2136 			p2.getProject().getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, null);
2137 			IMarker[] markers = p2.getProject().findMarkers(null, true, IResource.DEPTH_INFINITE);
2138 			assertMarkers("Unexpected markers", "",  markers);
2139 		} finally {
2140 			deleteProject("org.astro");
2141 			deleteProject("com.greetings");
2142 		}
2143 	}
test_Multiple_SourceFolders_WithModuleInfo()2144 	public void test_Multiple_SourceFolders_WithModuleInfo() throws CoreException {
2145 		try {
2146 			String[] sources = new String[] {
2147 				"src/module-info.java",
2148 				"module org.astro {\n" +
2149 				"	exports org.astro;\n" +
2150 				"}",
2151 				"src/org/astro/World.java",
2152 				"package org.astro;\n" +
2153 				"public interface World {\n" +
2154 				"	public String name();\n" +
2155 				"}",
2156 				"othersrc/org/astro/OtherWorld.java",
2157 				"package org.astro;\n" +
2158 				"import org.astro.World;\n" +
2159 				"public interface OtherWorld {\n" +
2160 				"	default public String name() {\n" +
2161 				"		return \" Other World!!\";\n" +
2162 				"	}\n" +
2163 				"}"
2164 			};
2165 			setupModuleProject("org.astro", new String[]{"src", "othersrc"}, sources, null);
2166 			String[] src = new String[] {
2167 				"src/module-info.java",
2168 				"module com.greetings {\n" +
2169 				"	requires org.astro;\n" +
2170 				"	exports com.greetings;\n" +
2171 				"}",
2172 				"src/com/greetings/MyWorld.java",
2173 				"package com.greetings;\n" +
2174 				"import org.astro.World;\n" +
2175 				"public class MyWorld implements World {\n" +
2176 				"	public String name() {\n" +
2177 				"		return \" My World!!\";\n" +
2178 				"	}\n" +
2179 				"}",
2180 				"othersrc/module-info.java",
2181 				"module com.greetings1 {\n" +
2182 				"	requires org.astro;\n" +
2183 				"	exports com.greetings;\n" +
2184 				"}",
2185 				"othersrc/com/greetings/AnotherWorld.java",
2186 				"package com.greetings;\n" +
2187 				"import org.astro.OtherWorld;\n" +
2188 				"public class AnotherWorld implements OtherWorld {\n" +
2189 				"	public String name() {\n" +
2190 				"		return \" Another World!!\";\n" +
2191 				"	}\n" +
2192 				"}"
2193 			};
2194 			IClasspathEntry dep = JavaCore.newContainerEntry(new Path(JavaCore.MODULE_PATH_CONTAINER_ID));
2195 			IJavaProject p2 = setupModuleProject("com.greetings", new String[]{"src", "othersrc"}, src, new IClasspathEntry[] { dep });
2196 			p2.getProject().getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, null);
2197 			IMarker[] markers = p2.getProject().findMarkers(IJavaModelMarker.JAVA_MODEL_PROBLEM_MARKER, true, IResource.DEPTH_ZERO);
2198 			assertEquals(1, markers.length);
2199 			String msg = markers[0].getAttribute(IMarker.MESSAGE, "");
2200 			String expected = Messages.bind(Messages.classpath_duplicateEntryPath, TypeConstants.MODULE_INFO_FILE_NAME_STRING, p2.getElementName());
2201 			assertTrue("Unexpected result", msg.indexOf(expected) != -1);
2202 		} finally {
2203 			deleteProject("org.astro");
2204 			deleteProject("com.greetings");
2205 		}
2206 	}
test_Multiple_SourceFolders_addModuleInfo()2207 	public void test_Multiple_SourceFolders_addModuleInfo() throws CoreException {
2208 		try {
2209 			String[] sources = new String[] {
2210 				"src/module-info.java",
2211 				"module org.astro {\n" +
2212 				"	exports org.astro;\n" +
2213 				"}",
2214 				"src/org/astro/World.java",
2215 				"package org.astro;\n" +
2216 				"public interface World {\n" +
2217 				"	public String name();\n" +
2218 				"}",
2219 				"othersrc/org/astro/OtherWorld.java",
2220 				"package org.astro;\n" +
2221 				"import org.astro.World;\n" +
2222 				"public interface OtherWorld {\n" +
2223 				"	default public String name() {\n" +
2224 				"		return \" Other World!!\";\n" +
2225 				"	}\n" +
2226 				"}"
2227 			};
2228 			IJavaProject p1 = setupModuleProject("org.astro", new String[]{"src", "othersrc"}, sources, null);
2229 			this.createFile("org.astro/othersrc/module-info.java",
2230 					"module org.astro1 {\n" +
2231 					"	exports org.astro;\n" +
2232 					"}");
2233 			waitForAutoBuild();
2234 			p1.getProject().getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, null);
2235 			IMarker[] markers = p1.getProject().findMarkers(IJavaModelMarker.JAVA_MODEL_PROBLEM_MARKER, true, IResource.DEPTH_ZERO);
2236 			assertEquals(1, markers.length);
2237 			String msg = markers[0].getAttribute(IMarker.MESSAGE, "");
2238 			String expected = Messages.bind(Messages.classpath_duplicateEntryPath, TypeConstants.MODULE_INFO_FILE_NAME_STRING, p1.getElementName());
2239 			assertTrue("Unexpected result", msg.indexOf(expected) != -1);
2240 		} finally {
2241 			deleteProject("org.astro");
2242 		}
2243 	}
test_Multiple_SourceFolders_removeModuleInfo()2244 	public void test_Multiple_SourceFolders_removeModuleInfo() throws CoreException {
2245 		try {
2246 			String[] sources = new String[] {
2247 				"src/module-info.java",
2248 				"module org.astro {\n" +
2249 				"	exports org.astro;\n" +
2250 				"}",
2251 				"src/org/astro/World.java",
2252 				"package org.astro;\n" +
2253 				"public interface World {\n" +
2254 				"	public String name();\n" +
2255 				"}",
2256 				"othersrc/module-info.java",
2257 				"module org.astro1 {\n" +
2258 				"	exports org.astro;\n" +
2259 				"}",
2260 				"othersrc/org/astro/OtherWorld.java",
2261 				"package org.astro;\n" +
2262 				"import org.astro.World;\n" +
2263 				"public interface OtherWorld {\n" +
2264 				"	default public String name() {\n" +
2265 				"		return \" Other World!!\";\n" +
2266 				"	}\n" +
2267 				"}"
2268 			};
2269 			IJavaProject p1 = setupModuleProject("org.astro", new String[]{"src", "othersrc"}, sources, null);
2270 			waitForAutoBuild();
2271 			this.deleteFile("org.astro/othersrc/module-info.java");
2272 			waitForAutoBuild();
2273 			p1.getProject().getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, null);
2274 			IMarker[] markers = p1.getProject().findMarkers(IJavaModelMarker.JAVA_MODEL_PROBLEM_MARKER, true, IResource.DEPTH_ZERO);
2275 			assertEquals(0, markers.length);
2276 		} finally {
2277 			deleteProject("org.astro");
2278 		}
2279 	}
test_services_multipleImpl()2280 	public void test_services_multipleImpl() throws CoreException {
2281 		try {
2282 			String[] sources = new String[] {
2283 					"src/module-info.java",
2284 					"module org.astro {\n" +
2285 					"	exports org.astro;\n" +
2286 					"}",
2287 					"src/org/astro/World.java",
2288 					"package org.astro;\n" +
2289 					"public interface World {\n" +
2290 					"	public String name();\n" +
2291 					"}"
2292 			};
2293 			IJavaProject p1 = setupModuleProject("org.astro", sources);
2294 			IClasspathAttribute modAttr = new ClasspathAttribute("module", "true");
2295 			IClasspathEntry dep = JavaCore.newProjectEntry(p1.getPath(), null, false,
2296 				new IClasspathAttribute[] {modAttr},
2297 				false/*not exported*/);
2298 			String[] src = new String[] {
2299 					"src/module-info.java",
2300 					"import org.astro.World;\n" +
2301 					"import com.greetings.*;\n" +
2302 					"module com.greetings {\n" +
2303 					"	requires org.astro;\n" +
2304 					"	exports com.greetings;\n" +
2305 					"	provides World with MyWorld, AnotherWorld;\n" +
2306 					"}",
2307 					"src/com/greetings/MyWorld.java",
2308 					"package com.greetings;\n" +
2309 					"import org.astro.World;\n"	+
2310 					"public class MyWorld implements World {\n" +
2311 					"	public String name() {\n" +
2312 					"		return \" My World!!\";\n" +
2313 					"	}\n" +
2314 					"}",
2315 					"src/com/greetings/AnotherWorld.java",
2316 					"package com.greetings;\n" +
2317 					"import org.astro.World;\n"	+
2318 					"public class AnotherWorld implements World {\n" +
2319 					"	public String name() {\n" +
2320 					"		return \" Another World!!\";\n" +
2321 					"	}\n" +
2322 					"}"
2323 			};
2324 			IJavaProject p2 = setupModuleProject("com.greetings", src, new IClasspathEntry[] { dep });
2325 			p2.getProject().getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, null);
2326 			IMarker[] markers = p2.getProject().findMarkers(null, true, IResource.DEPTH_INFINITE);
2327 			assertMarkers("Unexpected markers", "", markers);
2328 		} finally {
2329 			deleteProject("org.astro");
2330 			deleteProject("com.greetings");
2331 		}
2332 	}
test_imports_in_moduleinfo()2333 	public void test_imports_in_moduleinfo() throws CoreException {
2334 		try {
2335 			String[] sources = new String[] {
2336 					"src/module-info.java",
2337 					"module org.astro {\n" +
2338 					"	exports org.astro;\n" +
2339 					"}",
2340 					"src/org/astro/World.java",
2341 					"package org.astro;\n" +
2342 					"public interface World {\n" +
2343 					"	public String name();\n" +
2344 					"}"
2345 			};
2346 			IJavaProject p1 = setupModuleProject("org.astro", sources);
2347 			IClasspathAttribute modAttr = new ClasspathAttribute("module", "true");
2348 			IClasspathEntry dep = JavaCore.newProjectEntry(p1.getPath(), null, false,
2349 				new IClasspathAttribute[] {modAttr},
2350 				false/*not exported*/);
2351 			String[] src = new String[] {
2352 					"src/module-info.java",
2353 					"import org.astro.World;\n" +
2354 					"module com.greetings {\n" +
2355 					"	requires org.astro;\n" +
2356 					"	exports com.greetings;\n" +
2357 					"	provides World with com.greetings.MyWorld;\n" +
2358 					"}",
2359 					"src/com/greetings/MyWorld.java",
2360 					"package com.greetings;\n" +
2361 					"import org.astro.World;\n"	+
2362 					"public class MyWorld implements World {\n" +
2363 					"	public String name() {\n" +
2364 					"		return \" My World!!\";\n" +
2365 					"	}\n" +
2366 					"}"
2367 			};
2368 			IJavaProject p2 = setupModuleProject("com.greetings", src, new IClasspathEntry[] { dep });
2369 			p2.getProject().getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, null);
2370 			IMarker[] markers = p2.getProject().findMarkers(null, true, IResource.DEPTH_INFINITE);
2371 			assertMarkers("Unexpected markers", "", markers);
2372 		} finally {
2373 			deleteProject("org.astro");
2374 			deleteProject("com.greetings");
2375 		}
2376 	}
2377 
test_Opens_Nonexistent_Package()2378 	public void test_Opens_Nonexistent_Package() throws CoreException {
2379 		try {
2380 			String[] src = new String[] {
2381 				"src/module-info.java",
2382 				"module com.greetings {\n" +
2383 				"	opens com.greetings;\n" +
2384 				"}"
2385 			};
2386 			IJavaProject p2 = setupModuleProject("com.greetings", src);
2387 			p2.getProject().getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, null);
2388 			assertNoErrors();
2389 		} finally {
2390 			deleteProject("com.greetings");
2391 		}
2392 	}
test_Opens_Alien_Package()2393 	public void test_Opens_Alien_Package() throws CoreException {
2394 		try {
2395 			String[] src = new String[] {
2396 				"src/module-info.java",
2397 				"module org.astro {}",
2398 				"src/org/astro/World.java",
2399 				"package org.astro;\n" +
2400 				"public interface World {\n" +
2401 				"    public String name();\n" +
2402 				"}\n"
2403 			};
2404 			IJavaProject p1 = setupModuleProject("org.astro", src);
2405 			src = new String[] {
2406 				"src/module-info.java",
2407 				"module com.greetings {\n" +
2408 				"	requires org.astro;\n" +
2409 				"	opens org.astro;\n" +
2410 				"}",
2411 				"src/test/Test.java",
2412 				"package test;\n" +
2413 				"public class Test {\n" +
2414 				"	org.astro.World w = null;\n" +
2415 				"}"
2416 			};
2417 			IClasspathAttribute modAttr = new ClasspathAttribute(IClasspathAttribute.MODULE, "true");
2418 			IClasspathEntry dep = JavaCore.newProjectEntry(p1.getPath(), null, false, new IClasspathAttribute[] {modAttr}, false);
2419 			IJavaProject p2 = setupModuleProject("com.greetings", src, new IClasspathEntry[] {dep});
2420 			getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, null);
2421 			IMarker[] markers = p2.getProject().findMarkers(null, true, IResource.DEPTH_INFINITE);
2422 			sortMarkers(markers);
2423 			assertMarkers("Unexpected markers",
2424 					"The type org.astro.World is not accessible\n" +
2425 					"The package org.astro does not exist or is empty",  markers);
2426 		} finally {
2427 			deleteProject("org.astro");
2428 			deleteProject("com.greetings");
2429 		}
2430 	}
test_DuplicateOpens()2431 	public void test_DuplicateOpens() throws CoreException {
2432 		try {
2433 			String[] sources = new String[] {
2434 				"src/module-info.java",
2435 				"module org.astro {\n" +
2436 				"	opens org.astro;\n" +
2437 				"	opens org.astro;\n" +
2438 				"}",
2439 				"src/org/astro/World.java",
2440 				"package org.astro;\n" +
2441 				"public interface World {\n" +
2442 				"	public String name();\n" +
2443 				"}"
2444 			};
2445 			IJavaProject p1 = setupModuleProject("org.astro", sources);
2446 			p1.getProject().getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, null);
2447 			IMarker[] markers = p1.getProject().findMarkers(null, true, IResource.DEPTH_INFINITE);
2448 			assertMarkers("Unexpected markers",
2449 					"Duplicate opens entry: org.astro",  markers);
2450 		} finally {
2451 			deleteProject("org.astro");
2452 		}
2453 	}
test_TargetedOpens_Duplicates()2454 	public void test_TargetedOpens_Duplicates() throws CoreException {
2455 		try {
2456 			String[] sources = new String[] {
2457 				"src/module-info.java",
2458 				"module org.astro {\n" +
2459 				"	opens org.astro to com.greetings, com.greetings;\n" +
2460 				"}",
2461 				"src/org/astro/World.java",
2462 				"package org.astro;\n" +
2463 				"public interface World {\n" +
2464 				"	public String name();\n" +
2465 				"}"
2466 			};
2467 			IJavaProject p1 = setupModuleProject("org.astro", sources);
2468 			IClasspathEntry dep = JavaCore.newProjectEntry(p1.getPath());
2469 			String[] src = new String[] {
2470 				"src/module-info.java",
2471 				"module com.greetings {\n" +
2472 				"	requires org.astro;\n" +
2473 				"	exports com.greetings;\n" +
2474 				"}",
2475 				"src/com/greetings/MyWorld.java",
2476 				"package com.greetings;\n" +
2477 				"import org.astro.World;\n" +
2478 				"public class MyWorld implements World {\n" +
2479 				"	public String name() {\n" +
2480 				"		return \" My World!!\";\n" +
2481 				"	}\n" +
2482 				"}"
2483 			};
2484 			setupModuleProject("com.greetings", src, new IClasspathEntry[] { dep });
2485 			p1.getProject().getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, null);
2486 			IMarker[] markers = p1.getProject().findMarkers(null, true, IResource.DEPTH_INFINITE);
2487 			assertMarkers("Unexpected markers",
2488 					"Duplicate module name: com.greetings",  markers);
2489 		} finally {
2490 			deleteProject("org.astro");
2491 			deleteProject("com.greetings");
2492 		}
2493 	}
2494 	// It is permitted for the to clause of an exports or opens statement to
2495 	// specify a module which is not observable
test_TargetedOpens_Unresolved()2496 	public void test_TargetedOpens_Unresolved() throws CoreException {
2497 		try {
2498 			String[] sources = new String[] {
2499 				"src/module-info.java",
2500 				"module org.astro {\n" +
2501 				"	opens org.astro to some.mod;\n" +
2502 				"}",
2503 				"src/org/astro/World.java",
2504 				"package org.astro;\n" +
2505 				"public interface World {\n" +
2506 				"	public String name();\n" +
2507 				"}"
2508 			};
2509 			IJavaProject p1 = setupModuleProject("org.astro", sources);
2510 			p1.getProject().getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, null);
2511 			IMarker[] markers = p1.getProject().findMarkers(null, true, IResource.DEPTH_INFINITE);
2512 			assertMarkers("Unexpected markers",	"",  markers);
2513 		} finally {
2514 			deleteProject("org.astro");
2515 		}
2516 	}
2517 	// It is a compile-time error if an opens statement appears in the declaration of an open module.
test_OpensStatment_in_OpenModule()2518 	public void test_OpensStatment_in_OpenModule() throws CoreException {
2519 		try {
2520 			String[] sources = new String[] {
2521 				"src/module-info.java",
2522 				"open module org.astro {\n" +
2523 				"	opens org.astro to some.mod;\n" +
2524 				"}",
2525 				"src/org/astro/World.java",
2526 				"package org.astro;\n" +
2527 				"public interface World {\n" +
2528 				"	public String name();\n" +
2529 				"}"
2530 			};
2531 			IJavaProject p1 = setupModuleProject("org.astro", sources);
2532 			p1.getProject().getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, null);
2533 			IMarker[] markers = p1.getProject().findMarkers(null, true, IResource.DEPTH_INFINITE);
2534 			assertMarkers("Unexpected markers",
2535 				"opens statement is not allowed, as module org.astro is declared open",  markers);
2536 		} finally {
2537 			deleteProject("org.astro");
2538 		}
2539 	}
test_uses_DuplicateEntries()2540 	public void test_uses_DuplicateEntries() throws CoreException {
2541 		try {
2542 			String[] sources = new String[] {
2543 				"src/module-info.java",
2544 				"module org.astro {\n" +
2545 				"	exports org.astro;\n" +
2546 				"	uses org.astro.World;\n" +
2547 				"	uses org.astro.World;\n" +
2548 				"}",
2549 				"src/org/astro/World.java",
2550 				"package org.astro;\n" +
2551 				"public interface World {\n" +
2552 				"	public String name();\n" +
2553 				"}"
2554 			};
2555 			IJavaProject p1 = setupModuleProject("org.astro", sources);
2556 			p1.getProject().getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, null);
2557 			IMarker[] markers = p1.getProject().findMarkers(null, true, IResource.DEPTH_INFINITE);
2558 			assertMarkers("Unexpected markers",
2559 					"Duplicate uses entry: org.astro.World",  markers);
2560 		} finally {
2561 			deleteProject("org.astro");
2562 		}
2563 	}
test_uses_InvalidIntfType()2564 	public void test_uses_InvalidIntfType() throws CoreException {
2565 		try {
2566 			String[] src = new String[] {
2567 				"src/module-info.java",
2568 				"module com.greetings {\n" +
2569 				"	exports com.greetings;\n" +
2570 				"	uses com.greetings.MyEnum;\n" +
2571 				"}",
2572 				"src/com/greetings/MyEnum.java",
2573 				"package com.greetings;\n" +
2574 				"public enum MyEnum {}"
2575 			};
2576 			IJavaProject p2 = setupModuleProject("com.greetings", src);
2577 			p2.getProject().getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, null);
2578 			IMarker[] markers = p2.getProject().findMarkers(null, true, IResource.DEPTH_INFINITE);
2579 			sortMarkers(markers);
2580 			assertMarkers("Unexpected markers",
2581 					"Invalid service interface com.greetings.MyEnum, must be a class, interface or annotation type",  markers);
2582 		} finally {
2583 			deleteProject("com.greetings");
2584 		}
2585 	}
test_ReconcilerModuleLookup1()2586 	public void test_ReconcilerModuleLookup1() throws CoreException {
2587 		try {
2588 			String[] src = new String[] {
2589 				"src/module-info.java",
2590 				"module com.greetings {\n" +
2591 				"	requires java.sql;\n" +
2592 				"}"};
2593 			setupModuleProject("com.greetings", src);
2594 			this.workingCopies = new ICompilationUnit[1];
2595 			char[] sourceChars = src[1].toCharArray();
2596 			this.problemRequestor.initialize(sourceChars);
2597 			this.workingCopies[0] = getCompilationUnit("/com.greetings/src/module-info.java").getWorkingCopy(this.wcOwner, null);
2598 			assertProblems(
2599 					"Unexpected problems",
2600 					"----------\n" +
2601 					"----------\n",
2602 					this.problemRequestor);
2603 		} finally {
2604 			deleteProject("com.greetings");
2605 		}
2606 	}
test_ReconcilerModuleLookup2()2607 	public void test_ReconcilerModuleLookup2() throws CoreException {
2608 		try {
2609 			String[] src = new String[] {
2610 				"src/module-info.java",
2611 				"module com.greetings {\n" +
2612 				"	requires java.sq;\n" +
2613 				"}"};
2614 			setupModuleProject("com.greetings", src);
2615 			this.workingCopies = new ICompilationUnit[1];
2616 			char[] sourceChars = src[1].toCharArray();
2617 			this.problemRequestor.initialize(sourceChars);
2618 			this.workingCopies[0] = getCompilationUnit("/com.greetings/src/module-info.java").getWorkingCopy(this.wcOwner, null);
2619 			assertProblems(
2620 					"Unexpected problems",
2621 					"----------\n" +
2622 					"1. ERROR in /com.greetings/src/module-info.java (at line 2)\n" +
2623 					"	requires java.sq;\n" +
2624 					"	         ^^^^^^^\n" +
2625 					"java.sq cannot be resolved to a module\n" +
2626 					"----------\n",
2627 					this.problemRequestor);
2628 		} finally {
2629 			deleteProject("com.greetings");
2630 		}
2631 	}
testSystemLibAsJMod()2632 	public void testSystemLibAsJMod() throws CoreException {
2633 		try {
2634 			IJavaProject project = createJava9Project("Test01", new String[]{"src"});
2635 			IClasspathEntry[] rawClasspath = project.getRawClasspath();
2636 			for (int i = 0; i < rawClasspath.length; i++) {
2637 				IPath path = rawClasspath[i].getPath();
2638 				if (path.lastSegment().equals("jrt-fs.jar")) {
2639 					path = path.removeLastSegments(2).append("jmods").append("java.base.jmod");
2640 					IClasspathEntry newEntry = JavaCore.newLibraryEntry(path, rawClasspath[i].getSourceAttachmentPath(), new Path("java.base"));
2641 					rawClasspath[i] = newEntry;
2642 				}
2643 			}
2644 			project.setRawClasspath(rawClasspath, null);
2645 			this.createFile("Test01/src/module-info.java", "");
2646 			this.createFolder("Test01/src/com/greetings");
2647 			this.createFile("Test01/src/com/greetings/Main.java", "");
2648 			waitForManualRefresh();
2649 			waitForAutoBuild();
2650 			project.getProject().build(IncrementalProjectBuilder.FULL_BUILD, null);
2651 			IPackageFragmentRoot[] roots = project.getPackageFragmentRoots();
2652 			IPackageFragmentRoot base = null;
2653 			for (IPackageFragmentRoot iRoot : roots) {
2654 				IModuleDescription moduleDescription = iRoot.getModuleDescription();
2655 				if (moduleDescription != null) {
2656 					base = iRoot;
2657 					break;
2658 				}
2659 			}
2660 			assertNotNull("Java.base module should not null", base);
2661 			assertProblemMarkers("Unexpected markers", "", project.getProject());
2662 		} finally {
2663 			deleteProject("Test01");
2664 		}
2665 	}
testSystemLibAsJMod_2()2666 	public void testSystemLibAsJMod_2() throws CoreException {
2667 		try {
2668 			IJavaProject project = createJava9Project("Test01", new String[]{"src"});
2669 			IClasspathEntry[] rawClasspath = project.getRawClasspath();
2670 			IClasspathEntry[] newClasspath = new IClasspathEntry[rawClasspath.length + 1];
2671 			IClasspathEntry desktop = null;
2672 			for (int i = 0; i < rawClasspath.length; i++) {
2673 				IPath path = rawClasspath[i].getPath();
2674 				if (path.lastSegment().equals("jrt-fs.jar")) {
2675 					path = path.removeLastSegments(2).append("jmods").append("java.base.jmod");
2676 					IClasspathAttribute[] attributes = {
2677 							JavaCore.newClasspathAttribute(IClasspathAttribute.MODULE, "true") };
2678 					IClasspathEntry newEntry = JavaCore.newLibraryEntry(path, rawClasspath[i].getSourceAttachmentPath(),
2679 							new Path("java.base"), null, attributes, rawClasspath[i].isExported());
2680 					newClasspath[i] = newEntry;
2681 					path = path.removeLastSegments(2).append("jmods").append("java.desktop.jmod");
2682 					desktop = JavaCore.newLibraryEntry(path, rawClasspath[i].getSourceAttachmentPath(),
2683 							new Path("java.desktop"), null, attributes, rawClasspath[i].isExported());
2684 				} else {
2685 					newClasspath[i] = rawClasspath[i];
2686 				}
2687 			}
2688 			newClasspath[rawClasspath.length] = desktop;
2689 			project.setRawClasspath(newClasspath, null);
2690 			this.createFile("Test01/src/module-info.java",
2691 					"module org.eclipse {\n" +
2692 					"	requires java.desktop;\n" +
2693 					"	requires java.base;\n" +
2694 					"}");
2695 			waitForManualRefresh();
2696 			waitForAutoBuild();
2697 			project.getProject().build(IncrementalProjectBuilder.FULL_BUILD, null);
2698 			IMarker[] markers = project.getProject().findMarkers(IJavaModelMarker.JAVA_MODEL_PROBLEM_MARKER, true, IResource.DEPTH_INFINITE);
2699 			assertMarkers("unexpected markers", "", markers);
2700 
2701 			// Check the reconciler
2702 			ICompilationUnit cu = getCompilationUnit("/Test01/src/module-info.java");
2703 			cu.getWorkingCopy(this.wcOwner, null);
2704 			markers = project.getProject().findMarkers(IJavaModelMarker.JAVA_MODEL_PROBLEM_MARKER, true, IResource.DEPTH_INFINITE);
2705 			editFile("Test01/src/module-info.java",
2706 					"//Just touching \n" +
2707 					"module org.eclipse {\n" +
2708 					"	requires java.desktop;\n" +
2709 					"	requires java.base;\n" +
2710 					"}");
2711 			project.getProject().build(IncrementalProjectBuilder.INCREMENTAL_BUILD, null);
2712 			markers = project.getProject().findMarkers(IJavaModelMarker.JAVA_MODEL_PROBLEM_MARKER, true, IResource.DEPTH_INFINITE);
2713 			assertMarkers("unexpected markers", "", markers);
2714 		} finally {
2715 			deleteProject("Test01");
2716 		}
2717 	}
testBug510617()2718 	public void testBug510617() throws CoreException {
2719 		try {
2720 			String[] src = new String[] {
2721 				"src/module-info.java",
2722 				"module Test {\n" +
2723 				"	exports p;\n" +
2724 				"	requires java.sql;\n" +
2725 				"	provides java.sql.Driver with p.C;\n" +
2726 				"}",
2727 				"src/p/C.java",
2728 				"package p;\n" +
2729 				"import java.lang.SecurityManager;\n" +
2730 				"import java.sql.Connection;\n" +
2731 				"import java.sql.Driver;\n" +
2732 				"import java.sql.DriverPropertyInfo;\n" +
2733 				"import java.sql.SQLException;\n" +
2734 				"import java.sql.SQLFeatureNotSupportedException;\n" +
2735 				"import java.util.Properties;\n" +
2736 				"import java.util.logging.Logger;\n" +
2737 				"public class C implements Driver {\n" +
2738 				"	SecurityManager s;\n" +
2739 				"	@Override\n" +
2740 				"	public boolean acceptsURL(String arg0) throws SQLException {\n" +
2741 				"		return false;\n" +
2742 				"	}\n" +
2743 				"	@Override\n" +
2744 				"	public Connection connect(String arg0, Properties arg1) throws SQLException {\n" +
2745 				"		return null;\n" +
2746 				"	}\n" +
2747 				"	@Override\n" +
2748 				"	public int getMajorVersion() {\n" +
2749 				"		return 0;\n" +
2750 				"	}\n" +
2751 				"	@Override\n" +
2752 				"	public int getMinorVersion() {\n" +
2753 				"		return 0;\n" +
2754 				"	}\n" +
2755 				"	@Override\n" +
2756 				"	public Logger getParentLogger() throws SQLFeatureNotSupportedException {\n" +
2757 				"		return null;\n" +
2758 				"	}\n" +
2759 				"	@Override\n" +
2760 				"	public DriverPropertyInfo[] getPropertyInfo(String arg0, Properties arg1) throws SQLException {\n" +
2761 				"		return null;\n" +
2762 				"	}\n" +
2763 				"	@Override\n" +
2764 				"	public boolean jdbcCompliant() {\n" +
2765 				"		return false;\n" +
2766 				"	} \n" +
2767 				"}"
2768 			};
2769 			setupModuleProject("Test", src);
2770 			this.workingCopies = new ICompilationUnit[1];
2771 			char[] sourceChars = src[1].toCharArray();
2772 			this.problemRequestor.initialize(sourceChars);
2773 			this.workingCopies[0] = getCompilationUnit("/Test/src/module-info.java").getWorkingCopy(this.wcOwner, null);
2774 			assertProblems(
2775 				"Unexpected problems",
2776 				"----------\n" +
2777 				"----------\n",
2778 				this.problemRequestor);
2779 		} finally {
2780 			deleteProject("Test");
2781 		}
2782 	}
test_annotations_in_moduleinfo()2783 	public void test_annotations_in_moduleinfo() throws CoreException {
2784 		try {
2785 			String[] sources = new String[] {
2786 					"src/module-info.java",
2787 					"module org.astro {\n" +
2788 					"	exports org.astro;\n" +
2789 					"}",
2790 					"src/org/astro/World.java",
2791 					"package org.astro;\n" +
2792 					"public interface World {\n" +
2793 					"	public String name();\n" +
2794 					"}",
2795 					"src/org/astro/Foo.java",
2796 					"package org.astro;\n" +
2797 					"public @interface Foo {}"
2798 			};
2799 			IJavaProject p1 = setupModuleProject("org.astro", sources);
2800 			IClasspathAttribute modAttr = new ClasspathAttribute("module", "true");
2801 			IClasspathEntry dep = JavaCore.newProjectEntry(p1.getPath(), null, false,
2802 				new IClasspathAttribute[] {modAttr},
2803 				false/*not exported*/);
2804 			String[] src = new String[] {
2805 					"src/module-info.java",
2806 					"import org.astro.Foo;\n" +
2807 					"import org.astro.World;\n" +
2808 					"@Foo\n" +
2809 					"module com.greetings {\n" +
2810 					"	requires org.astro;\n" +
2811 					"	exports com.greetings;\n" +
2812 					"	provides World with com.greetings.MyWorld;\n" +
2813 					"}",
2814 					"src/com/greetings/MyWorld.java",
2815 					"package com.greetings;\n" +
2816 					"import org.astro.World;\n"	+
2817 					"public class MyWorld implements World {\n" +
2818 					"	public String name() {\n" +
2819 					"		return \" My World!!\";\n" +
2820 					"	}\n" +
2821 					"}"
2822 			};
2823 			IJavaProject p2 = setupModuleProject("com.greetings", src, new IClasspathEntry[] { dep });
2824 			p2.getProject().getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, null);
2825 			IMarker[] markers = p2.getProject().findMarkers(null, true, IResource.DEPTH_INFINITE);
2826 			assertMarkers("Unexpected markers", "", markers);
2827 		} finally {
2828 			deleteProject("org.astro");
2829 			deleteProject("com.greetings");
2830 		}
2831 	}
test_unresolved_annotations()2832 	public void test_unresolved_annotations() throws CoreException {
2833 		try {
2834 			String[] sources = new String[] {
2835 					"src/module-info.java",
2836 					"module org.astro {\n" +
2837 					"	exports org.astro;\n" +
2838 					"}",
2839 					"src/org/astro/World.java",
2840 					"package org.astro;\n" +
2841 					"public interface World {\n" +
2842 					"	public String name();\n" +
2843 					"}",
2844 					"src/org/astro/Foo.java",
2845 					"package org.astro;\n" +
2846 					"public @interface Foo {}"
2847 			};
2848 			IJavaProject p1 = setupModuleProject("org.astro", sources);
2849 			IClasspathAttribute modAttr = new ClasspathAttribute("module", "true");
2850 			IClasspathEntry dep = JavaCore.newProjectEntry(p1.getPath(), null, false,
2851 				new IClasspathAttribute[] {modAttr},
2852 				false/*not exported*/);
2853 			String[] src = new String[] {
2854 					"src/module-info.java",
2855 					"import org.astro.Foo;\n" +
2856 					"import org.astro.World;\n" +
2857 					"@Foo @Bar\n" +
2858 					"module com.greetings {\n" +
2859 					"	requires org.astro;\n" +
2860 					"	exports com.greetings;\n" +
2861 					"	provides World with com.greetings.MyWorld;\n" +
2862 					"}",
2863 					"src/com/greetings/MyWorld.java",
2864 					"package com.greetings;\n" +
2865 					"import org.astro.World;\n"	+
2866 					"public class MyWorld implements World {\n" +
2867 					"	public String name() {\n" +
2868 					"		return \" My World!!\";\n" +
2869 					"	}\n" +
2870 					"}"
2871 			};
2872 			IJavaProject p2 = setupModuleProject("com.greetings", src, new IClasspathEntry[] { dep });
2873 			p2.getProject().getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, null);
2874 			IMarker[] markers = p2.getProject().findMarkers(null, true, IResource.DEPTH_INFINITE);
2875 			assertMarkers("Unexpected markers",
2876 					"Bar cannot be resolved to a type", markers);
2877 		} finally {
2878 			deleteProject("org.astro");
2879 			deleteProject("com.greetings");
2880 		}
2881 	}
test_illegal_modifiers()2882 	public void test_illegal_modifiers() throws CoreException {
2883 		try {
2884 			String[] sources = new String[] {
2885 					"src/module-info.java",
2886 					"module org.astro {\n" +
2887 					"	exports org.astro;\n" +
2888 					"}",
2889 					"src/org/astro/World.java",
2890 					"package org.astro;\n" +
2891 					"public interface World {\n" +
2892 					"	public String name();\n" +
2893 					"}",
2894 					"src/org/astro/Foo.java",
2895 					"package org.astro;\n" +
2896 					"public @interface Foo {}"
2897 			};
2898 			IJavaProject p1 = setupModuleProject("org.astro", sources);
2899 			IClasspathAttribute modAttr = new ClasspathAttribute("module", "true");
2900 			IClasspathEntry dep = JavaCore.newProjectEntry(p1.getPath(), null, false,
2901 				new IClasspathAttribute[] {modAttr},
2902 				false/*not exported*/);
2903 			String[] src = new String[] {
2904 					"src/module-info.java",
2905 					"import org.astro.Foo;\n" +
2906 					"import org.astro.World;\n" +
2907 					"@Foo\n" +
2908 					"private static module com.greetings {\n" +
2909 					"	requires org.astro;\n" +
2910 					"	exports com.greetings;\n" +
2911 					"	provides World with com.greetings.MyWorld;\n" +
2912 					"}",
2913 					"src/com/greetings/MyWorld.java",
2914 					"package com.greetings;\n" +
2915 					"import org.astro.World;\n"	+
2916 					"public class MyWorld implements World {\n" +
2917 					"	public String name() {\n" +
2918 					"		return \" My World!!\";\n" +
2919 					"	}\n" +
2920 					"}"
2921 			};
2922 			IJavaProject p2 = setupModuleProject("com.greetings", src, new IClasspathEntry[] { dep });
2923 			p2.getProject().getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, null);
2924 			IMarker[] markers = p2.getProject().findMarkers(null, true, IResource.DEPTH_INFINITE);
2925 			assertMarkers("Unexpected markers",
2926 					"Illegal modifier for module com.greetings; only open is permitted", markers);
2927 		} finally {
2928 			deleteProject("org.astro");
2929 			deleteProject("com.greetings");
2930 		}
2931 	}
test_annotations_with_target()2932 	public void test_annotations_with_target() throws CoreException {
2933 		try {
2934 			String[] sources = new String[] {
2935 					"src/module-info.java",
2936 					"module org.astro {\n" +
2937 					"	exports org.astro;\n" +
2938 					"}",
2939 					"src/org/astro/World.java",
2940 					"package org.astro;\n" +
2941 					"public interface World {\n" +
2942 					"	public String name();\n" +
2943 					"}",
2944 					"src/org/astro/Foo.java",
2945 					"package org.astro;\n" +
2946 					"import java.lang.annotation.ElementType;\n" +
2947 					"import java.lang.annotation.Target;\n" +
2948 					"@Target(ElementType.MODULE)\n" +
2949 					"public @interface Foo {}"
2950 			};
2951 			IJavaProject p1 = setupModuleProject("org.astro", sources);
2952 			IClasspathAttribute modAttr = new ClasspathAttribute("module", "true");
2953 			IClasspathEntry dep = JavaCore.newProjectEntry(p1.getPath(), null, false,
2954 				new IClasspathAttribute[] {modAttr},
2955 				false/*not exported*/);
2956 			String[] src = new String[] {
2957 					"src/module-info.java",
2958 					"import org.astro.Foo;\n" +
2959 					"import org.astro.World;\n" +
2960 					"@Foo\n" +
2961 					"module com.greetings {\n" +
2962 					"	requires org.astro;\n" +
2963 					"	exports com.greetings;\n" +
2964 					"	provides World with com.greetings.MyWorld;\n" +
2965 					"}",
2966 					"src/com/greetings/MyWorld.java",
2967 					"package com.greetings;\n" +
2968 					"import org.astro.World;\n"	+
2969 					"public class MyWorld implements World {\n" +
2970 					"	public String name() {\n" +
2971 					"		return \" My World!!\";\n" +
2972 					"	}\n" +
2973 					"}"
2974 			};
2975 			IJavaProject p2 = setupModuleProject("com.greetings", src, new IClasspathEntry[] { dep });
2976 			p2.getProject().getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, null);
2977 			IMarker[] markers = p2.getProject().findMarkers(null, true, IResource.DEPTH_INFINITE);
2978 			assertMarkers("Unexpected markers", "", markers);
2979 		} finally {
2980 			deleteProject("org.astro");
2981 			deleteProject("com.greetings");
2982 		}
2983 	}
test_annotations_with_wrong_target()2984 	public void test_annotations_with_wrong_target() throws CoreException {
2985 		try {
2986 			String[] sources = new String[] {
2987 					"src/module-info.java",
2988 					"module org.astro {\n" +
2989 					"	exports org.astro;\n" +
2990 					"}",
2991 					"src/org/astro/World.java",
2992 					"package org.astro;\n" +
2993 					"public interface World {\n" +
2994 					"	public String name();\n" +
2995 					"}",
2996 					"src/org/astro/Foo.java",
2997 					"package org.astro;\n" +
2998 					"import java.lang.annotation.ElementType;\n" +
2999 					"import java.lang.annotation.Target;\n" +
3000 					"@Target({ElementType.TYPE_PARAMETER, ElementType.TYPE})\n" +
3001 					"public @interface Foo {}"
3002 			};
3003 			IJavaProject p1 = setupModuleProject("org.astro", sources);
3004 			IClasspathAttribute modAttr = new ClasspathAttribute("module", "true");
3005 			IClasspathEntry dep = JavaCore.newProjectEntry(p1.getPath(), null, false,
3006 				new IClasspathAttribute[] {modAttr},
3007 				false/*not exported*/);
3008 			String[] src = new String[] {
3009 					"src/module-info.java",
3010 					"import org.astro.Foo;\n" +
3011 					"import org.astro.World;\n" +
3012 					"@Foo\n" +
3013 					"module com.greetings {\n" +
3014 					"	requires org.astro;\n" +
3015 					"	exports com.greetings;\n" +
3016 					"	provides World with com.greetings.MyWorld;\n" +
3017 					"}",
3018 					"src/com/greetings/MyWorld.java",
3019 					"package com.greetings;\n" +
3020 					"import org.astro.World;\n"	+
3021 					"public class MyWorld implements World {\n" +
3022 					"	public String name() {\n" +
3023 					"		return \" My World!!\";\n" +
3024 					"	}\n" +
3025 					"}"
3026 			};
3027 			IJavaProject p2 = setupModuleProject("com.greetings", src, new IClasspathEntry[] { dep });
3028 			p2.getProject().getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, null);
3029 			IMarker[] markers = p2.getProject().findMarkers(null, true, IResource.DEPTH_INFINITE);
3030 			assertMarkers("Unexpected markers",
3031 					"The annotation @Foo is disallowed for this location", markers);
3032 		} finally {
3033 			deleteProject("org.astro");
3034 			deleteProject("com.greetings");
3035 		}
3036 	}
testBug518334()3037 	public void testBug518334() throws CoreException, IOException {
3038 		try {
3039 			String[] sources = new String[] {
3040 					"src/module-info.java",
3041 					"module org.astro {\n" +
3042 					"	requires java.sql;\n" +
3043 					"}"
3044 			};
3045 			IJavaProject p1 = setupModuleProject("org.astro", sources);
3046 			waitForAutoBuild();
3047 			// set options
3048 			Map<String, String> options = new HashMap<>();
3049 			options.put(CompilerOptions.OPTION_Compliance, "1.8");
3050 			options.put(CompilerOptions.OPTION_Source, "1.8");
3051 			options.put(CompilerOptions.OPTION_TargetPlatform, "1.8");
3052 			p1.setOptions(options);
3053 //			waitForAutoBuild();
3054 			p1.getProject().getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, null);
3055 			IMarker[] markers = p1.getProject().findMarkers(null, true, IResource.DEPTH_INFINITE);
3056 			assertTrue("Module declaration incorrectly accepted below 9", markers.length > 0);
3057 		} finally {
3058 			deleteProject("org.astro");
3059 		}
3060 	}
testBug518334a()3061 	public void testBug518334a() throws CoreException {
3062 		try {
3063 			String[] sources = new String[] {
3064 					"src/module-info.java",
3065 					"module org.astro {\n" +
3066 					"	exports org.astro;\n" +
3067 					"}",
3068 					"src/org/astro/World.java",
3069 					"package org.astro;\n" +
3070 					"public interface World {\n" +
3071 					"	public String name();\n" +
3072 					"}"
3073 			};
3074 			IJavaProject p1 = setupModuleProject("org.astro", sources);
3075 			IClasspathEntry dep = JavaCore.newProjectEntry(p1.getPath());
3076 			String[] src = new String[] {
3077 					"src/module-info.java",
3078 					"module com.greetings {\n" +
3079 					"	requires org.astro;\n" +
3080 					"}"
3081 			};
3082 			IJavaProject p2 = setupModuleProject("com.greetings", src, new IClasspathEntry[] { dep });
3083 			waitForAutoBuild();
3084 			// set options
3085 			Map<String, String> options = new HashMap<>();
3086 			options.put(CompilerOptions.OPTION_Compliance, "1.8");
3087 			options.put(CompilerOptions.OPTION_Source, "1.8");
3088 			options.put(CompilerOptions.OPTION_TargetPlatform, "1.8");
3089 			p1.setOptions(options);
3090 
3091 			p2.getProject().getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, null);
3092 			IMarker[] markers = p2.getProject().findMarkers(null, true, IResource.DEPTH_INFINITE);
3093 			assertMarkers("Unexpected markers",
3094 					"org.astro cannot be resolved to a module", markers);
3095 		} finally {
3096 			deleteProject("org.astro");
3097 			deleteProject("com.greetings");
3098 		}
3099 	}
3100 
test_api_leak_1()3101 	public void test_api_leak_1() throws CoreException {
3102 		try {
3103 			String[] sources1 = {
3104 								"src/module-info.java",
3105 								"module mod.one { \n" +
3106 								"	exports pm;\n" +
3107 								"}",
3108 								"src/impl/Other.java",
3109 								"package impl;\n" +
3110 								"public class Other {\n" +
3111 								"}\n",
3112 								"src/pm/C1.java",
3113 								"package pm;\n" +
3114 								"import impl.Other;\n" +
3115 								"public class C1 extends Other {\n" +
3116 								"	public void m1(Other o) {}\n" +
3117 								"}\n"
3118 							};
3119 			IJavaProject p1 = setupModuleProject("mod.one", sources1);
3120 			IClasspathAttribute modAttr = new ClasspathAttribute("module", "true");
3121 			IClasspathEntry dep = JavaCore.newProjectEntry(p1.getPath(), null, false,
3122 				new IClasspathAttribute[] {modAttr},
3123 				false/*not exported*/);
3124 			p1.getProject().getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, null);
3125 
3126 			String[] sources2 = {
3127 								"src/module-info.java",
3128 								"module mod.two { \n" +
3129 								"	requires mod.one;\n" +
3130 								"}",
3131 								"src/impl/Other.java",
3132 								"package impl;\n" +
3133 								"public class Other {\n" +
3134 								"}\n",
3135 								"src/po/Client.java",
3136 								"package po;\n" +
3137 								"import pm.C1;\n" +
3138 								"public class Client {\n" +
3139 								"    void test1(C1 one) {\n" +
3140 								"        one.m1(one);\n" +
3141 								"    }\n" +
3142 								"}\n"
3143 							};
3144 			IJavaProject p2 = setupModuleProject("mod.two", sources2, new IClasspathEntry[] { dep });
3145 			p2.getProject().getWorkspace().build(IncrementalProjectBuilder.INCREMENTAL_BUILD, null);
3146 			IMarker[] markers = p2.getProject().findMarkers(null, true, IResource.DEPTH_INFINITE);
3147 			assertMarkers("Unexpected markers", "", markers);
3148 
3149 			p2.getProject().getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, null);
3150 			markers = p2.getProject().findMarkers(null, true, IResource.DEPTH_INFINITE);
3151 			assertMarkers("Unexpected markers", "", markers);
3152 		} finally {
3153 			deleteProject("mod.one");
3154 			deleteProject("mod.two");
3155 		}
3156 	}
3157 
3158 	/**
3159 	 * Same-named classes should not conflict, since one is not accessible.
3160 	 * Still a sub class of the inaccessible class can be accessed and used for a method argument.
3161 	 */
test_api_leak_2()3162 	public void test_api_leak_2() throws CoreException {
3163 		try {
3164 			String[] sources1 = {
3165 						"src/module-info.java",
3166 						"module mod.one { \n" +
3167 						"	exports pm;\n" +
3168 						"}",
3169 						"src/impl/SomeImpl.java",
3170 						"package impl;\n" +
3171 								"public class SomeImpl {\n" +
3172 						"}\n",
3173 						"src/pm/C1.java",
3174 						"package pm;\n" +
3175 						"import impl.SomeImpl;\n" +
3176 						"public class C1 {\n" +
3177 						"	public void m1(SomeImpl o) {}\n" +
3178 						"}\n",
3179 						"src/pm/Other.java",
3180 						"package pm;\n" +
3181 								"import impl.SomeImpl;\n" +
3182 								"public class Other extends SomeImpl {\n" +
3183 						"}\n"
3184 					};
3185 			IJavaProject p1 = setupModuleProject("mod.one", sources1);
3186 			IClasspathAttribute modAttr = new ClasspathAttribute("module", "true");
3187 			IClasspathEntry dep = JavaCore.newProjectEntry(p1.getPath(), null, false,
3188 				new IClasspathAttribute[] {modAttr},
3189 				false/*not exported*/);
3190 			p1.getProject().getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, null);
3191 
3192 			String[] sources2 = {
3193 						"src/module-info.java",
3194 						"module mod.two { \n" +
3195 						"	requires mod.one;\n" +
3196 						"}",
3197 						"src/impl/SomeImpl.java",
3198 						"package impl;\n" +
3199 								"public class SomeImpl {\n" + // pseudo-conflict to same named, but inaccessible class from mod.one
3200 						"}\n",
3201 						"src/po/Client.java",
3202 						"package po;\n" +
3203 						"import pm.C1;\n" +
3204 						"import pm.Other;\n" +
3205 						"import impl.SomeImpl;\n" +
3206 						"public class Client {\n" +
3207 						"    void test1(C1 one) {\n" +
3208 						"		 SomeImpl impl = new SomeImpl();\n" + // our own version
3209 						"        one.m1(impl);\n" + // incompatible to what's required
3210 						"		 one.m1(new Other());\n" + // OK
3211 						"    }\n" +
3212 						"}\n",
3213 					};
3214 			String expectedError = "The method m1(impl.SomeImpl) in the type C1 is not applicable for the arguments (impl.SomeImpl)";
3215 			IJavaProject p2 = setupModuleProject("mod.two", sources2, new IClasspathEntry[] { dep });
3216 			p2.getProject().getWorkspace().build(IncrementalProjectBuilder.INCREMENTAL_BUILD, null);
3217 			IMarker[] markers = p2.getProject().findMarkers(null, true, IResource.DEPTH_INFINITE);
3218 			assertMarkers("Unexpected markers", expectedError, markers);
3219 
3220 			p2.getProject().getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, null);
3221 			markers = p2.getProject().findMarkers(null, true, IResource.DEPTH_INFINITE);
3222 			assertMarkers("Unexpected markers", expectedError, markers);
3223 		} finally {
3224 			deleteProject("mod.one");
3225 			deleteProject("mod.two");
3226 		}
3227 	}
3228 
testNonPublic1()3229 	public void testNonPublic1() throws CoreException {
3230 		try {
3231 			String[] sources1 = {
3232 					"src/module-info.java",
3233 					"module mod.one { \n" +
3234 					"	exports pm;\n" +
3235 					"}",
3236 					"src/pm/C1.java",
3237 					"package pm;\n" +
3238 					"class C1 {\n" +
3239 					"	public void test() {}\n" +
3240 					"}\n"
3241 			};
3242 			IJavaProject p1 = setupModuleProject("mod.one", sources1);
3243 			IClasspathAttribute modAttr = new ClasspathAttribute("module", "true");
3244 			IClasspathEntry dep = JavaCore.newProjectEntry(p1.getPath(), null, false,
3245 				new IClasspathAttribute[] {modAttr},
3246 				false/*not exported*/);
3247 			p1.getProject().getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, null);
3248 
3249 			String[] sources2 = {
3250 					"src/module-info.java",
3251 					"module mod.two { \n" +
3252 					"	requires mod.one;\n" +
3253 					"}",
3254 					"src/pm/sub/C2.java",
3255 					"package pm.sub;\n" +
3256 					"class C2 {\n" +
3257 					"	public void foo() {}\n" +
3258 					"}\n",
3259 					"src/po/Client.java",
3260 					"package po;\n" +
3261 					"import pm.*;\n" + // package is exported but type C1 is not public
3262 					"public class Client {\n" +
3263 					"    void test1(C1 one) {\n" +
3264 					"        one.test();\n" +
3265 					"    }\n" +
3266 					"}\n"
3267 			};
3268 
3269 			IJavaProject p2 = setupModuleProject("mod.two", sources2, new IClasspathEntry[] { dep });
3270 			this.workingCopies = new ICompilationUnit[3];
3271 			this.workingCopies[0] = getCompilationUnit("/mod.two/src/module-info.java").getWorkingCopy(this.wcOwner, null);
3272 			this.workingCopies[1] = getCompilationUnit("/mod.two/src/pm/sub/C2.java").getWorkingCopy(this.wcOwner, null);
3273 			this.problemRequestor.initialize(sources2[5].toCharArray());
3274 			this.workingCopies[2] = getCompilationUnit("/mod.two/src/po/Client.java").getWorkingCopy(this.wcOwner, null);
3275 			assertProblems(
3276 					"Unexpected problems",
3277 					"----------\n" +
3278 					"1. ERROR in /mod.two/src/po/Client.java (at line 4)\n" +
3279 					"	void test1(C1 one) {\n" +
3280 					"	           ^^\n" +
3281 					"The type C1 is not visible\n" +
3282 					"----------\n" +
3283 					"2. ERROR in /mod.two/src/po/Client.java (at line 5)\n" +
3284 					"	one.test();\n" +
3285 					"	^^^\n" +
3286 					"The type C1 is not visible\n" +
3287 					"----------\n",
3288 					this.problemRequestor);
3289 
3290 			String expectedError = "The type C1 is not visible\n" +
3291 									"The type C1 is not visible";
3292 			p2.getProject().getWorkspace().build(IncrementalProjectBuilder.INCREMENTAL_BUILD, null);
3293 			IMarker[] markers = p2.getProject().findMarkers(null, true, IResource.DEPTH_INFINITE);
3294 			assertMarkers("Unexpected markers", expectedError, markers);
3295 
3296 			p2.getProject().getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, null);
3297 			markers = p2.getProject().findMarkers(null, true, IResource.DEPTH_INFINITE);
3298 			assertMarkers("Unexpected markers", expectedError, markers);
3299 		} finally {
3300 			deleteProject("mod.one");
3301 			deleteProject("mod.two");
3302 		}
3303 	}
3304 	// test that two packages with the same name result in conflict if they are both
3305 	// accessible to a module
test_conflicting_packages()3306 	public void test_conflicting_packages() throws CoreException {
3307 		try {
3308 			String[] sources = new String[] {
3309 				"src/module-info.java",
3310 				"module some.mod {\n" +
3311 				"	exports org.astro;\n" +
3312 				"}",
3313 				"src/org/astro/Test.java",
3314 				"package org.astro;\n" +
3315 				"public class Test { }"
3316 			};
3317 			IClasspathEntry dep = JavaCore.newContainerEntry(new Path(JavaCore.MODULE_PATH_CONTAINER_ID));
3318 			setupModuleProject("some.mod", sources, new IClasspathEntry[]{dep});
3319 			sources = new String[] {
3320 				"src/module-info.java",
3321 				"module org.astro {\n" +
3322 				"	exports org.astro;\n" +
3323 				"}",
3324 				"src/org/astro/World.java",
3325 				"package org.astro;\n" +
3326 				"public interface World {\n" +
3327 				"	public String name();\n" +
3328 				"}"
3329 			};
3330 			setupModuleProject("org.astro", sources, new IClasspathEntry[]{dep});
3331 			String[] src = new String[] {
3332 				"src/module-info.java",
3333 				"module com.greetings {\n" +
3334 				"	requires some.mod;\n" +
3335 				"	requires org.astro;\n" +
3336 				"	exports com.greetings;\n" +
3337 				"}",
3338 				"src/com/greetings/MyWorld.java",
3339 				"package com.greetings;\n" +
3340 				"import org.astro.World;\n" +
3341 				"public class MyWorld implements World {\n" +
3342 				"	public String name() {\n" +
3343 				"		return \" My World!!\";\n" +
3344 				"	}\n" +
3345 				"}"
3346 			};
3347 
3348 			IJavaProject p2 = setupModuleProject("com.greetings", src, new IClasspathEntry[] { dep });
3349 			p2.getProject().getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, null);
3350 			IMarker[] markers = p2.getProject().findMarkers(null, true, IResource.DEPTH_INFINITE);
3351 			sortMarkers(markers);
3352 			assertMarkers("Unexpected markers",
3353 					// reported against both 'requires' directives & against the import:
3354 					"The package org.astro is accessible from more than one module: org.astro, some.mod\n" +
3355 					"The package org.astro is accessible from more than one module: org.astro, some.mod\n" +
3356 					"The package org.astro is accessible from more than one module: org.astro, some.mod\n" +
3357 					"World cannot be resolved to a type",
3358 					markers);
3359 		} finally {
3360 			deleteProject("org.astro");
3361 			deleteProject("some.mod");
3362 			deleteProject("com.greetings");
3363 		}
3364 	}
3365 
3366 	// test that the compilation of a class using same package defined in the java.util module
3367 	// works if a special option is given
test_no_conflicting_packages_for_debugger_global()3368 	public void test_no_conflicting_packages_for_debugger_global() throws CoreException {
3369 		Hashtable<String, String> javaCoreOptions = JavaCore.getOptions();
3370 		try {
3371 			Hashtable<String, String> newOptions=new Hashtable<>(javaCoreOptions);
3372 			newOptions.put(CompilerOptions.OPTION_JdtDebugCompileMode, JavaCore.ENABLED);
3373 			JavaCore.setOptions(newOptions);
3374 			String[] sources = new String[] {
3375 					"src/java/util/Map___.java",
3376 					"package java.util;\n" +
3377 					"abstract class Map___ implements java.util.Map {\n" +
3378 					"  Map___() {\n" +
3379 					"    super();\n" +
3380 					"  }\n" +
3381 					"  Object[] ___run() throws Throwable {\n" +
3382 					"    return entrySet().toArray();\n" +
3383 					"  }\n" +
3384 					"}"
3385 			};
3386 			IClasspathEntry dep = JavaCore.newContainerEntry(new Path(JavaCore.MODULE_PATH_CONTAINER_ID));
3387 			IJavaProject p1= setupModuleProject("debugger_project", sources, new IClasspathEntry[]{dep});
3388 			p1.getProject().getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, null);
3389 			assertNoErrors();
3390 
3391 			assertNull("Option should not be stored", JavaCore.getOption(CompilerOptions.OPTION_JdtDebugCompileMode));
3392 		} finally {
3393 			deleteProject("debugger_project");
3394 			JavaCore.setOptions(javaCoreOptions);
3395 		}
3396 	}
3397 
3398 	// test that the special OPTION_JdtDebugCompileMode cannot be persisted on a project
test_no_conflicting_packages_for_debugger_project()3399 	public void test_no_conflicting_packages_for_debugger_project() throws CoreException {
3400 		try {
3401 			String[] sources = new String[] {
3402 					"src/java/util/Map___.java",
3403 					"package java.util;\n" +
3404 					"abstract class Map___ implements java.util.Map {\n" +
3405 					"  Map___() {\n" +
3406 					"    super();\n" +
3407 					"  }\n" +
3408 					"  Object[] ___run() throws Throwable {\n" +
3409 					"    return entrySet().toArray();\n" +
3410 					"  }\n" +
3411 					"}"
3412 			};
3413 			IClasspathEntry dep = JavaCore.newContainerEntry(new Path(JavaCore.MODULE_PATH_CONTAINER_ID));
3414 			IJavaProject p1= setupModuleProject("debugger_project", sources, new IClasspathEntry[]{dep});
3415 			p1.setOption(CompilerOptions.OPTION_JdtDebugCompileMode, JavaCore.ENABLED);
3416 			assertNull("Option should not be stored", p1.getOption(CompilerOptions.OPTION_JdtDebugCompileMode, false));
3417 			p1.getProject().getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, null);
3418 			IMarker[] markers = p1.getProject().findMarkers(null, true, IResource.DEPTH_INFINITE);
3419 			sortMarkers(markers);
3420 			assertMarkers("Unexpected markers",
3421 					"The package java.util conflicts with a package accessible from another module: java.base\n" +
3422 					"The package java.util is accessible from more than one module: <unnamed>, java.base\n" +
3423 					"The method entrySet() is undefined for the type Map___",
3424 					markers);
3425 		} finally {
3426 			deleteProject("debugger_project");
3427 		}
3428 	}
3429 
3430 	// test that a package declared in a module conflicts with an accessible package
3431 	// of the same name declared in another required module
test_conflicting_packages_declaredvsaccessible()3432 	public void test_conflicting_packages_declaredvsaccessible() throws CoreException {
3433 		try {
3434 			IClasspathEntry dep = JavaCore.newContainerEntry(new Path(JavaCore.MODULE_PATH_CONTAINER_ID));
3435 			String[] sources = new String[] {
3436 				"src/module-info.java",
3437 				"module org.astro {\n" +
3438 				"	exports org.astro;\n" +
3439 				"}",
3440 				"src/org/astro/World.java",
3441 				"package org.astro;\n" +
3442 				"public interface World {\n" +
3443 				"	public String name();\n" +
3444 				"}"
3445 			};
3446 			setupModuleProject("org.astro", sources, new IClasspathEntry[]{dep});
3447 			String[] src = new String[] {
3448 				"src/module-info.java",
3449 				"module com.greetings {\n" +
3450 				"	requires org.astro;\n" +
3451 				"	exports com.greetings;\n" +
3452 				"}",
3453 				"src/org/astro/Test.java",
3454 				"package org.astro;\n" +
3455 				"public class Test {\n" +
3456 				"	public String name() {\n" +
3457 				"		return \" My World!!\";\n" +
3458 				"	}\n" +
3459 				"}",
3460 				"src/com/greetings/MyWorld.java",
3461 				"package com.greetings;\n" +
3462 				"public class MyWorld implements org.astro.World {\n" +
3463 				"	public String name() {\n" +
3464 				"		return \" My World!!\";\n" +
3465 				"	}\n" +
3466 				"}"
3467 			};
3468 			IJavaProject p2 = setupModuleProject("com.greetings", src, new IClasspathEntry[] { dep });
3469 			p2.getProject().getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, null);
3470 			IMarker[] markers = p2.getProject().findMarkers(null, true, IResource.DEPTH_INFINITE);
3471 			sortMarkers(markers);
3472 			assertMarkers("Unexpected markers",
3473 					"The package org.astro conflicts with a package accessible from another module: org.astro\n" +
3474 					"The package org.astro is accessible from more than one module: com.greetings, org.astro",
3475 					markers);
3476 		} finally {
3477 			deleteProject("org.astro");
3478 			deleteProject("com.greetings");
3479 		}
3480 	}
3481 	// accessible package bundle.org contains type astro
3482 	// accessible package bundle.org.astro contains type World
3483 	// Type bundle.org.astro.World should not be resolved, because type
3484 	// bundle.org.astro trumps package bundle.org.astro
test_conflict_packagevstype()3485 	public void test_conflict_packagevstype() throws CoreException {
3486 		try {
3487 			IClasspathEntry dep = JavaCore.newContainerEntry(new Path(JavaCore.MODULE_PATH_CONTAINER_ID));
3488 			String[] sources = new String[] {
3489 				"src/module-info.java",
3490 				"module org.astro {\n" +
3491 				"	exports bundle.org.astro;\n" +
3492 				"}",
3493 				"src/bundle/org/astro/World.java",
3494 				"package bundle.org.astro;\n" +
3495 				"public interface World {\n" +
3496 				"	public String name();\n" +
3497 				"}"
3498 			};
3499 			setupModuleProject("org.astro", sources, new IClasspathEntry[]{dep});
3500 			sources = new String[] {
3501 					"src/module-info.java",
3502 					"module other.mod {\n" +
3503 					"	exports bundle.org;\n" +
3504 					"}",
3505 					"src/bundle/org/astro.java",
3506 					"package bundle.org;\n" +
3507 					"public class astro {}"
3508 				};
3509 			setupModuleProject("other.mod", sources, new IClasspathEntry[]{dep});
3510 			String[] src = new String[] {
3511 				"src/module-info.java",
3512 				"module com.greetings {\n" +
3513 				"	requires org.astro;\n" +
3514 				"	requires other.mod;\n" +
3515 				"	exports com.greetings;\n" +
3516 				"}",
3517 				"src/com/greetings/MyWorld.java",
3518 				"package com.greetings;\n" +
3519 				"public class MyWorld implements bundle.org.astro.World {\n" +
3520 				"	public String name() {\n" +
3521 				"		return \" My World!!\";\n" +
3522 				"	}\n" +
3523 				"}"
3524 			};
3525 			IJavaProject p2 = setupModuleProject("com.greetings", src, new IClasspathEntry[] { dep });
3526 			p2.getProject().getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, null);
3527 			IMarker[] markers = p2.getProject().findMarkers(null, true, IResource.DEPTH_INFINITE);
3528 			assertMarkers("Unexpected markers",
3529 					"bundle.org.astro.World cannot be resolved to a type",  markers);
3530 		} finally {
3531 			deleteProject("org.astro");
3532 			deleteProject("other.mod");
3533 			deleteProject("com.greetings");
3534 		}
3535 	}
3536 	// package bundle.org contains type astro, but the package is not accessible
3537 	// accessible package bundle.org.astro contains type World
3538 	// type bundle.org.astro.World should be resolved because type bundle.org.astro
3539 	// cannot be seen
3540 	// TODO - to be confirmed with spec
test_noconflict_concealedtype_accessiblepackage()3541 	public void test_noconflict_concealedtype_accessiblepackage() throws CoreException {
3542 		try {
3543 			IClasspathEntry dep = JavaCore.newContainerEntry(new Path(JavaCore.MODULE_PATH_CONTAINER_ID));
3544 			String[] sources = new String[] {
3545 				"src/module-info.java",
3546 				"module org.astro {\n" +
3547 				"	exports bundle.org.astro;\n" +
3548 				"}",
3549 				"src/bundle/org/astro/World.java",
3550 				"package bundle.org.astro;\n" +
3551 				"public interface World {\n" +
3552 				"	public String name();\n" +
3553 				"}"
3554 			};
3555 			setupModuleProject("org.astro", sources, new IClasspathEntry[]{dep});
3556 			sources = new String[] {
3557 					"src/module-info.java",
3558 					"module other.mod {\n" +
3559 					"}",
3560 					"src/bundle/org/astro.java",
3561 					"package bundle.org;\n" +
3562 					"public class astro {}"
3563 				};
3564 			setupModuleProject("other.mod", sources, new IClasspathEntry[]{dep});
3565 			String[] src = new String[] {
3566 				"src/module-info.java",
3567 				"module com.greetings {\n" +
3568 				"	requires org.astro;\n" +
3569 				"	requires other.mod;\n" +
3570 				"	exports com.greetings;\n" +
3571 				"}",
3572 				"src/com/greetings/MyWorld.java",
3573 				"package com.greetings;\n" +
3574 				"public class MyWorld implements bundle.org.astro.World {\n" +
3575 				"	public String name() {\n" +
3576 				"		return \" My World!!\";\n" +
3577 				"	}\n" +
3578 				"}"
3579 			};
3580 			IJavaProject p2 = setupModuleProject("com.greetings", src, new IClasspathEntry[] { dep });
3581 			p2.getProject().getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, null);
3582 			IMarker[] markers = p2.getProject().findMarkers(null, true, IResource.DEPTH_INFINITE);
3583 			assertMarkers("Unexpected markers",	"",  markers);
3584 		} finally {
3585 			deleteProject("org.astro");
3586 			deleteProject("other.mod");
3587 			deleteProject("com.greetings");
3588 		}
3589 	}
3590 	// test that two packages of the same name exported by two named modules result in
3591 	// a conflict in the context of a non-modular project
test_conflicting_packages_unnamed()3592 	public void test_conflicting_packages_unnamed() throws CoreException {
3593 		try {
3594 			String[] sources = new String[] {
3595 				"src/module-info.java",
3596 				"module some.mod {\n" +
3597 				"	exports org.astro;\n" +
3598 				"}",
3599 				"src/org/astro/Test.java",
3600 				"package org.astro;\n" +
3601 				"public class Test { }"
3602 			};
3603 			IClasspathEntry dep = JavaCore.newContainerEntry(new Path(JavaCore.MODULE_PATH_CONTAINER_ID));
3604 			IJavaProject p1 = setupModuleProject("some.mod", sources, new IClasspathEntry[]{dep});
3605 			sources = new String[] {
3606 				"src/module-info.java",
3607 				"module org.astro {\n" +
3608 				"	exports org.astro;\n" +
3609 				"}",
3610 				"src/org/astro/World.java",
3611 				"package org.astro;\n" +
3612 				"public interface World {\n" +
3613 				"	public String name();\n" +
3614 				"}"
3615 			};
3616 			IJavaProject p2 = setupModuleProject("org.astro", sources, new IClasspathEntry[]{dep});
3617 			String[] src = new String[] {
3618 				"src/com/greetings/MyWorld.java",
3619 				"package com.greetings;\n" +
3620 				"import org.astro.World;\n" +
3621 				"public class MyWorld implements World {\n" +
3622 				"	public String name() {\n" +
3623 				"		return \" My World!!\";\n" +
3624 				"	}\n" +
3625 				"}"
3626 			};
3627 			IClasspathAttribute modAttr = new ClasspathAttribute("module", "true");
3628 			IClasspathEntry dep1 = JavaCore.newProjectEntry(p1.getPath(), null, false,
3629 				new IClasspathAttribute[] {modAttr},
3630 				false/*not exported*/);
3631 			IClasspathEntry dep2 = JavaCore.newProjectEntry(p2.getPath(), null, false,
3632 				new IClasspathAttribute[] {modAttr},
3633 				false/*not exported*/);
3634 			IJavaProject p3 = setupModuleProject("com.greetings", src, new IClasspathEntry[] { dep1, dep2 });
3635 			getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, null);
3636 			IMarker[] markers = p3.getProject().findMarkers(null, true, IResource.DEPTH_INFINITE);
3637 			sortMarkers(markers);
3638 			assertMarkers("Unexpected markers",
3639 					"The package org.astro is accessible from more than one module: org.astro, some.mod\n" +
3640 					"World cannot be resolved to a type",
3641 					markers);
3642 		} finally {
3643 			deleteProject("org.astro");
3644 			deleteProject("some.mod");
3645 			deleteProject("com.greetings");
3646 		}
3647 	}
3648 	// test that a package declared in a non-modular project conflicts with a package with the same name
3649 	// exported by a named module on it's build path
test_conflict_unnamed_declaredvsexported()3650 	public void test_conflict_unnamed_declaredvsexported() throws CoreException {
3651 		try {
3652 			IClasspathEntry dep = JavaCore.newContainerEntry(new Path(JavaCore.MODULE_PATH_CONTAINER_ID));
3653 			String[] sources = new String[] {
3654 				"src/module-info.java",
3655 				"module org.astro {\n" +
3656 				"	exports org.astro;\n" +
3657 				"}",
3658 				"src/org/astro/World.java",
3659 				"package org.astro;\n" +
3660 				"public interface World {\n" +
3661 				"	public String name();\n" +
3662 				"}"
3663 			};
3664 			IJavaProject p1 = setupModuleProject("org.astro", sources, new IClasspathEntry[]{dep});
3665 			String[] src = new String[] {
3666 				"src/org/astro/Test.java",
3667 				"package org.astro;\n" +
3668 				"public class Test {\n" +
3669 				"	public String name() {\n" +
3670 				"		return \" My World!!\";\n" +
3671 				"	}\n" +
3672 				"}",
3673 				"src/com/greetings/MyWorld.java",
3674 				"package com.greetings;\n" +
3675 				"public class MyWorld implements org.astro.World {\n" +
3676 				"	public String name() {\n" +
3677 				"		return \" My World!!\";\n" +
3678 				"	}\n" +
3679 				"}"
3680 			};
3681 			IClasspathAttribute modAttr = new ClasspathAttribute("module", "true");
3682 			IClasspathEntry dep1 = JavaCore.newProjectEntry(p1.getPath(), null, false,
3683 				new IClasspathAttribute[] {modAttr},
3684 				false/*not exported*/);
3685 			IJavaProject p2 = setupModuleProject("com.greetings", src, new IClasspathEntry[] { dep1 });
3686 			p2.getProject().getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, null);
3687 			IMarker[] markers = p2.getProject().findMarkers(null, true, IResource.DEPTH_INFINITE);
3688 			sortMarkers(markers);
3689 			assertMarkers("Unexpected markers",
3690 					"The package org.astro conflicts with a package accessible from another module: org.astro\n" +
3691 					"The package org.astro is accessible from more than one module: <unnamed>, org.astro",
3692 					markers);
3693 		} finally {
3694 			deleteProject("org.astro");
3695 			deleteProject("com.greetings");
3696 		}
3697 	}
3698 	// test that a type in an accessible package trumps an accessible package with the same name
3699 	// in the context of a non-modular project
test_conflict_packagevstype_unnamed()3700 	public void test_conflict_packagevstype_unnamed() throws CoreException {
3701 		try {
3702 			IClasspathEntry dep = JavaCore.newContainerEntry(new Path(JavaCore.MODULE_PATH_CONTAINER_ID));
3703 			String[] sources = new String[] {
3704 				"src/module-info.java",
3705 				"module org.astro {\n" +
3706 				"	exports bundle.org.astro;\n" +
3707 				"}",
3708 				"src/bundle/org/astro/World.java",
3709 				"package bundle.org.astro;\n" +
3710 				"public interface World {\n" +
3711 				"	public String name();\n" +
3712 				"}"
3713 			};
3714 			IJavaProject p1 = setupModuleProject("org.astro", sources, new IClasspathEntry[]{dep});
3715 			sources = new String[] {
3716 					"src/module-info.java",
3717 					"module other.mod {\n" +
3718 					"	exports bundle.org;\n" +
3719 					"}",
3720 					"src/bundle/org/astro.java",
3721 					"package bundle.org;\n" +
3722 					"public class astro {}"
3723 				};
3724 			IJavaProject p2 = setupModuleProject("other.mod", sources, new IClasspathEntry[]{dep});
3725 			String[] src = new String[] {
3726 				"src/com/greetings/MyWorld.java",
3727 				"package com.greetings;\n" +
3728 				"public class MyWorld implements bundle.org.astro.World {\n" +
3729 				"	public String name() {\n" +
3730 				"		return \" My World!!\";\n" +
3731 				"	}\n" +
3732 				"}"
3733 			};
3734 			IClasspathAttribute modAttr = new ClasspathAttribute("module", "true");
3735 			IClasspathEntry dep1 = JavaCore.newProjectEntry(p1.getPath(), null, false,
3736 				new IClasspathAttribute[] {modAttr},
3737 				false/*not exported*/);
3738 			IClasspathEntry dep2 = JavaCore.newProjectEntry(p2.getPath(), null, false,
3739 				new IClasspathAttribute[] {modAttr},
3740 				false/*not exported*/);
3741 			IJavaProject p3 = setupModuleProject("com.greetings", src, new IClasspathEntry[] { dep1, dep2 });
3742 			getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, null);
3743 			IMarker[] markers = p3.getProject().findMarkers(null, true, IResource.DEPTH_INFINITE);
3744 			assertMarkers("Unexpected markers",
3745 					"bundle.org.astro.World cannot be resolved to a type",  markers);
3746 		} finally {
3747 			deleteProject("org.astro");
3748 			deleteProject("other.mod");
3749 			deleteProject("com.greetings");
3750 		}
3751 	}
3752 	// test that a conflicting package does not cause an error when resolving a sub package name
3753 	// when the sub package is accessible in the context of a non-modular project
test_noconflict_subpkg_unnamed()3754 	public void test_noconflict_subpkg_unnamed() throws CoreException {
3755 		try {
3756 			IClasspathEntry dep = JavaCore.newContainerEntry(new Path(JavaCore.MODULE_PATH_CONTAINER_ID));
3757 			String[] sources = new String[] {
3758 				"src/module-info.java",
3759 				"module org.astro {\n" +
3760 				"	exports bundle.org.astro;\n" +
3761 				"}",
3762 				"src/bundle/org/astro/World.java",
3763 				"package bundle.org.astro;\n" +
3764 				"public interface World {\n" +
3765 				"	public String name();\n" +
3766 				"}"
3767 			};
3768 			IJavaProject p1 = setupModuleProject("org.astro", sources, new IClasspathEntry[]{dep});
3769 			sources = new String[] {
3770 					"src/module-info.java",
3771 					"module other.mod {\n" +
3772 					"	exports bundle.org;\n" +
3773 					"}",
3774 					"src/bundle/org/astro.java",
3775 					"package bundle.org;\n" +
3776 					"public class astro {}"
3777 				};
3778 			IJavaProject p2 = setupModuleProject("other.mod", sources, new IClasspathEntry[]{dep});
3779 			String[] src = new String[] {
3780 				"src/bundle/org/Test.java",
3781 				"package bundle.org;\n" +
3782 				"public class Test {}",
3783 				"src/com/greetings/MyWorld.java",
3784 				"package com.greetings;\n" +
3785 				"public class MyWorld implements bundle.org.astro.World {\n" +
3786 				"	public String name() {\n" +
3787 				"		return \" My World!!\";\n" +
3788 				"	}\n" +
3789 				"}"
3790 			};
3791 			IClasspathAttribute modAttr = new ClasspathAttribute("module", "true");
3792 			IClasspathEntry dep1 = JavaCore.newProjectEntry(p1.getPath(), null, false,
3793 				new IClasspathAttribute[] {modAttr},
3794 				false/*not exported*/);
3795 			IClasspathEntry dep2 = JavaCore.newProjectEntry(p2.getPath(), null, false,
3796 				new IClasspathAttribute[] {modAttr},
3797 				false/*not exported*/);
3798 			IJavaProject p3 = setupModuleProject("com.greetings", src, new IClasspathEntry[] { dep1, dep2 });
3799 			getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, null);
3800 			IMarker[] markers = p3.getProject().findMarkers(null, true, IResource.DEPTH_INFINITE);
3801 			sortMarkers(markers);
3802 			assertMarkers("Unexpected markers",
3803 					"The package bundle.org conflicts with a package accessible from another module: other.mod\n" +
3804 					"The package bundle.org is accessible from more than one module: <unnamed>, other.mod",
3805 					markers);
3806 		} finally {
3807 			deleteProject("org.astro");
3808 			deleteProject("other.mod");
3809 			deleteProject("com.greetings");
3810 		}
3811 	}
3812 	// test that a type in a non-accessible package does not conflict with an accessible package
3813 	// in the context of a non-modular project
test_noconflict_concealedtype_accessiblepackage_unnamed()3814 	public void test_noconflict_concealedtype_accessiblepackage_unnamed() throws CoreException {
3815 		try {
3816 			IClasspathEntry dep = JavaCore.newContainerEntry(new Path(JavaCore.MODULE_PATH_CONTAINER_ID));
3817 			String[] sources = new String[] {
3818 				"src/module-info.java",
3819 				"module org.astro {\n" +
3820 				"	exports bundle.org.astro;\n" +
3821 				"}",
3822 				"src/bundle/org/astro/World.java",
3823 				"package bundle.org.astro;\n" +
3824 				"public interface World {\n" +
3825 				"	public String name();\n" +
3826 				"}"
3827 			};
3828 			IJavaProject p1 = setupModuleProject("org.astro", sources, new IClasspathEntry[]{dep});
3829 			sources = new String[] {
3830 					"src/module-info.java",
3831 					"module other.mod {\n" +
3832 					"}",
3833 					"src/bundle/org/astro.java",
3834 					"package bundle.org;\n" +
3835 					"public class astro {}"
3836 				};
3837 			IJavaProject p2 = setupModuleProject("other.mod", sources, new IClasspathEntry[]{dep});
3838 			String[] src = new String[] {
3839 				"src/com/greetings/MyWorld.java",
3840 				"package com.greetings;\n" +
3841 				"public class MyWorld implements bundle.org.astro.World {\n" +
3842 				"	public String name() {\n" +
3843 				"		return \" My World!!\";\n" +
3844 				"	}\n" +
3845 				"}"
3846 			};
3847 			IClasspathAttribute modAttr = new ClasspathAttribute("module", "true");
3848 			IClasspathEntry dep1 = JavaCore.newProjectEntry(p1.getPath(), null, false,
3849 				new IClasspathAttribute[] {modAttr},
3850 				false/*not exported*/);
3851 			IClasspathEntry dep2 = JavaCore.newProjectEntry(p2.getPath(), null, false,
3852 				new IClasspathAttribute[] {modAttr},
3853 				false/*not exported*/);
3854 			IJavaProject p3 = setupModuleProject("com.greetings", src, new IClasspathEntry[] { dep1, dep2 });
3855 			getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, null);
3856 			IMarker[] markers = p3.getProject().findMarkers(null, true, IResource.DEPTH_INFINITE);
3857 			assertMarkers("Unexpected markers",	"",  markers);
3858 		} finally {
3859 			deleteProject("org.astro");
3860 			deleteProject("other.mod");
3861 			deleteProject("com.greetings");
3862 		}
3863 	}
testBug512053()3864 	public void testBug512053() throws CoreException, IOException {
3865 		Hashtable<String, String> javaCoreOptions = JavaCore.getOptions();
3866 		this.sourceWorkspacePath = super.getSourceWorkspacePath() + java.io.File.separator + "bug512053";
3867 		try {
3868 			setUpJavaProject("bundle.test.a.callable", "9");
3869 			setUpJavaProject("bundle.test.a", "9");
3870 			setUpJavaProject("bundle.test.b", "9");
3871 			setUpJavaProject("jpms.test.a", "9");
3872 			setUpJavaProject("jpms.test.b", "9");
3873 			getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, null);
3874 			assertNoErrors();
3875 			//assertNoErrors(p2);
3876 		} finally {
3877 			this.deleteProject("bundle.test.a.callable");
3878 			this.deleteProject("bundle.test.a");
3879 			this.deleteProject("bundle.test.b");
3880 			this.deleteProject("jpms.test.a");
3881 			this.deleteProject("jpms.test.b");
3882 			this.sourceWorkspacePath = null;
3883 			 JavaCore.setOptions(javaCoreOptions);
3884 		}
3885 	}
3886 	// basic test for automatic modules - external jars
testBug518280()3887 	public void testBug518280() throws CoreException, IOException {
3888 		try {
3889 			String libPath = "externalLib/test.jar";
3890 			Util.createJar(
3891 					new String[] {
3892 						"test/src/org/astro/World.java", //$NON-NLS-1$
3893 						"package org.astro;\n" +
3894 						"public interface World {\n" +
3895 						"	public String name();\n" +
3896 						"}",
3897 					},
3898 					null,
3899 					new HashMap<>(),
3900 					null,
3901 					getExternalResourcePath(libPath));
3902 			String[] src = new String[] {
3903 					"src/module-info.java",
3904 					"module com.greetings {\n" +
3905 					"	requires test;\n" +
3906 					"	exports com.greetings;\n" +
3907 					"}",
3908 					"src/com/greetings/MyWorld.java",
3909 					"package com.greetings;\n" +
3910 					"import org.astro.World;\n"	+
3911 					"public class MyWorld implements World {\n" +
3912 					"	public String name() {\n" +
3913 					"		return \" My World!!\";\n" +
3914 					"	}\n" +
3915 					"}"
3916 			};
3917 			IClasspathAttribute modAttr = new ClasspathAttribute("module", "true");
3918 			IClasspathEntry dep = JavaCore.newLibraryEntry(new Path(getExternalResourcePath(libPath)), null, null, ClasspathEntry.NO_ACCESS_RULES,
3919 					new IClasspathAttribute[] {modAttr},
3920 					false/*not exported*/);
3921 			IJavaProject p2 = setupModuleProject("com.greetings", src, new IClasspathEntry[] { dep });
3922 			p2.setOption(JavaCore.COMPILER_PB_UNSTABLE_AUTO_MODULE_NAME, JavaCore.IGNORE);
3923 
3924 			getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, null);
3925 			IMarker[] markers = p2.getProject().findMarkers(null, true, IResource.DEPTH_INFINITE);
3926 			assertMarkers("Unexpected markers", "", markers);
3927 		} finally {
3928 			deleteExternalResource("externalLib");
3929 			this.deleteProject("com.greetings");
3930 		}
3931 	}
3932 	// basic test for automatic modules - workspace jars
testBug518282()3933 	public void testBug518282() throws CoreException, IOException {
3934 		Hashtable<String, String> javaCoreOptions = JavaCore.getOptions();
3935 		try {
3936 			setUpJavaProject("test_automodules", "9");
3937 			getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, null);
3938 			getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, null);
3939 			assertNoErrors();
3940 		} finally {
3941 			this.deleteProject("test_automodules");
3942 			JavaCore.setOptions(javaCoreOptions);
3943 		}
3944 	}
3945 	// Only the project using a jar as an automatic module should be able to
3946 	// resolve one as such
testBug518282a()3947 	public void testBug518282a() throws CoreException, IOException {
3948 		Hashtable<String, String> javaCoreOptions = JavaCore.getOptions();
3949 		try {
3950 			IJavaProject p1 = setUpJavaProject("test_automodules", "9");
3951 			getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, null);
3952 			assertNoErrors();
3953 			String[] src = new String[] {
3954 					"src/module-info.java",
3955 					"module com.greetings {\n" +
3956 					"	requires junit; // This should not be resolved\n" +
3957 					"	exports com.greetings;\n" +
3958 					"}",
3959 					"src/com/greetings/Test.java",
3960 					"package com.greetings;\n" +
3961 					"public class Test {\n" +
3962 					"	public String name() {\n" +
3963 					"		return \" My World!!\";\n" +
3964 					"	}\n" +
3965 					"}"
3966 			};
3967 			IClasspathAttribute modAttr = new ClasspathAttribute("module", "false");
3968 			IClasspathEntry dep = JavaCore.newLibraryEntry(p1.getProject().findMember("lib/junit.jar").getFullPath(), null, null,
3969 					ClasspathEntry.NO_ACCESS_RULES,
3970 					new IClasspathAttribute[] {modAttr},
3971 					false/*not exported*/);
3972 			IJavaProject p2 = setupModuleProject("com.greetings", src, new IClasspathEntry[] { dep });
3973 
3974 			getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, null);
3975 			IMarker[] markers = p2.getProject().findMarkers(null, true, IResource.DEPTH_INFINITE);
3976 			assertMarkers("Unexpected markers",
3977 					"junit cannot be resolved to a module", markers);
3978 		} finally {
3979 			this.deleteProject("test_automodules");
3980 			this.deleteProject("com.greetings");
3981 			JavaCore.setOptions(javaCoreOptions);
3982 		}
3983 	}
3984 	// A modular jar on the module path of a project should behave as a regular module and not
3985 	// as an automatic module
testBug518282b()3986 	public void testBug518282b() throws CoreException, IOException {
3987 		Hashtable<String, String> javaCoreOptions = JavaCore.getOptions();
3988 		String libPath = "externalLib/test.jar";
3989 		try {
3990 			String[] src = new String[] {
3991 					"src/module-info.java",
3992 					"module com.greetings {\n" +
3993 					"	exports com.greetings;\n" +
3994 					"}",
3995 					"src/com/greetings/Test.java",
3996 					"package com.greetings;\n" +
3997 					"public class Test {\n" +
3998 					"	public String name() {\n" +
3999 					"		return \" My World!!\";\n" +
4000 					"	}\n" +
4001 					"}"
4002 			};
4003 			IJavaProject p1 = setupModuleProject("test", src);
4004 			getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, null);
4005 			File rootDir = new File(p1.getProject().findMember("bin").getLocation().toString());
4006 			Util.zip(rootDir, getExternalResourcePath(libPath));
4007 			src = new String[] {
4008 					"src/module-info.java",
4009 					"module test_automodules {\n" +
4010 					"	requires com.greetings;\n" +
4011 					"}",
4012 					"src/test/Main.java",
4013 					"package test;\n" +
4014 					"import com.greetings.Test;\n" +
4015 					"public class Main {\n" +
4016 					"	public static void main(String[] args) {\n" +
4017 					"		System.out.println(new Test().name());\n" +
4018 					"	}\n" +
4019 					"}"
4020 			};
4021 			IClasspathAttribute modAttr = new ClasspathAttribute("module", "true");
4022 			IClasspathEntry dep = JavaCore.newLibraryEntry(new Path(getExternalResourcePath(libPath)), null, null,
4023 				ClasspathEntry.NO_ACCESS_RULES,
4024 				new IClasspathAttribute[] {modAttr},
4025 				false/*not exported*/);
4026 			IJavaProject p2 = setupModuleProject("test_automodules", src, new IClasspathEntry[] {dep});
4027 			getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, null);
4028 			IMarker[] markers = p2.getProject().findMarkers(null, true, IResource.DEPTH_INFINITE);
4029 			assertMarkers("Unexpected markers", "", markers);
4030 		} finally {
4031 			this.deleteProject("test");
4032 			this.deleteProject("test_automodules");
4033 			deleteExternalResource(libPath);
4034 			JavaCore.setOptions(javaCoreOptions);
4035 		}
4036 	}
4037 	// A modular jar on the class path of a module project - shouldn't be
4038 	// treated as a module and shouldn't be readable
testBug518282c()4039 	public void testBug518282c() throws CoreException, IOException {
4040 		Hashtable<String, String> javaCoreOptions = JavaCore.getOptions();
4041 		String libPath = "externalLib/test.jar";
4042 		try {
4043 			String[] src = new String[] {
4044 					"src/module-info.java",
4045 					"module test {\n" +
4046 					"	exports com.greetings;\n" +
4047 					"}",
4048 					"src/com/greetings/Test.java",
4049 					"package com.greetings;\n" +
4050 					"public class Test {\n" +
4051 					"	public String name() {\n" +
4052 					"		return \" My World!!\";\n" +
4053 					"	}\n" +
4054 					"}"
4055 			};
4056 			IJavaProject p1 = setupModuleProject("test", src);
4057 			getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, null);
4058 			File rootDir = new File(p1.getProject().findMember("bin").getLocation().toString());
4059 			Util.zip(rootDir, getExternalResourcePath(libPath));
4060 			src = new String[] {
4061 					"src/module-info.java",
4062 					"module test_automodules {\n" +
4063 					"	requires test;\n" +
4064 					"}",
4065 					"src/test/Main.java",
4066 					"package test;\n" +
4067 					"import com.greetings.Test;\n" +
4068 					"public class Main {\n" +
4069 					"	public static void main(String[] args) {\n" +
4070 					"		System.out.println(new Test().name());\n" +
4071 					"	}\n" +
4072 					"}"
4073 			};
4074 			IClasspathAttribute modAttr = new ClasspathAttribute("module", "false");
4075 			IClasspathEntry dep = JavaCore.newLibraryEntry(new Path(getExternalResourcePath(libPath)), null, null,
4076 				ClasspathEntry.NO_ACCESS_RULES,
4077 				new IClasspathAttribute[] {modAttr},
4078 				false/*not exported*/);
4079 			IJavaProject p2 = setupModuleProject("test_automodules", src, new IClasspathEntry[] {dep});
4080 			getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, null);
4081 			IMarker[] markers = p2.getProject().findMarkers(null, true, IResource.DEPTH_INFINITE);
4082 			assertTrue("Compilation succeeds unexpectedly", markers.length > 0);
4083 		} finally {
4084 			this.deleteProject("test");
4085 			this.deleteProject("test_automodules");
4086 			deleteExternalResource(libPath);
4087 			JavaCore.setOptions(javaCoreOptions);
4088 		}
4089 	}
4090 	// An automatic module grants implied readability to all other automatic modules
testBug518282d()4091 	public void testBug518282d() throws CoreException, IOException {
4092 		Hashtable<String, String> javaCoreOptions = JavaCore.getOptions();
4093 		String libPath = "externalLib/test.jar";
4094 		try {
4095 			String[] src = new String[] {
4096 					"src/org/astro/World.java",
4097 					"package org.astro;\n" +
4098 					"public interface World {\n" +
4099 					"	public String name();\n" +
4100 					"}"
4101 			};
4102 			IJavaProject p1 = setupModuleProject("org.astro", src);
4103 			src = new String[] {
4104 				"src/org/greetings/Test.java",
4105 				"package org.greetings;\n" +
4106 				"import  org.astro.World;\n" +
4107 				"public class Test implements World {\n" +
4108 				"	public String name() {\n" +
4109 				"		return \" My World!!\";\n" +
4110 				"	}\n" +
4111 				"}"
4112 			};
4113 			IClasspathEntry dep = JavaCore.newProjectEntry(p1.getPath());
4114 			IJavaProject p2 = setupModuleProject("test", src, new IClasspathEntry[] {dep});
4115 			getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, null);
4116 			File rootDir = new File(p2.getProject().findMember("bin").getLocation().toString());
4117 			Util.zip(rootDir, getExternalResourcePath(libPath));
4118 			src = new String[] {
4119 				"src/module-info.java",
4120 				"module test_automodules {\n" +
4121 				"	requires test;\n" +
4122 				"}",
4123 				"src/test/Main.java",
4124 				"package test;\n" +
4125 				"import org.greetings.Test;\n" +
4126 				"public class Main {\n" +
4127 				"	public static void main(String[] args) {\n" +
4128 				"		org.astro.World world = new Test();\n" +
4129 				"		System.out.println(world.name());\n" +
4130 				"	}\n" +
4131 				"}"
4132 			};
4133 			IClasspathAttribute modAttr = new ClasspathAttribute("module", "true");
4134 			dep = JavaCore.newLibraryEntry(new Path(getExternalResourcePath(libPath)), null, null,
4135 				ClasspathEntry.NO_ACCESS_RULES,
4136 				new IClasspathAttribute[] {modAttr},
4137 				false/*not exported*/);
4138 			IClasspathEntry dep2 = JavaCore.newLibraryEntry(p1.getProject().findMember("bin").getFullPath(), null, null,
4139 				ClasspathEntry.NO_ACCESS_RULES,
4140 				new IClasspathAttribute[] {modAttr},
4141 				false/*not exported*/);
4142 			IJavaProject p3 = setupModuleProject("test_automodules", src, new IClasspathEntry[] {dep, dep2});
4143 			p3.setOption(JavaCore.COMPILER_PB_UNSTABLE_AUTO_MODULE_NAME, JavaCore.IGNORE);
4144 			getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, null);
4145 			IMarker[] markers = p3.getProject().findMarkers(null, true, IResource.DEPTH_INFINITE);
4146 			assertMarkers("Unexpected markers", "", markers);
4147 		} finally {
4148 			this.deleteProject("test");
4149 			this.deleteProject("test_automodules");
4150 			this.deleteProject("org.astro");
4151 			deleteExternalResource(libPath);
4152 			JavaCore.setOptions(javaCoreOptions);
4153 		}
4154 	}
4155 	// Automatic module should not allow access to other explicit modules without
4156 	// requires
testBug518282e()4157 	public void testBug518282e() throws CoreException, IOException {
4158 		Hashtable<String, String> javaCoreOptions = JavaCore.getOptions();
4159 		String libPath = "externalLib/test.jar";
4160 		try {
4161 			String[] src = new String[] {
4162 					"src/module-info.java",
4163 					"module org.astro {\n" +
4164 					"	exports org.astro;\n" +
4165 					"}",
4166 					"src/org/astro/World.java",
4167 					"package org.astro;\n" +
4168 					"public interface World {\n" +
4169 					"	public String name();\n" +
4170 					"}"
4171 			};
4172 			IJavaProject p1 = setupModuleProject("org.astro", src);
4173 			src = new String[] {
4174 				"src/com/greetings/Test.java",
4175 				"package com.greetings;\n" +
4176 				"import  org.astro.World;\n" +
4177 				"public class Test implements World {\n" +
4178 				"	public String name() {\n" +
4179 				"		return \" My World!!\";\n" +
4180 				"	}\n" +
4181 				"}"
4182 			};
4183 			IClasspathEntry dep = JavaCore.newProjectEntry(p1.getPath());
4184 			IJavaProject p2 = setupModuleProject("test", src, new IClasspathEntry[] {dep});
4185 			getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, null);
4186 			File rootDir = new File(p2.getProject().findMember("bin").getLocation().toString());
4187 			Util.zip(rootDir, getExternalResourcePath(libPath));
4188 			src = new String[] {
4189 				"src/module-info.java",
4190 				"module test_automodules {\n" +
4191 				"	requires test;\n" +
4192 				"}",
4193 				"src/test/Main.java",
4194 				"package test;\n" +
4195 				"import com.greetings.Test;\n" +
4196 				"import org.astro.*;\n" +
4197 				"public class Main {\n" +
4198 				"	public static void main(String[] args) {\n" +
4199 				"		World world = new Test();\n" +
4200 				"		System.out.println(world.name());\n" +
4201 				"	}\n" +
4202 				"}"
4203 			};
4204 			IClasspathAttribute modAttr = new ClasspathAttribute("module", "true");
4205 			dep = JavaCore.newLibraryEntry(new Path(getExternalResourcePath(libPath)), null, null,
4206 				ClasspathEntry.NO_ACCESS_RULES,
4207 				new IClasspathAttribute[] {modAttr},
4208 				false/*not exported*/);
4209 			modAttr = new ClasspathAttribute("module", "true");
4210 			IClasspathEntry dep2 = JavaCore.newProjectEntry(p1.getPath(), null, true,
4211 				new IClasspathAttribute[] {modAttr},
4212 				false/*not exported*/);
4213 			IJavaProject p3 = setupModuleProject("test_automodules", src, new IClasspathEntry[] {dep, dep2});
4214 			p3.setOption(JavaCore.COMPILER_PB_UNSTABLE_AUTO_MODULE_NAME, JavaCore.IGNORE);
4215 			getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, null);
4216 			IMarker[] markers = p3.getProject().findMarkers(null, true, IResource.DEPTH_INFINITE);
4217 			sortMarkers(markers);
4218 			assertMarkers("Unexpected markers",
4219 					"The package org.astro is not accessible\n" +
4220 					"World cannot be resolved to a type", markers);
4221 		} finally {
4222 			this.deleteProject("test");
4223 			this.deleteProject("test_automodules");
4224 			this.deleteProject("org.astro");
4225 			deleteExternalResource(libPath);
4226 			JavaCore.setOptions(javaCoreOptions);
4227 		}
4228 	}
4229 	// An automatic module shouldn't allow access to classpath
testBug518282f()4230 	public void testBug518282f() throws CoreException, IOException {
4231 		Hashtable<String, String> javaCoreOptions = JavaCore.getOptions();
4232 		String libPath = "externalLib/test.jar";
4233 		try {
4234 			String[] src = new String[] {
4235 					"src/org/astro/World.java",
4236 					"package org.astro;\n" +
4237 					"public interface World {\n" +
4238 					"	public String name();\n" +
4239 					"}"
4240 			};
4241 			IJavaProject p1 = setupModuleProject("org.astro", src);
4242 			src = new String[] {
4243 				"src/com/greetings/Test.java",
4244 				"package com.greetings;\n" +
4245 				"import  org.astro.World;\n" +
4246 				"public class Test implements World {\n" +
4247 				"	public String name() {\n" +
4248 				"		return \" My World!!\";\n" +
4249 				"	}\n" +
4250 				"}"
4251 			};
4252 			IClasspathEntry dep = JavaCore.newProjectEntry(p1.getPath());
4253 			IJavaProject p2 = setupModuleProject("test", src, new IClasspathEntry[] {dep});
4254 			getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, null);
4255 			File rootDir = new File(p2.getProject().findMember("bin").getLocation().toString());
4256 			Util.zip(rootDir, getExternalResourcePath(libPath));
4257 			src = new String[] {
4258 				"src/module-info.java",
4259 				"module test_automodules {\n" +
4260 				"	requires test;\n" +
4261 				"}",
4262 				"src/test/Main.java",
4263 				"package test;\n" +
4264 				"import com.greetings.Test;\n" +
4265 				"public class Main {\n" +
4266 				"	public static void main(String[] args) {\n" +
4267 				"		org.astro.World world = new Test();\n" +
4268 				"		System.out.println(world.name());\n" +
4269 				"	}\n" +
4270 				"}"
4271 			};
4272 			IClasspathAttribute modAttr = new ClasspathAttribute("module", "true");
4273 			dep = JavaCore.newLibraryEntry(new Path(getExternalResourcePath(libPath)), null, null,
4274 				ClasspathEntry.NO_ACCESS_RULES,
4275 				new IClasspathAttribute[] {modAttr},
4276 				false/*not exported*/);
4277 			modAttr = new ClasspathAttribute("module", "false");
4278 			IClasspathEntry dep2 = JavaCore.newLibraryEntry(p1.getProject().findMember("bin").getFullPath(), null, null,
4279 				ClasspathEntry.NO_ACCESS_RULES,
4280 				new IClasspathAttribute[] {modAttr},
4281 				false/*not exported*/);
4282 			IJavaProject p3 = setupModuleProject("test_automodules", src, new IClasspathEntry[] {dep, dep2});
4283 			getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, null);
4284 			IMarker[] markers = p3.getProject().findMarkers(null, true, IResource.DEPTH_INFINITE);
4285 			assertMarkers("Unexpected markers",
4286 					"Name of automatic module \'test\' is unstable, it is derived from the module\'s file name.\n" +
4287 					"The type org.astro.World is not accessible",
4288 					markers);
4289 		} finally {
4290 			this.deleteProject("test");
4291 			this.deleteProject("test_automodules");
4292 			this.deleteProject("org.astro");
4293 			deleteExternalResource(libPath);
4294 			JavaCore.setOptions(javaCoreOptions);
4295 		}
4296 	}
4297 
testUnnamedModule_bug519674()4298 	public void testUnnamedModule_bug519674() throws CoreException {
4299 		try {
4300 			IJavaProject p1 = createJava9Project("Project1");
4301 			createFolder("/Project1/src/pack1");
4302 			createFile("/Project1/src/pack1/Class1.java",
4303 					"package pack1;\n" +
4304 					"public class Class1 {}\n");
4305 
4306 			IJavaProject p2 = createJava9Project("Project2");
4307 			{
4308 				IClasspathEntry[] old = p2.getRawClasspath();
4309 				IClasspathEntry[] newPath = new IClasspathEntry[old.length + 1];
4310 				System.arraycopy(old, 0, newPath, 0, old.length);
4311 				newPath[old.length] = JavaCore.newProjectEntry(p1.getPath());
4312 				p2.setRawClasspath(newPath, null);
4313 			}
4314 			createFolder("/Project2/src/pack2");
4315 			createFile("/Project2/src/pack2/Class2.java",
4316 					"package pack2;\n" +
4317 					"import pack1.Class1;\n" +
4318 					"public class Class2 extends Class1 {}\n");
4319 			getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, null);
4320 			IMarker[] markers = p2.getProject().findMarkers(null, true, IResource.DEPTH_INFINITE);
4321 			assertMarkers("Unexpected markers", "", markers);
4322 		} finally {
4323 			this.deleteProject("Project1");
4324 			this.deleteProject("Project2");
4325 		}
4326 
4327 	}
testBug520246()4328 	public void testBug520246() throws CoreException {
4329 		try {
4330 			String[] src = new String[] {
4331 				"src/module-info.java",
4332 				"module test_automodules {\n" +
4333 				"	requires java.sql;\n" +
4334 				"}",
4335 				"src/org/astro/World.java",
4336 				"package org.astro;\n" +
4337 				"import some.pack.Type;\n" +
4338 				"public interface World {\n" +
4339 				"	public String name();\n" +
4340 				"}"
4341 			};
4342 			IJavaProject p1 = setupModuleProject("org.astro", src);
4343 			getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, null);
4344 			IMarker[] markers = p1.getProject().findMarkers(null, true, IResource.DEPTH_INFINITE);
4345 			assertMarkers("Unexpected markers", "The import some cannot be resolved", markers);
4346 		} finally {
4347 			this.deleteProject("org.astro");
4348 		}
4349 
4350 	}
testBug520147()4351 	public void testBug520147() throws CoreException, IOException {
4352 		Hashtable<String, String> javaCoreOptions = JavaCore.getOptions();
4353 		try {
4354 			String[] src = new String[] {
4355 					"src/module-info.java",
4356 					"module org.astro {\n" +
4357 					"	exports org.astro;\n" +
4358 					"}",
4359 					"src/bundle/org/SomeClass.java",
4360 					"package bundle.org;\n" +
4361 					"public class SomeClass {}",
4362 					"src/org/astro/World.java",
4363 					"package org.astro;\n" +
4364 					"public interface World {\n" +
4365 					"	public String name();\n" +
4366 					"}"
4367 			};
4368 			IJavaProject p1 = setupModuleProject("org.astro", src);
4369 			src = new String[] {
4370 				"src/module-info.java",
4371 				"module com.greetings {\n" +
4372 					"	requires org.astro;\n" +
4373 					"	exports bundle.org;\n" +
4374 					"}",
4375 				"src/bundle/org/SomeWorld.java",
4376 				"package bundle.org;\n" +
4377 				"import  org.astro.World;\n" +
4378 				"public class SomeWorld implements World {\n" +
4379 				"	public String name() {\n" +
4380 				"		return \" Some World!!\";\n" +
4381 				"	}\n" +
4382 				"}"
4383 			};
4384 			IClasspathAttribute modAttr = new ClasspathAttribute("module", "true");
4385 			IClasspathEntry dep = JavaCore.newProjectEntry(p1.getPath(), null, false, new IClasspathAttribute[] {modAttr}, false);
4386 			IJavaProject p2 = setupModuleProject("com.greetings", src, new IClasspathEntry[] {dep});
4387 			getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, null);
4388 			src = new String[] {
4389 				"src/module-info.java",
4390 				"module test {\n" +
4391 				"	exports test;\n" +
4392 				"	requires org.astro;\n" +
4393 				"	requires com.greetings;\n" +
4394 				"}",
4395 				"src/test/Main.java",
4396 				"package test;\n" +
4397 				"import bundle.org.SomeWorld;\n" +
4398 				"public class Main {\n" +
4399 				"	public static void main(String[] args) {\n" +
4400 				"		org.astro.World world = new SomeWorld();\n" +
4401 				"		System.out.println(world.name());\n" +
4402 				"	}\n" +
4403 				"}"
4404 			};
4405 			IClasspathEntry dep2 = JavaCore.newProjectEntry(p2.getPath(), null, false, new IClasspathAttribute[] {modAttr}, false);
4406 			IJavaProject p3 = setupModuleProject("test", src, new IClasspathEntry[] {dep, dep2});
4407 			getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, null);
4408 			IMarker[] markers = p3.getProject().findMarkers(null, true, IResource.DEPTH_INFINITE);
4409 			assertMarkers("Unexpected markers", "", markers);
4410 		} finally {
4411 			this.deleteProject("test");
4412 			this.deleteProject("com.greetings");
4413 			this.deleteProject("org.astro");
4414 			JavaCore.setOptions(javaCoreOptions);
4415 		}
4416 	}
testBug520147a()4417 	public void testBug520147a() throws CoreException, IOException {
4418 		Hashtable<String, String> javaCoreOptions = JavaCore.getOptions();
4419 		try {
4420 			String[] src = new String[] {
4421 					"src/module-info.java",
4422 					"module org.astro {\n" +
4423 					"	exports org.astro;\n" +
4424 					"}",
4425 					"src/bundle/org/SomeClass.java",
4426 					"package bundle.org;\n" +
4427 					"public class SomeClass {}",
4428 					"src/org/astro/World.java",
4429 					"package org.astro;\n" +
4430 					"public interface World {\n" +
4431 					"	public String name();\n" +
4432 					"}"
4433 			};
4434 			IJavaProject p1 = setupModuleProject("org.astro", src);
4435 			src = new String[] {
4436 				"src/module-info.java",
4437 				"module com.greetings {\n" +
4438 					"	requires org.astro;\n" +
4439 					"	exports bundle.org;\n" +
4440 					"}",
4441 				"src/bundle/org/SomeWorld.java",
4442 				"package bundle.org;\n" +
4443 				"import  org.astro.World;\n" +
4444 				"public class SomeWorld implements World {\n" +
4445 				"	public String name() {\n" +
4446 				"		return \" Some World!!\";\n" +
4447 				"	}\n" +
4448 				"}"
4449 			};
4450 			IClasspathAttribute modAttr = new ClasspathAttribute("module", "true");
4451 			IClasspathEntry dep = JavaCore.newProjectEntry(p1.getPath(), null, false, new IClasspathAttribute[] {modAttr}, false);
4452 			IJavaProject p2 = setupModuleProject("com.greetings", src, new IClasspathEntry[] {dep});
4453 			getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, null);
4454 			src = new String[] {
4455 				"src/module-info.java",
4456 				"module test {\n" +
4457 				"	exports test;\n" +
4458 				"	requires com.greetings;\n" +
4459 				"}",
4460 				"src/test/Main.java",
4461 				"package test;\n" +
4462 				"import bundle.org.SomeWorld;\n" +
4463 				"public class Main {\n" +
4464 				"	public static void main(String[] args) {\n" +
4465 				"		org.astro.World world = new SomeWorld();\n" +
4466 				"		System.out.println(world.name());\n" +
4467 				"	}\n" +
4468 				"}"
4469 			};
4470 			IClasspathEntry dep2 = JavaCore.newProjectEntry(p2.getPath(), null, false, new IClasspathAttribute[] {modAttr}, false);
4471 			IJavaProject p3 = setupModuleProject("test", src, new IClasspathEntry[] {dep, dep2});
4472 			getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, null);
4473 			IMarker[] markers = p3.getProject().findMarkers(null, true, IResource.DEPTH_INFINITE);
4474 			assertMarkers("Unexpected markers",
4475 					"The type org.astro.World is not accessible", markers);
4476 		} finally {
4477 			this.deleteProject("test");
4478 			this.deleteProject("com.greetings");
4479 			this.deleteProject("org.astro");
4480 			JavaCore.setOptions(javaCoreOptions);
4481 		}
4482 	}
testBug520147b()4483 	public void testBug520147b() throws CoreException, IOException {
4484 		Hashtable<String, String> javaCoreOptions = JavaCore.getOptions();
4485 		try {
4486 			String[] src = new String[] {
4487 					"src/module-info.java",
4488 					"module org.astro {\n" +
4489 					"	exports org.astro;\n" +
4490 					"	exports bundle.org to com.greetings;\n" +
4491 					"}",
4492 					"src/bundle/org/SomeClass.java",
4493 					"package bundle.org;\n" +
4494 					"public class SomeClass {}",
4495 					"src/org/astro/World.java",
4496 					"package org.astro;\n" +
4497 					"public interface World {\n" +
4498 					"	public String name();\n" +
4499 					"}"
4500 			};
4501 			IJavaProject p1 = setupModuleProject("org.astro", src);
4502 			src = new String[] {
4503 				"src/module-info.java",
4504 				"module com.greetings {\n" +
4505 					"	requires org.astro;\n" +
4506 					"	exports bundle.org;\n" +
4507 					"}",
4508 				"src/bundle/org/SomeWorld.java",
4509 				"package bundle.org;\n" +
4510 				"import  org.astro.World;\n" +
4511 				"public class SomeWorld implements World {\n" +
4512 				"	public String name() {\n" +
4513 				"		return \" Some World!!\";\n" +
4514 				"	}\n" +
4515 				"}"
4516 			};
4517 			IClasspathAttribute modAttr = new ClasspathAttribute("module", "true");
4518 			IClasspathEntry dep = JavaCore.newProjectEntry(p1.getPath(), null, false, new IClasspathAttribute[] {modAttr}, false);
4519 			IJavaProject p2 = setupModuleProject("com.greetings", src, new IClasspathEntry[] {dep});
4520 			getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, null);
4521 			IMarker[] markers = p2.getProject().findMarkers(null, true, IResource.DEPTH_INFINITE);
4522 			sortMarkers(markers);
4523 			assertMarkers("markers on com.greetings",
4524 					"The package bundle.org conflicts with a package accessible from another module: org.astro",
4525 					markers);
4526 
4527 			src = new String[] {
4528 				"src/module-info.java",
4529 				"module test {\n" +
4530 				"	exports test;\n" +
4531 				"	requires org.astro;\n" +
4532 				"	requires com.greetings;\n" +
4533 				"}",
4534 				"src/test/Main.java",
4535 				"package test;\n" +
4536 				"import bundle.org.SomeWorld;\n" +
4537 				"public class Main {\n" +
4538 				"	public static void main(String[] args) {\n" +
4539 				"		org.astro.World world = new SomeWorld();\n" +
4540 				"		System.out.println(world.name());\n" +
4541 				"	}\n" +
4542 				"}"
4543 			};
4544 			IClasspathEntry dep2 = JavaCore.newProjectEntry(p2.getPath(), null, false, new IClasspathAttribute[] {modAttr}, false);
4545 			IJavaProject p3 = setupModuleProject("test", src, new IClasspathEntry[] {dep, dep2});
4546 			p3.getProject().build(IncrementalProjectBuilder.FULL_BUILD, null);
4547 			markers = p3.getProject().findMarkers(null, true, IResource.DEPTH_INFINITE);
4548 			assertMarkers("Unexpected markers", "", markers);
4549 		} finally {
4550 			this.deleteProject("test");
4551 			this.deleteProject("com.greetings");
4552 			this.deleteProject("org.astro");
4553 			JavaCore.setOptions(javaCoreOptions);
4554 		}
4555 	}
testSourceFolders_Bug519673()4556 	public void testSourceFolders_Bug519673() throws CoreException {
4557 		try {
4558 			// Setup project PSources1:
4559 			String[] src = new String[] {
4560 					"src/module-info.java",
4561 					"module PSources1 {\n" +
4562 					"	//exports p.q;\n" +
4563 					"}",
4564 					"src2/p/q/SomeClass.java",
4565 					"package p.q;\n" +
4566 					"public class SomeClass {}",
4567 			};
4568 			IJavaProject p1 = setupModuleProject("PSources1", new String[] { "src", "src2" }, src, new IClasspathEntry[0]);
4569 			getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, null);
4570 
4571 			// Edit PSources1/src/module-info.java:
4572 			String infoSrc =
4573 					"module PSources1 {\n" +
4574 					"	exports p.q;\n" +
4575 					"}";
4576 			String infoPath = "/PSources1/src/module-info.java";
4577 			editFile(infoPath, infoSrc);
4578 			this.workingCopies = new ICompilationUnit[1];
4579 			char[] sourceChars = src[1].toCharArray();
4580 			this.problemRequestor.initialize(sourceChars);
4581 			this.workingCopies[0] = getCompilationUnit(infoPath).getWorkingCopy(this.wcOwner, null);
4582 			// was: ERROR: The package pkg does not exist or is empty
4583 			assertProblems(
4584 					"Unexpected problems",
4585 					"----------\n" +
4586 					"----------\n",
4587 					this.problemRequestor);
4588 
4589 			// Setup project PClient2:
4590 			String[] src2 = new String[] {
4591 					"src/module-info.java",
4592 					"module PClient2 {\n" +
4593 					"	requires PSources1;\n" +
4594 					"}",
4595 					"src/x/Client.java",
4596 					"package x;\n" +
4597 					"public class Client {\n" +
4598 					"	p.q.SomeClass f;\n" +
4599 					"\n}",
4600 			};
4601 			setupModuleProject("PClient2", src2);
4602 			getWorkspace().build(IncrementalProjectBuilder.INCREMENTAL_BUILD, null);
4603 			IMarker[] markers = p1.getProject().findMarkers(null, true, IResource.DEPTH_INFINITE);
4604 			assertMarkers("Unexpected markers", "", markers);
4605 
4606 			// Edit PClient2/src/module-info.java:
4607 			// was NPE in ModuleBinding.canAccess()
4608 			char[] info2Chars = src2[2].toCharArray();
4609 			this.problemRequestor.initialize(info2Chars);
4610 			this.workingCopies[0] = getCompilationUnit("PClient2/src/module-info.java").getWorkingCopy(this.wcOwner, null);
4611 			assertProblems(
4612 					"Unexpected problems",
4613 					"----------\n" +
4614 					"----------\n",
4615 					this.problemRequestor);
4616 
4617 			// Failed attempt to trigger NPE in ModuleBinding.isPackageExportedTo() by editing Client.java
4618 			char[] source2Chars = src2[3].toCharArray();
4619 			this.problemRequestor.initialize(source2Chars);
4620 			this.workingCopies[0] = getCompilationUnit("PClient2/src/x/Client.java").getWorkingCopy(this.wcOwner, null);
4621 			assertProblems(
4622 					"Unexpected problems",
4623 					"----------\n" +
4624 					"----------\n",
4625 					this.problemRequestor);
4626 		} finally {
4627 			deleteProject("PSources1");
4628 			deleteProject("PClient2");
4629 		}
4630 	}
testPrivateMethod_Bug515985()4631 	public void testPrivateMethod_Bug515985() throws CoreException {
4632 		try {
4633 			String[] src = new String[] {
4634 					"src/module-info.java",
4635 					"module mod.one { \n" +
4636 					"	exports pm;\n" +
4637 					"}",
4638 					"src/impl/Other.java",
4639 					"package impl;\n" +
4640 					"public class Other {\n" +
4641 					"    public void privateMethod() {}" +
4642 					"}\n",
4643 					"src/pm/C1.java",
4644 					"package pm;\n" +
4645 					"import impl.Other;\n" +
4646 					"public class C1 extends Other {\n" +
4647 					"}\n"
4648 			};
4649 			IJavaProject p1 = setupModuleProject("mod.one", src);
4650 			getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, null);
4651 
4652 			String[] src2 = new String[] {
4653 					"src/module-info.java",
4654 					"module mod.two { \n" +
4655 					"	requires mod.one;\n" +
4656 					"}",
4657 					"src/po/Client.java",
4658 					"package po;\n" +
4659 					"import pm.C1;\n" +
4660 					"public class Client {\n" +
4661 					"    void test1(C1 one) {\n" +
4662 					"        one.privateMethod(); // ecj: The method privateMethod() is undefined for the type C1\n" +
4663 					"    }\n" +
4664 					"}\n"
4665 			};
4666 			IClasspathAttribute modAttr = new ClasspathAttribute("module", "true");
4667 			IClasspathEntry dep = JavaCore.newProjectEntry(p1.getPath(), null, false, new IClasspathAttribute[] {modAttr}, false);
4668 			IJavaProject p2 = setupModuleProject("mod.two", src2, new IClasspathEntry[] {dep});
4669 			getWorkspace().build(IncrementalProjectBuilder.INCREMENTAL_BUILD, null);
4670 			IMarker[] markers = p2.getProject().findMarkers(null, true, IResource.DEPTH_INFINITE);
4671 			assertMarkers("Unexpected markers", "", markers);
4672 		} finally {
4673 			deleteProject("mod.one");
4674 			deleteProject("mod.two");
4675 		}
4676 	}
testAddExports()4677 	public void testAddExports() throws CoreException {
4678 		try {
4679 			String[] sources = new String[] {
4680 					"src/module-info.java",
4681 					"module morg.astro {\n" +
4682 //					"	exports org.astro to com.greetings;\n" + // this export will be added via add-exports
4683 					"}",
4684 					"src/org/astro/World.java",
4685 					"package org.astro;\n" +
4686 					"public interface World {\n" +
4687 					"	public String name();\n" +
4688 					"}"
4689 			};
4690 			IJavaProject p1 = setupModuleProject("morg.astro", sources);
4691 			IClasspathAttribute modAttr = new ClasspathAttribute("module", "true");
4692 			IClasspathAttribute addExports = new ClasspathAttribute(IClasspathAttribute.ADD_EXPORTS, "morg.astro/org.astro=com.greetings");
4693 			IClasspathEntry dep = JavaCore.newProjectEntry(p1.getPath(), null, false,
4694 															new IClasspathAttribute[] {modAttr, addExports},
4695 															false/*not exported*/);
4696 			String[] src = new String[] {
4697 					"src/module-info.java",
4698 					"module com.greetings {\n" +
4699 					"	requires morg.astro;\n" +
4700 					"	exports com.greetings;\n" +
4701 					"}",
4702 					"src/com/greetings/MyWorld.java",
4703 					"package com.greetings;\n" +
4704 					"import org.astro.World;\n" +
4705 					"public class MyWorld implements World {\n" +
4706 					"	public String name() {\n" +
4707 					"		return \" My World!!\";\n" +
4708 					"	}\n" +
4709 					"}"
4710 			};
4711 			IJavaProject p2 = setupModuleProject("com.greetings", src, new IClasspathEntry[] { dep });
4712 			p2.getProject().getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, null);
4713 			IMarker[] markers = p2.getProject().findMarkers(null, true, IResource.DEPTH_INFINITE);
4714 			assertMarkers("Unexpected markers",	"",  markers);
4715 		} finally {
4716 			deleteProject("morg.astro");
4717 			deleteProject("com.greetings");
4718 		}
4719 	}
testAddExports2()4720 	public void testAddExports2() throws CoreException {
4721 		try {
4722 			String[] sources = new String[] {
4723 					"src/module-info.java",
4724 					"module morg.astro {\n" +
4725 //					"	exports org.astro to com.greetings;\n" + // this export will be added via add-exports
4726 //					"	exports org.eclipse to com.greetings;\n" + // this export will be added via add-exports
4727 					"}",
4728 					"src/org/astro/World.java",
4729 					"package org.astro;\n" +
4730 					"public interface World {\n" +
4731 					"	public String name();\n" +
4732 					"}",
4733 					"src/org/eclipse/Planet.java",
4734 					"package org.eclipse;\n" +
4735 					"public class Planet {}\n"
4736 			};
4737 			IJavaProject p1 = setupModuleProject("morg.astro", sources);
4738 			IClasspathAttribute modAttr = new ClasspathAttribute("module", "true");
4739 			IClasspathAttribute addExports = new ClasspathAttribute(IClasspathAttribute.ADD_EXPORTS,
4740 						"morg.astro/org.astro=com.greetings:morg.astro/org.eclipse=com.greetings");
4741 			IClasspathEntry dep = JavaCore.newProjectEntry(p1.getPath(), null, false,
4742 															new IClasspathAttribute[] {modAttr, addExports},
4743 															false/*not exported*/);
4744 			String[] src = new String[] {
4745 					"src/module-info.java",
4746 					"module com.greetings {\n" +
4747 					"	requires morg.astro;\n" +
4748 					"	exports com.greetings;\n" +
4749 					"}",
4750 					"src/com/greetings/MyWorld.java",
4751 					"package com.greetings;\n" +
4752 					"import org.astro.World;\n" +
4753 					"public class MyWorld implements World {\n" +
4754 					"	org.eclipse.Planet planet;\n" +
4755 					"	public String name() {\n" +
4756 					"		return \" My World!!\";\n" +
4757 					"	}\n" +
4758 					"}"
4759 			};
4760 			IJavaProject p2 = setupModuleProject("com.greetings", src, new IClasspathEntry[] { dep });
4761 			p2.getProject().getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, null);
4762 			IMarker[] markers = p2.getProject().findMarkers(null, true, IResource.DEPTH_INFINITE);
4763 			assertMarkers("Unexpected markers",	"",  markers);
4764 		} finally {
4765 			deleteProject("morg.astro");
4766 			deleteProject("com.greetings");
4767 		}
4768 	}
testAddReads()4769 	public void testAddReads() throws CoreException, IOException {
4770 		try {
4771 			// org.astro defines the "real" org.astro.World:
4772 			String[] sources = new String[] {
4773 					"src/module-info.java",
4774 					"module org.astro {\n" +
4775 					"	exports org.astro;\n" +
4776 					"}",
4777 					"src/org/astro/World.java",
4778 					"package org.astro;\n" +
4779 					"public interface World {\n" +
4780 					"	public String name();\n" +
4781 					"}"
4782 			};
4783 			IJavaProject p = setupModuleProject("org.astro", sources);
4784 
4785 			// build mod.one with a private copy of org.astro.World:
4786 			String[] src1 = new String[] {
4787 					"src/module-info.java",
4788 					"module mod.one {\n" +
4789 					"	exports one.p;\n" +
4790 					"}\n",
4791 					"src/org/astro/World.java",
4792 					"package org.astro;\n" +
4793 					"public interface World { public String name(); }\n",
4794 					"src/one/p/C.java",
4795 					"package one.p;\n" +
4796 					"public class C {\n" +
4797 					"	public void test(org.astro.World w) {\n" +
4798 					"		System.out.println(w.name());\n" +
4799 					"	}\n" +
4800 					"}\n"
4801 			};
4802 			IClasspathAttribute modAttr = new ClasspathAttribute("module", "true");
4803 			IClasspathEntry dep = JavaCore.newProjectEntry(p.getPath(), null, false,
4804 															new IClasspathAttribute[] { modAttr },
4805 															false/*not exported*/);
4806 			IJavaProject p1 = setupModuleProject("mod.one", src1, new IClasspathEntry[] { dep });
4807 			p1.setOption(JavaCore.COMPILER_PB_API_LEAKS, JavaCore.IGNORE); // the stub org.astro.World is not exported but used in API
4808 			p1.getProject().getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, null);
4809 			IMarker[] markers = p1.getProject().findMarkers(null, true, IResource.DEPTH_INFINITE);
4810 			assertMarkers("Unexpected markers",	"",  markers);
4811 
4812 			// jar-up without the private copy:
4813 			deleteFile("/mod.one/src/org/astro/World.java");
4814 			deleteFile("/mod.one/bin/org/astro/World.class");
4815 			String modOneJarPath = getWorkspacePath()+File.separator+"mod.one.jar";
4816 			Util.zip(new File(getWorkspacePath()+"/mod.one/bin"), modOneJarPath);
4817 
4818 			// com.greetings depends on both other modules:
4819 			String[] src2 = new String[] {
4820 				"src/module-info.java",
4821 				"module com.greetings {\n" +
4822 				"	requires org.astro;\n" +
4823 				"	requires mod.one;\n" +
4824 				"}",
4825 				"src/com/greetings/MyTest.java",
4826 				"package com.greetings;\n" +
4827 				"public class MyTest {\n" +
4828 				"	public void test(one.p.C c, org.astro.World w) {\n" +
4829 				"		c.test(w);\n" +
4830 				"	}\n" +
4831 				"}"
4832 			};
4833 			IClasspathEntry dep1 = JavaCore.newProjectEntry(p.getPath(), null, false,
4834 															new IClasspathAttribute[] {new ClasspathAttribute("module", "true")},
4835 															false/*not exported*/);
4836 			// need to re-wire dependency mod.one -> org.astro for resolving one.p.C:
4837 			IClasspathEntry dep2 = JavaCore.newLibraryEntry(new Path(modOneJarPath), null, null, null,
4838 															new IClasspathAttribute[] {
4839 																	new ClasspathAttribute("module", "true"),
4840 																	new ClasspathAttribute(IClasspathAttribute.ADD_READS, "mod.one=org.astro")
4841 															},
4842 															false/*not exported*/);
4843 			IJavaProject p2 = setupModuleProject("com.greetings", src2, new IClasspathEntry[] { dep1, dep2 });
4844 			p2.getProject().getWorkspace().build(IncrementalProjectBuilder.INCREMENTAL_BUILD, null);
4845 			markers = p2.getProject().findMarkers(null, true, IResource.DEPTH_INFINITE);
4846 			assertMarkers("Unexpected markers",	"",  markers);
4847 
4848 			// check that reconcile respects --add-reads, too:
4849 			this.problemRequestor.reset();
4850 			ICompilationUnit cu = getCompilationUnit("/com.greetings/src/com/greetings/MyTest.java");
4851 			cu.getWorkingCopy(this.wcOwner, null);
4852 			assertProblems(
4853 				"Unexpected problems",
4854 				"----------\n" +
4855 				"----------\n",
4856 				this.problemRequestor);
4857 
4858 		} finally {
4859 			deleteProject("mod.one");
4860 			deleteProject("org.astro");
4861 			deleteProject("com.greetings");
4862 		}
4863 	}
testBug520147c()4864 	public void testBug520147c() throws CoreException, IOException {
4865 		Hashtable<String, String> javaCoreOptions = JavaCore.getOptions();
4866 		try {
4867 			String[] src = new String[] {
4868 					"src/module-info.java",
4869 					"module org.astro {\n" +
4870 					"	exports org.astro;\n" +
4871 					"}",
4872 					"src/org/astro/World.java",
4873 					"package org.astro;\n" +
4874 					"public interface World {\n" +
4875 					"	public String name();\n" +
4876 					"}"
4877 			};
4878 			IJavaProject p1 = setupModuleProject("org.astro", src);
4879 			src = new String[] {
4880 				"src/org/eclipse/pack1/SomeWorld.java",
4881 				"package org.eclipse.pack1;\n" +
4882 				"import  org.astro.World;\n" +
4883 				"public class SomeWorld implements World {\n" +
4884 				"	public String name() {\n" +
4885 				"		return \" Some World!!\";\n" +
4886 				"	}\n" +
4887 				"}"
4888 			};
4889 			IClasspathAttribute modAttr = new ClasspathAttribute("module", "true");
4890 			IClasspathEntry dep = JavaCore.newProjectEntry(p1.getPath(), null, false, new IClasspathAttribute[] {modAttr}, false);
4891 			IJavaProject p2 = setupModuleProject("com.greetings", src, new IClasspathEntry[] {dep});
4892 			getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, null);
4893 			src = new String[] {
4894 				"src/module-info.java",
4895 				"module test {\n" +
4896 				"	exports test;\n" +
4897 				"	requires com.greetings;\n" +
4898 				"	requires org.astro;\n" +
4899 				"}",
4900 				"src/test/Main.java",
4901 				"package test;\n" +
4902 				"import org.eclipse.pack1.SomeWorld;\n" +
4903 				"public class Main {\n" +
4904 				"	public static void main(String[] args) {\n" +
4905 				"		org.astro.World world = new SomeWorld();\n" +
4906 				"		System.out.println(world.name());\n" +
4907 				"	}\n" +
4908 				"}"
4909 			};
4910 			IClasspathEntry dep2 = JavaCore.newProjectEntry(p2.getPath(), null, false, new IClasspathAttribute[] {modAttr}, false);
4911 			IJavaProject p3 = setupModuleProject("test", src, new IClasspathEntry[] {dep, dep2});
4912 			getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, null);
4913 			IMarker[] markers = p3.getProject().findMarkers(null, true, IResource.DEPTH_INFINITE);
4914 			assertMarkers("Unexpected markers",
4915 					"Name of automatic module \'com.greetings\' is unstable, it is derived from the module\'s file name.",
4916 					markers);
4917 		} finally {
4918 			this.deleteProject("test");
4919 			this.deleteProject("com.greetings");
4920 			this.deleteProject("org.astro");
4921 			JavaCore.setOptions(javaCoreOptions);
4922 		}
4923 	}
4924 	@Deprecated
testBug519935()4925 	public void testBug519935() throws CoreException, IOException {
4926 		Hashtable<String, String> javaCoreOptions = JavaCore.getOptions();
4927 		try {
4928 			String[] src = new String[] {
4929 				"src/module-info.java",
4930 				"module org.astro {\n" +
4931 				"	exports org.astro;\n" +
4932 				"}",
4933 				"src/org/astro/World.java",
4934 				"package org.astro;\n" +
4935 				"public interface World {\n" +
4936 				"	public String name();\n" +
4937 				"}"
4938 			};
4939 			IJavaProject p1 = setupModuleProject("org.astro", src);
4940 			src = new String[] {
4941 				"src/org/eclipse/pack/Test.java",
4942 				"package org.eclipse.pack;\n" +
4943 				"import org.astro.World;\n" +
4944 				"public class Test implements World {\n" +
4945 				"	public String name() {\n" +
4946 				"		return \" My World!!\";\n" +
4947 				"	}\n" +
4948 				"}"
4949 			};
4950 			IClasspathEntry dep = JavaCore.newProjectEntry(p1.getPath());
4951 			IJavaProject p2 = setupModuleProject("test", src, new IClasspathEntry[] {dep});
4952 			getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, null);
4953 			src = new String[] {
4954 				"src/module-info.java",
4955 				"module test_automodules {\n" +
4956 				"	requires bin;\n" +
4957 				"	requires org.astro;\n" +
4958 				"}",
4959 				"src/test/Main.java",
4960 				"package test;\n" +
4961 				"import org.eclipse.pack.Test;\n" +
4962 				"import org.astro.*;\n" +
4963 				"public class Main {\n" +
4964 				"	public static void main(String[] args) {\n" +
4965 				"		World world = new Test();\n" +
4966 				"		System.out.println(world.name());\n" +
4967 				"	}\n" +
4968 				"}"
4969 			};
4970 			IClasspathAttribute modAttr = new ClasspathAttribute("module", "true");
4971 			dep = JavaCore.newLibraryEntry(p2.getProject().findMember("bin").getFullPath(), null, null,
4972 				ClasspathEntry.NO_ACCESS_RULES,
4973 				new IClasspathAttribute[] {modAttr},
4974 				false/*not exported*/);
4975 			modAttr = new ClasspathAttribute("module", "true");
4976 			IClasspathEntry dep2 = JavaCore.newProjectEntry(p1.getPath(), null, true,
4977 				new IClasspathAttribute[] {modAttr},
4978 				false/*not exported*/);
4979 			setupModuleProject("testSOE", src, new IClasspathEntry[] {dep, dep2});
4980 			this.workingCopies = new ICompilationUnit[1];
4981 			this.workingCopies[0] = getCompilationUnit("/testSOE/src/test/Main.java").getWorkingCopy(this.wcOwner, null);
4982 			this.problemRequestor.initialize(src[3].toCharArray());
4983 			CompilationUnit unit = this.workingCopies[0].reconcile(AST.JLS9, true, this.wcOwner, null);
4984 			assertNotNull("Could not reconcile", unit);
4985 		} finally {
4986 			this.deleteProject("test");
4987 			this.deleteProject("testSOE");
4988 			this.deleteProject("org.astro");
4989 			JavaCore.setOptions(javaCoreOptions);
4990 		}
4991 	}
4992 	@Deprecated
testBug520310()4993 	public void testBug520310() throws CoreException, IOException {
4994 		try {
4995 			String[] src = new String[] {
4996 				"src/module-info.java",
4997 				"module mod.one {\n" +
4998 //				"	requires mod.two;\n" +
4999 				"	exports org.astro;\n" +
5000 				"}",
5001 				"src/org/astro/World.java",
5002 				"package org.astro;\n" +
5003 				"public interface World {\n" +
5004 				"	public String name();\n" +
5005 				"}"
5006 			};
5007 			IClasspathEntry modDep = JavaCore.newContainerEntry(new Path(JavaCore.MODULE_PATH_CONTAINER_ID));
5008 			IJavaProject p1 = setupModuleProject("mod.one", src, new IClasspathEntry[] {modDep});
5009 
5010 			src = new String[] {
5011 					"src/module-info.java",
5012 					"module mod.two {\n" +
5013 					"	requires mod.one;\n" +
5014 					"	exports test;\n" +
5015 					"}",
5016 					"src/test/Test.java",
5017 					"package test;\n" +
5018 					"import org.astro.World;\n" +
5019 					"public class Test implements World {\n" +
5020 					"	public String name() {\n" +
5021 					"		return \" My World!!\";\n" +
5022 					"	}\n" +
5023 					"}"
5024 			};
5025 			IJavaProject p2 = setupModuleProject("mod.two", src, new IClasspathEntry[] {modDep});
5026 
5027 			getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, null);
5028 			IMarker[] markers = p1.getProject().findMarkers(null, true, IResource.DEPTH_INFINITE);
5029 			assertMarkers("Unexpected markers in mod.one", "", markers);
5030 			markers = p2.getProject().findMarkers(null, true, IResource.DEPTH_INFINITE);
5031 			assertMarkers("Unexpected markers in mod.two", "", markers);
5032 
5033 			editFile("/mod.one/src/module-info.java",
5034 				"module mod.one {\n" +
5035 				"	requires mod.two;\n" + // added
5036 				"	exports org.astro;\n" +
5037 				"}");
5038 			getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, null);
5039 			getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, null); // modules see each other only on 2nd attempt, don't ask me...
5040 			markers = p1.getProject().findMarkers(null, true, IResource.DEPTH_INFINITE);
5041 			assertMarkers("Unexpected markers in mod.one",
5042 					"Cycle exists in module dependencies, Module mod.one requires itself via mod.two",
5043 					markers);
5044 			markers = p2.getProject().findMarkers(null, true, IResource.DEPTH_INFINITE);
5045 			sortMarkers(markers);
5046 			assertMarkers("Unexpected markers in mod.two",
5047 					"The type org.astro.World is not accessible\n" + // cannot use cyclic requires
5048 					"Cycle exists in module dependencies, Module mod.two requires itself via mod.one\n" +
5049 					"World cannot be resolved to a type",
5050 					markers);
5051 
5052 			this.workingCopies = new ICompilationUnit[1];
5053 			this.workingCopies[0] = getCompilationUnit("/mod.two/src/module-info.java").getWorkingCopy(this.wcOwner, null);
5054 			this.problemRequestor.initialize(src[1].toCharArray());
5055 			CompilationUnit unit = this.workingCopies[0].reconcile(AST.JLS9, true, this.wcOwner, null);
5056 			assertNotNull("Could not reconcile", unit);
5057 		} finally {
5058 			this.deleteProject("mod.one");
5059 			this.deleteProject("mod.two");
5060 		}
5061 	}
testBug521346()5062 	public void testBug521346() throws CoreException, IOException {
5063 		IJavaProject javaProject = null;
5064 		try {
5065 			String src =
5066 					"import java.*;\n" +
5067 					"public class X {\n" +
5068 					"    public static void main(String[] args) {\n" +
5069 					"        System.out.println(true);\n" +
5070 					"    }\n" +
5071 					"}";
5072 			javaProject = createJava9Project("Test");
5073 			this.problemRequestor.initialize(src.toCharArray());
5074 			getWorkingCopy("/Test/src/X.java", src, true);
5075 			assertProblems("should have not problems",
5076 					"----------\n" +
5077 					"1. ERROR in /Test/src/X.java (at line 1)\n" +
5078 					"	import java.*;\n" +
5079 					"	       ^^^^\n" +
5080 					"The package java is not accessible\n" +
5081 					"----------\n",
5082 					this.problemRequestor);
5083 		} finally {
5084 			if (javaProject != null)
5085 				deleteProject(javaProject);
5086 		}
5087 	}
testAutoModule1()5088 	public void testAutoModule1() throws Exception {
5089 		IJavaProject javaProject = null;
5090 		try {
5091 			String[] sources = {
5092 				"p/a/X.java",
5093 				"package p.a;\n" +
5094 				"public class X {}\n;"
5095 			};
5096 			String outputDirectory = Util.getOutputDirectory();
5097 
5098 			String jarPath = outputDirectory + File.separator + "lib-x.jar";
5099 			Util.createJar(sources, jarPath, "1.8");
5100 
5101 			javaProject = createJava9Project("mod.one", new String[] {"src"});
5102 			IClasspathAttribute[] attributes = { JavaCore.newClasspathAttribute(IClasspathAttribute.MODULE, "true") };
5103 			addClasspathEntry(javaProject, JavaCore.newLibraryEntry(new Path(jarPath), null, null, null, attributes, false));
5104 
5105 			String srcMod =
5106 				"module mod.one { \n" +
5107 				"	requires lib.x;\n" + // lib.x is derived from lib-x.jar
5108 				"}";
5109 			createFile("/mod.one/src/module-info.java",
5110 				srcMod);
5111 			createFolder("mod.one/src/q");
5112 			String srcX =
5113 				"package q;\n" +
5114 				"public class X {\n" +
5115 				"	p.a.X f;\n" +
5116 				"}";
5117 			createFile("/mod.one/src/q/X.java", srcX);
5118 
5119 			this.problemRequestor.initialize(srcMod.toCharArray());
5120 			getWorkingCopy("/mod.one/module-info.java", srcMod, true);
5121 			assertProblems("module-info should have one warning",
5122 					"----------\n" +
5123 					"1. WARNING in /mod.one/module-info.java (at line 2)\n" +
5124 					"	requires lib.x;\n" +
5125 					"	         ^^^^^\n" +
5126 					"Name of automatic module \'lib.x\' is unstable, it is derived from the module\'s file name.\n" +
5127 					"----------\n",
5128 					this.problemRequestor);
5129 
5130 			this.problemRequestor.initialize(srcX.toCharArray());
5131 			getWorkingCopy("/mod.one/src/q/X.java", srcX, true);
5132 			assertProblems("X should have no problems",
5133 					"----------\n" +
5134 					"----------\n",
5135 					this.problemRequestor);
5136 
5137 			javaProject.getProject().build(IncrementalProjectBuilder.FULL_BUILD, null);
5138 			assertNoErrors();
5139 		} finally {
5140 			if (javaProject != null)
5141 				deleteProject(javaProject);
5142 		}
5143 	}
testAutoModule2()5144 	public void testAutoModule2() throws Exception {
5145 		IJavaProject javaProject = null;
5146 		try {
5147 			String[] sources = {
5148 				"p/a/X.java",
5149 				"package p.a;\n" +
5150 				"public class X {}\n;",
5151 			};
5152 			String[] mfSource = {
5153 				"META-INF/MANIFEST.MF",
5154 				"Manifest-Version: 1.0\n" +
5155 				"Automatic-Module-Name: org.eclipse.lib.x\n"
5156 			};
5157 			String outputDirectory = Util.getOutputDirectory();
5158 
5159 			String jarPath = outputDirectory + File.separator + "lib-x.jar";
5160 			Util.createJar(sources, mfSource, jarPath, "1.8");
5161 
5162 			javaProject = createJava9Project("mod.one", new String[] {"src"});
5163 			IClasspathAttribute[] attributes = { JavaCore.newClasspathAttribute(IClasspathAttribute.MODULE, "true") };
5164 			addClasspathEntry(javaProject, JavaCore.newLibraryEntry(new Path(jarPath), null, null, null, attributes, false));
5165 
5166 			String srcMod =
5167 				"module mod.one { \n" +
5168 				"	requires org.eclipse.lib.x;\n" + // from jar attribute
5169 				"}";
5170 			createFile("/mod.one/src/module-info.java",
5171 				srcMod);
5172 			createFolder("mod.one/src/q");
5173 			String srcX =
5174 				"package q;\n" +
5175 				"public class X {\n" +
5176 				"	p.a.X f;\n" +
5177 				"}";
5178 			createFile("/mod.one/src/q/X.java", srcX);
5179 
5180 			this.problemRequestor.initialize(srcMod.toCharArray());
5181 			getWorkingCopy("/mod.one/module-info.java", srcMod, true);
5182 			assertProblems("module-info should have no problems",
5183 					"----------\n" +
5184 					"----------\n",
5185 					this.problemRequestor);
5186 
5187 			this.problemRequestor.initialize(srcX.toCharArray());
5188 			getWorkingCopy("/mod.one/src/q/X.java", srcX, true);
5189 			assertProblems("X should have no problems",
5190 					"----------\n" +
5191 					"----------\n",
5192 					this.problemRequestor);
5193 
5194 			javaProject.getProject().build(IncrementalProjectBuilder.FULL_BUILD, null);
5195 			assertNoErrors();
5196 		} finally {
5197 			if (javaProject != null)
5198 				deleteProject(javaProject);
5199 		}
5200 	}
testAutoModule3()5201 	public void testAutoModule3() throws Exception {
5202 		IJavaProject javaProject = null, auto = null;
5203 		try {
5204 			auto = createJava9Project("auto", new String[] {"src"});
5205 			createFolder("auto/src/p/a");
5206 			createFile("auto/src/p/a/X.java",
5207 				"package p.a;\n" +
5208 				"public class X {}\n;");
5209 			createFolder("auto/META-INF");
5210 			createFile("auto/META-INF/MANIFEST.MF",
5211 				"Manifest-Version: 1.0\n" +
5212 				"Automatic-Module-Name: org.eclipse.lib.x\n");
5213 
5214 			javaProject = createJava9Project("mod.one", new String[] {"src"});
5215 			IClasspathAttribute[] attributes = { JavaCore.newClasspathAttribute(IClasspathAttribute.MODULE, "true") };
5216 			addClasspathEntry(javaProject, JavaCore.newProjectEntry(auto.getPath(), null, false, attributes, false));
5217 
5218 			String srcMod =
5219 				"module mod.one { \n" +
5220 				"	requires org.eclipse.lib.x;\n" + // from manifest attribute
5221 				"}";
5222 			createFile("/mod.one/src/module-info.java",
5223 				srcMod);
5224 			createFolder("mod.one/src/q");
5225 			String srcX =
5226 				"package q;\n" +
5227 				"public class X {\n" +
5228 				"	p.a.X f;\n" +
5229 				"}";
5230 			createFile("/mod.one/src/q/X.java", srcX);
5231 			auto.getProject().build(IncrementalProjectBuilder.FULL_BUILD, null);
5232 
5233 			this.problemRequestor.initialize(srcMod.toCharArray());
5234 			getWorkingCopy("/mod.one/module-info.java", srcMod, true);
5235 			assertProblems("module-info should have no problems",
5236 					"----------\n" +
5237 					"----------\n",
5238 					this.problemRequestor);
5239 
5240 			this.problemRequestor.initialize(srcX.toCharArray());
5241 			getWorkingCopy("/mod.one/src/q/X.java", srcX, true);
5242 			assertProblems("X should have no problems",
5243 					"----------\n" +
5244 					"----------\n",
5245 					this.problemRequestor);
5246 
5247 			javaProject.getProject().build(IncrementalProjectBuilder.FULL_BUILD, null);
5248 			assertNoErrors();
5249 		} finally {
5250 			if (javaProject != null)
5251 				deleteProject(javaProject);
5252 			if (auto != null)
5253 				deleteProject(auto);
5254 		}
5255 	}
5256 
testAutoModule4()5257 	public void testAutoModule4() throws Exception {
5258 		IJavaProject javaProject = null;
5259 		IJavaProject javaProject2 = null;
5260 		try {
5261 			// auto module as jar:
5262 			String[] sources = {
5263 				"p/a/X.java",
5264 				"package p.a;\n" +
5265 				"public class X {}\n;",
5266 			};
5267 			String[] mfSource = {
5268 				"META-INF/MANIFEST.MF",
5269 				"Manifest-Version: 1.0\n" +
5270 				"Automatic-Module-Name: org.eclipse.lib.x\n" // automatic module reads all (incl. mod.one below)
5271 			};
5272 			String outputDirectory = Util.getOutputDirectory();
5273 
5274 			String jarPath = outputDirectory + File.separator + "lib-x.jar";
5275 			Util.createJar(sources, mfSource, jarPath, "1.8");
5276 
5277 			// first source module:
5278 			javaProject = createJava9Project("mod.one", new String[] {"src"});
5279 			IClasspathAttribute[] attributes = { JavaCore.newClasspathAttribute(IClasspathAttribute.MODULE, "true") };
5280 			addClasspathEntry(javaProject, JavaCore.newLibraryEntry(new Path(jarPath), null, null, null, attributes, false));
5281 
5282 			String srcMod =
5283 				"module mod.one { \n" +
5284 				"	requires org.eclipse.lib.x;\n" + // creates cycle mod.one -> org.eclipse.lib.x -> mod.one
5285 				"	exports p.q.api;\n" +
5286 				"}";
5287 			createFile("/mod.one/src/module-info.java", srcMod);
5288 			createFolder("mod.one/src/p/q/api");
5289 			String srcX =
5290 				"package p.q.api;\n" +
5291 				"public class X {\n" +
5292 				"	p.a.X f;\n" +
5293 				"}";
5294 			createFile("/mod.one/src/p/q/api/X.java", srcX);
5295 
5296 			// second source module:
5297 			javaProject2 = createJava9Project("mod.two", new String[] {"src"});
5298 			addClasspathEntry(javaProject2, JavaCore.newProjectEntry(new Path("/mod.one"), null, false, attributes, false));
5299 			addClasspathEntry(javaProject2, JavaCore.newLibraryEntry(new Path(jarPath), null, null, null, attributes, false));
5300 			String srcMod2 =
5301 				"module mod.two { \n" +
5302 				"	requires mod.one;\n" +
5303 				"}";
5304 			createFile("/mod.two/src/module-info.java", srcMod2);
5305 			createFolder("mod.two/src/p/q");
5306 			String srcY =
5307 				"package p.q;\n" +
5308 				"import p.q.api.X;\n" + // here we saw "The package p.q.api is accessible from more than one module: mod.one, mod.one"
5309 				"public class Y {\n" +
5310 				"	X f;\n" +
5311 				"}";
5312 			createFile("/mod.two/src/p/q/Y.java", srcY);
5313 
5314 			this.problemRequestor.initialize(srcMod.toCharArray());
5315 			getWorkingCopy("/mod.one/module-info.java", srcMod, true);
5316 			assertProblems("module-info should have no problems",
5317 					"----------\n" +
5318 					"----------\n",
5319 					this.problemRequestor);
5320 
5321 			this.problemRequestor.initialize(srcX.toCharArray());
5322 			getWorkingCopy("/mod.one/src/p/q/api/X.java", srcX, true);
5323 			assertProblems("X should have no problems",
5324 					"----------\n" +
5325 					"----------\n",
5326 					this.problemRequestor);
5327 
5328 			this.problemRequestor.initialize(srcY.toCharArray());
5329 			getWorkingCopy("/mod.two/src/p/q/Y.java", srcY, true);
5330 			assertProblems("Y should have no problems",
5331 					"----------\n" +
5332 					"----------\n",
5333 					this.problemRequestor);
5334 
5335 			javaProject.getProject().build(IncrementalProjectBuilder.FULL_BUILD, null);
5336 			assertProblemMarkers("markers in mod.one", "", javaProject.getProject());
5337 
5338 			javaProject2.getProject().build(IncrementalProjectBuilder.FULL_BUILD, null);
5339 			assertProblemMarkers("markers in mod.two", "", javaProject2.getProject());
5340 
5341 			javaProject.getProject().getWorkspace().build(IncrementalProjectBuilder.CLEAN_BUILD, null);
5342 			assertNoErrors();
5343 		} finally {
5344 			if (javaProject != null)
5345 				deleteProject(javaProject);
5346 			if (javaProject2 != null)
5347 				deleteProject(javaProject2);
5348 		}
5349 	}
5350 	// like testAutoModule3 without name derived from project, not manifest - warning suppressed
testAutoModule5()5351 	public void testAutoModule5() throws Exception {
5352 		IJavaProject javaProject = null, auto = null;
5353 		try {
5354 			auto = createJava9Project("auto", new String[] {"src"});
5355 			createFolder("auto/src/p/a");
5356 			createFile("auto/src/p/a/X.java",
5357 				"package p.a;\n" +
5358 				"public class X {}\n;");
5359 
5360 			javaProject = createJava9Project("mod.one", new String[] {"src"});
5361 			IClasspathAttribute[] attributes = { JavaCore.newClasspathAttribute(IClasspathAttribute.MODULE, "true") };
5362 			addClasspathEntry(javaProject, JavaCore.newProjectEntry(auto.getPath(), null, false, attributes, false));
5363 
5364 			String srcMod =
5365 				"@SuppressWarnings(\"module\")\n" +
5366 				"module mod.one { \n" +
5367 				"	requires auto;\n" +
5368 				"}";
5369 			createFile("/mod.one/src/module-info.java",
5370 				srcMod);
5371 			createFolder("mod.one/src/q");
5372 			String srcX =
5373 				"package q;\n" +
5374 				"public class X {\n" +
5375 				"	p.a.X f;\n" +
5376 				"}";
5377 			createFile("/mod.one/src/q/X.java", srcX);
5378 			auto.getProject().build(IncrementalProjectBuilder.FULL_BUILD, null);
5379 
5380 			this.problemRequestor.initialize(srcMod.toCharArray());
5381 			getWorkingCopy("/mod.one/module-info.java", srcMod, true);
5382 			assertProblems("module-info should have no problems",
5383 					"----------\n" +
5384 					"----------\n",
5385 					this.problemRequestor);
5386 
5387 			this.problemRequestor.initialize(srcX.toCharArray());
5388 			getWorkingCopy("/mod.one/src/q/X.java", srcX, true);
5389 			assertProblems("X should have no problems",
5390 					"----------\n" +
5391 					"----------\n",
5392 					this.problemRequestor);
5393 
5394 			javaProject.getProject().build(IncrementalProjectBuilder.FULL_BUILD, null);
5395 			assertNoErrors();
5396 		} finally {
5397 			if (javaProject != null)
5398 				deleteProject(javaProject);
5399 			if (auto != null)
5400 				deleteProject(auto);
5401 		}
5402 	}
5403 	// like testAutoModule5, warning configured as ERROR
testAutoModule6()5404 	public void testAutoModule6() throws Exception {
5405 		IJavaProject javaProject = null, auto = null;
5406 		try {
5407 			auto = createJava9Project("auto", new String[] {"src"});
5408 			createFolder("auto/src/p/a");
5409 			createFile("auto/src/p/a/X.java",
5410 				"package p.a;\n" +
5411 				"public class X {}\n;");
5412 
5413 			javaProject = createJava9Project("mod.one", new String[] {"src"});
5414 			IClasspathAttribute[] attributes = { JavaCore.newClasspathAttribute(IClasspathAttribute.MODULE, "true") };
5415 			addClasspathEntry(javaProject, JavaCore.newProjectEntry(auto.getPath(), null, false, attributes, false));
5416 			javaProject.setOption(JavaCore.COMPILER_PB_UNSTABLE_AUTO_MODULE_NAME, JavaCore.ERROR);
5417 
5418 			String srcMod =
5419 				"module mod.one { \n" +
5420 				"	requires auto;\n" +
5421 				"}";
5422 			createFile("/mod.one/src/module-info.java",
5423 				srcMod);
5424 			auto.getProject().build(IncrementalProjectBuilder.FULL_BUILD, null);
5425 
5426 			this.problemRequestor.initialize(srcMod.toCharArray());
5427 			getWorkingCopy("/mod.one/module-info.java", srcMod, true);
5428 			assertProblems("module-info should have only one error",
5429 					"----------\n" +
5430 					"1. ERROR in /mod.one/module-info.java (at line 2)\n" +
5431 					"	requires auto;\n" +
5432 					"	         ^^^^\n" +
5433 					"Name of automatic module \'auto\' is unstable, it is derived from the module\'s file name.\n" +
5434 					"----------\n",
5435 					this.problemRequestor);
5436 		} finally {
5437 			if (javaProject != null)
5438 				deleteProject(javaProject);
5439 			if (auto != null)
5440 				deleteProject(auto);
5441 		}
5442 	}
5443 
5444 	// patch can see unexported type from host (and package accessible method), but not vice versa
testPatch1()5445 	public void testPatch1() throws CoreException, IOException {
5446 		try {
5447 			IJavaProject mainProject = createJava9Project("org.astro");
5448 			String[] sources = {
5449 				"src/module-info.java",
5450 				"module org.astro {\n" + // no exports
5451 				"}",
5452 				"src/org/astro/World.java",
5453 				"package org.astro;\n" +
5454 				"public class World {\n" +
5455 				"	public String name() { return \"world\"; }\n" +
5456 				"	void internalTest() { }\n" +
5457 				"	public org.astro.test.WorldTest test;\n" +
5458 				"}",
5459 			};
5460 			createSourceFiles(mainProject, sources);
5461 
5462 			IJavaProject patchProject = createJava9Project("org.astro.patch");
5463 			IClasspathAttribute[] attributes = {
5464 						JavaCore.newClasspathAttribute(IClasspathAttribute.MODULE, "true"),
5465 						JavaCore.newClasspathAttribute(IClasspathAttribute.PATCH_MODULE, "org.astro")
5466 					};
5467 			addClasspathEntry(patchProject, JavaCore.newProjectEntry(new Path("/org.astro"), null, false, attributes, false));
5468 			String[] patchSources = {
5469 				"src/org/astro/test/WorldTest.java",
5470 				"package org.astro.test;\n" +
5471 				"import org.astro.*;\n" +
5472 				"public class WorldTest {\n" +
5473 				"	void testWorld(World w) {\n" +
5474 				"		w.name();\n" +
5475 				"	}\n" +
5476 				"}\n",
5477 				"src/org/astro/Test2.java",
5478 				"package org.astro;\n" +
5479 				"class Test2 {\n" +
5480 				"	void test(World w) {\n" +
5481 				"		w.internalTest();\n" + // package access
5482 				"	}\n" +
5483 				"}\n"
5484 			};
5485 			createSourceFiles(patchProject, patchSources);
5486 
5487 			getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, null);
5488 			IMarker[] markers = mainProject.getProject().findMarkers(null, true, IResource.DEPTH_INFINITE);
5489 			assertMarkers("Unexpected markers",
5490 					"org.astro.test cannot be resolved to a type", // missing reverse dependency
5491 					markers);
5492 
5493 			this.problemRequestor.reset();
5494 			ICompilationUnit cu = getCompilationUnit("/org.astro.patch/src/org/astro/test/WorldTest.java");
5495 			cu.getWorkingCopy(this.wcOwner, null);
5496 			assertProblems(
5497 				"Unexpected problems",
5498 				"----------\n" +
5499 				"----------\n",
5500 				this.problemRequestor);
5501 
5502 			this.problemRequestor.reset();
5503 			cu = getCompilationUnit("/org.astro/src/org/astro/World.java");
5504 			cu.getWorkingCopy(this.wcOwner, null);
5505 			assertProblems(
5506 				"Unexpected problems",
5507 				"----------\n" +
5508 				"1. ERROR in /org.astro/src/org/astro/World.java\n" +
5509 				"org.astro.test cannot be resolved to a type\n" +
5510 				"----------\n",
5511 				this.problemRequestor);
5512 
5513 		} finally {
5514 			this.deleteProject("org.astro");
5515 			this.deleteProject("org.astro.patch");
5516 		}
5517 	}
5518 
5519 	// patch can see unexported type from host - JRE patched from two source folders
testPatch2()5520 	public void testPatch2() throws CoreException, IOException {
5521 		try {
5522 			IClasspathAttribute[] attributes = {
5523 					JavaCore.newClasspathAttribute(IClasspathAttribute.MODULE, "true"),
5524 					JavaCore.newClasspathAttribute(IClasspathAttribute.PATCH_MODULE, "java.desktop=/missing.path::java.base=/org.astro.patch/src:/org.astro.patch/src2")
5525 			};
5526 			IJavaProject patchProject = createJava9ProjectWithJREAttributes("org.astro.patch", new String[]{"src", "src2"}, attributes);
5527 
5528 			String[] patchSources = {
5529 				"src/org/astro/Test2.java",
5530 				"package org.astro;\n" +
5531 				"class Test2 {\n" +
5532 				"	int test(jdk.internal.misc.Unsafe unsafe) {\n" +
5533 				"		return unsafe.addressSize();\n" +
5534 				"	}\n" +
5535 				"}\n",
5536 				"src2/jdk/internal/misc/Test3.java",
5537 				"package jdk.internal.misc;\n" +
5538 				"class Test3 {\n" +
5539 				"	Signal.NativeHandler handler;\n" + // package access
5540 				"}\n"
5541 			};
5542 			createSourceFiles(patchProject, patchSources);
5543 
5544 			getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, null);
5545 			assertNoErrors();
5546 
5547 			this.problemRequestor.reset();
5548 			ICompilationUnit cu = getCompilationUnit("/org.astro.patch/src/org/astro/Test2.java");
5549 			cu.getWorkingCopy(this.wcOwner, null);
5550 			assertProblems(
5551 				"Unexpected problems",
5552 				"----------\n" +
5553 				"----------\n",
5554 				this.problemRequestor);
5555 
5556 		} finally {
5557 			this.deleteProject("org.astro.patch");
5558 		}
5559 	}
5560 
5561 	// patch can share a package with its host - jar
testPatch3()5562 	public void testPatch3() throws CoreException, IOException {
5563 		try {
5564 			String[] sources = {
5565 				"p/a/X.java",
5566 				"package p.a;\n" +
5567 				"class X {}\n;", // package access
5568 				"module-info.java",
5569 				"module mod.one {\n" + // no exports
5570 				"}\n"
5571 			};
5572 			String outputDirectory = Util.getOutputDirectory();
5573 
5574 			String jarPath = outputDirectory + File.separator + "mod-one.jar";
5575 			Util.createJar(sources, jarPath, "9");
5576 
5577 			IJavaProject patchProject = createJava9Project("mod.one.patch");
5578 			IClasspathAttribute[] attributes = {
5579 					JavaCore.newClasspathAttribute(IClasspathAttribute.MODULE, "true"),
5580 					JavaCore.newClasspathAttribute(IClasspathAttribute.PATCH_MODULE, "mod.one=/mod.one.patch")
5581 			};
5582 			addClasspathEntry(patchProject, JavaCore.newLibraryEntry(new Path(jarPath), null, null, null, attributes, false));
5583 
5584 			String[] patchSources = {
5585 				"src/p/a/Test2.java",
5586 				"package p.a;\n" +
5587 				"class Test2 extends X {\n" +
5588 				"}\n"
5589 			};
5590 			createSourceFiles(patchProject, patchSources);
5591 
5592 			getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, null);
5593 			assertNoErrors();
5594 
5595 			this.problemRequestor.reset();
5596 			ICompilationUnit cu = getCompilationUnit("/mod.one.patch/src/p/a/Test2.java");
5597 			cu.getWorkingCopy(this.wcOwner, null);
5598 			assertProblems(
5599 				"Unexpected problems",
5600 				"----------\n" +
5601 				"----------\n",
5602 				this.problemRequestor);
5603 
5604 		} finally {
5605 			this.deleteProject("mod.one.patch");
5606 		}
5607 	}
testLimitModules1()5608 	public void testLimitModules1() throws CoreException, IOException {
5609 		try {
5610 			IClasspathAttribute[] attributes = {
5611 					JavaCore.newClasspathAttribute(IClasspathAttribute.MODULE, "true"),
5612 					JavaCore.newClasspathAttribute(IClasspathAttribute.LIMIT_MODULES, "java.base,java.desktop")
5613 			};
5614 			IJavaProject project = createJava9ProjectWithJREAttributes("org.astro", new String[]{"src", "src2"}, attributes);
5615 
5616 			String[] sources = {
5617 				"src/module-info.java",
5618 				"module org.astro {\n" +
5619 				"	requires java.base;\n" +
5620 				"	requires java.desktop;\n" +
5621 				"	requires java.datatransfer;\n" + // within the closure of java.desktop
5622 				"	requires java.sql;\n" + // not included
5623 				"}\n",
5624 				"src/org/astro/Test2.java",
5625 				"package org.astro;\n" +
5626 				"class Test2 {\n" +
5627 				"	java.awt.Window window;\n" +
5628 				"}\n",
5629 				"src2/org/astro/Test3.java",
5630 				"package org.astro;\n" +
5631 				"class Test3 {\n" +
5632 				"	java.awt.datatransfer.Clipboard clippy;\n" +
5633 				"}\n"
5634 			};
5635 			createSourceFiles(project, sources);
5636 
5637 			getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, null);
5638 			IMarker[] markers = project.getProject().findMarkers(null, true, IResource.DEPTH_INFINITE);
5639 			assertMarkers("Unexpected markers",
5640 					"java.sql cannot be resolved to a module", // outside limited scope
5641 					markers);
5642 
5643 			this.problemRequestor.reset();
5644 			ICompilationUnit cu = getCompilationUnit("/org.astro/src/module-info.java");
5645 			cu.getWorkingCopy(this.wcOwner, null);
5646 			assertProblems(
5647 				"Unexpected problems",
5648 				"----------\n" +
5649 				"1. ERROR in /org.astro/src/module-info.java\n" +
5650 				"java.sql cannot be resolved to a module\n" +
5651 				"----------\n",
5652 				this.problemRequestor);
5653 
5654 			this.problemRequestor.reset();
5655 			cu = getCompilationUnit("/org.astro/src/org/astro/Test2.java");
5656 			cu.getWorkingCopy(this.wcOwner, null);
5657 			assertProblems(
5658 				"Unexpected problems",
5659 				"----------\n" +
5660 				"----------\n",
5661 				this.problemRequestor);
5662 
5663 			this.problemRequestor.reset();
5664 			cu = getCompilationUnit("/org.astro/src/org/astro/Test3.java");
5665 			cu.getWorkingCopy(this.wcOwner, null);
5666 			assertProblems(
5667 				"Unexpected problems",
5668 				"----------\n" +
5669 				"----------\n",
5670 				this.problemRequestor);
5671 
5672 		} finally {
5673 			this.deleteProject("org.astro");
5674 		}
5675 	}
testLimitModules2()5676 	public void testLimitModules2() throws CoreException, IOException {
5677 		try {
5678 			IClasspathAttribute[] attributes = {
5679 					JavaCore.newClasspathAttribute(IClasspathAttribute.MODULE, "true"),
5680 					JavaCore.newClasspathAttribute(IClasspathAttribute.LIMIT_MODULES, "java.se") // test transitive closure
5681 			};
5682 			IJavaProject project = createJava9ProjectWithJREAttributes("org.astro", new String[]{"src", "src2"}, attributes);
5683 
5684 			String[] sources = {
5685 				"src/module-info.java",
5686 				"module org.astro {\n" +
5687 				"	requires java.base;\n" +
5688 				"	requires java.desktop;\n" +
5689 				"	requires java.datatransfer;\n" +
5690 				"	requires java.sql;\n" +
5691 				"}\n",
5692 				"src/org/astro/Test2.java",
5693 				"package org.astro;\n" +
5694 				"class Test2 {\n" +
5695 				"	java.awt.Window window;\n" +
5696 				"}\n",
5697 				"src2/org/astro/Test3.java",
5698 				"package org.astro;\n" +
5699 				"class Test3 {\n" +
5700 				"	java.awt.datatransfer.Clipboard clippy;\n" +
5701 				"}\n"
5702 			};
5703 			createSourceFiles(project, sources);
5704 
5705 			getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, null);
5706 			IMarker[] markers = project.getProject().findMarkers(null, true, IResource.DEPTH_INFINITE);
5707 			assertMarkers("Unexpected markers",
5708 					"",
5709 					markers);
5710 
5711 			this.problemRequestor.reset();
5712 			ICompilationUnit cu = getCompilationUnit("/org.astro/src/module-info.java");
5713 			cu.getWorkingCopy(this.wcOwner, null);
5714 			assertProblems(
5715 				"Unexpected problems",
5716 				"----------\n" +
5717 				"----------\n",
5718 				this.problemRequestor);
5719 
5720 			this.problemRequestor.reset();
5721 			cu = getCompilationUnit("/org.astro/src/org/astro/Test2.java");
5722 			cu.getWorkingCopy(this.wcOwner, null);
5723 			assertProblems(
5724 				"Unexpected problems",
5725 				"----------\n" +
5726 				"----------\n",
5727 				this.problemRequestor);
5728 
5729 			this.problemRequestor.reset();
5730 			cu = getCompilationUnit("/org.astro/src/org/astro/Test3.java");
5731 			cu.getWorkingCopy(this.wcOwner, null);
5732 			assertProblems(
5733 				"Unexpected problems",
5734 				"----------\n" +
5735 				"----------\n",
5736 				this.problemRequestor);
5737 
5738 		} finally {
5739 			this.deleteProject("org.astro");
5740 		}
5741 	}
testDefaultRootModules()5742 	public void testDefaultRootModules() throws CoreException, IOException {
5743 		try {
5744 
5745 			IJavaProject project = createJava9Project("org.astro", new String[]{"src"});
5746 
5747 			String[] sources = {
5748 				"src/org/astro/ProblemWithPostConstruct.java",
5749 				"package org.astro;\n" +
5750 				"import javax.annotation.PostConstruct;\n" +
5751 				"\n" +
5752 				"public class ProblemWithPostConstruct {\n" +
5753 				"	@PostConstruct void init() {}\n" +
5754 				"}\n"
5755 			};
5756 			createSourceFiles(project, sources);
5757 
5758 			getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, null);
5759 			IMarker[] markers = project.getProject().findMarkers(null, true, IResource.DEPTH_INFINITE);
5760 			sortMarkers(markers);
5761 			assertMarkers("Unexpected markers",
5762 					"The import javax.annotation.PostConstruct cannot be resolved\n" +
5763 					"PostConstruct cannot be resolved to a type", // not in default root modules: java.xml.ws.annotation
5764 					markers);
5765 
5766 			this.problemRequestor.reset();
5767 			ICompilationUnit cu = getCompilationUnit("/org.astro/src/org/astro/ProblemWithPostConstruct.java");
5768 			cu.getWorkingCopy(this.wcOwner, null);
5769 			assertProblems(
5770 				"Unexpected problems",
5771 				"----------\n" +
5772 				"1. ERROR in /org.astro/src/org/astro/ProblemWithPostConstruct.java\n" +
5773 				"The import javax.annotation.PostConstruct cannot be resolved\n" +
5774 				"----------\n" +
5775 				"2. ERROR in /org.astro/src/org/astro/ProblemWithPostConstruct.java\n" +
5776 				"PostConstruct cannot be resolved to a type\n" +
5777 				"----------\n",
5778 				this.problemRequestor);
5779 		} finally {
5780 			this.deleteProject("org.astro");
5781 		}
5782 	}
testBug522398()5783 	public void testBug522398() throws CoreException {
5784 		try {
5785 
5786 			String[] sources = new String[] {
5787 				"src/javax/xml/mysubpackage/MyClass.java",
5788 				"package javax.xml.mysubpackage;\n" +
5789 				"\n" +
5790 				"public class MyClass {\n" +
5791 				"}\n" +
5792 				"\n" +
5793 				"",
5794 				"src/nonmodular/UsesMySubPackage.java",
5795 				"package nonmodular;\n" +
5796 				"\n" +
5797 				"import javax.xml.mysubpackage.MyClass;\n" +
5798 				"\n" +
5799 				"public class UsesMySubPackage {\n" +
5800 				"	public MyClass field;\n" +
5801 				"}\n" +
5802 				"",
5803 			};
5804 			IJavaProject p1 = setupModuleProject("nonmodular1", sources);
5805 			IClasspathEntry dep = JavaCore.newProjectEntry(p1.getPath(), null, false,
5806 				new IClasspathAttribute[] {},
5807 				false/*not exported*/);
5808 			String[] src = new String[] {
5809 				"src/nonmodular2/Problem.java",
5810 				"package nonmodular2;\n" +
5811 				"\n" +
5812 				"import javax.xml.XMLConstants;\n" +
5813 				"\n" +
5814 				"import nonmodular.UsesMySubPackage;\n" +
5815 				"\n" +
5816 				"public class Problem extends nonmodular.UsesMySubPackage {\n" +
5817 				"	String s = XMLConstants.NULL_NS_URI;\n" +
5818 				"}\n" +
5819 				"",
5820 			};
5821 			IJavaProject p2 = setupModuleProject("nonmodular2", src, new IClasspathEntry[] { dep });
5822 			p2.getProject().getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, null);
5823 			assertNoErrors();
5824 		} finally {
5825 			deleteProject("nonmodular1");
5826 			deleteProject("nonmodular2");
5827 		}
5828 	}
testBug522330()5829 	public void testBug522330() throws CoreException, IOException {
5830 		try {
5831 			String[] sources = new String[] {
5832 				"src/javax/net/ServerSocketFactory1.java",
5833 				"package javax.net;\n" +
5834 				"\n" +
5835 				"public class ServerSocketFactory1 {\n" +
5836 				"}\n" +
5837 				"\n" +
5838 				"",
5839 			};
5840 			IJavaProject p1 = setupModuleProject("nonmodular1", sources);
5841 			p1.setOption(JavaCore.COMPILER_COMPLIANCE, "1.8"); // compile with 1.8 compliance to avoid error about package conflict
5842 
5843 			IClasspathEntry dep = JavaCore.newProjectEntry(p1.getPath(), null, false,
5844 				new IClasspathAttribute[] {},
5845 				false/*not exported*/);
5846 			String[] src = new String[] {
5847 				"src/nonmodular2/Problem.java",
5848 				"package nonmodular2;\n" +
5849 				"\n" +
5850 				"import javax.net.ServerSocketFactory;\n" +
5851 				"\n" +
5852 				"public class Problem  {\n" +
5853 				"	Object o = ServerSocketFactory.getDefault();\n" +
5854 				"} \n" +
5855 				"",
5856 			};
5857 			IJavaProject p2 = setupModuleProject("nonmodular2", src, new IClasspathEntry[] { dep });
5858 			p2.getProject().getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, null);
5859 			IMarker[] markers = p2.getProject().findMarkers(null, true, IResource.DEPTH_INFINITE);
5860 			sortMarkers(markers);
5861 			assertMarkers("unexpected markers",
5862 					"The package javax.net is accessible from more than one module: <unnamed>, java.base\n" +
5863 					"ServerSocketFactory cannot be resolved",
5864 					markers);
5865 		} finally {
5866 			deleteProject("nonmodular1");
5867 			deleteProject("nonmodular2");
5868 		}
5869 	}
5870 
testBug522503()5871 	public void testBug522503() throws Exception {
5872 		try {
5873 			IJavaProject p1 = setupModuleProject("mod.one",
5874 				new String[] {
5875 					"src/module-info.java",
5876 					"module mod.one {\n" +
5877 					"	exports p1;\n" +
5878 					"}\n",
5879 					"src/p1/API.java",
5880 					"package p1;\n" +
5881 					"public class API {}\n"
5882 				});
5883 			IClasspathAttribute[] attr = { JavaCore.newClasspathAttribute(IClasspathAttribute.MODULE, "true") };
5884 			IClasspathEntry[] deps = { JavaCore.newLibraryEntry(p1.getOutputLocation(), null, null, null, attr, false) };
5885 			String[] sources2 = new String[] {
5886 				"src/module-info.java",
5887 				"module mod.two {\n" +
5888 				"	requires mod.one;\n" +
5889 				"}\n",
5890 				"src/client/Client.java",
5891 				"package client;\n" +
5892 				"import p1.API;\n" +
5893 				"public class Client {\n" +
5894 				"	API api;\n" +
5895 				"}\n"
5896 			};
5897 			IJavaProject p2 = setupModuleProject("mod.two", sources2, deps);
5898 			p2.getProject().getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, null);
5899 			assertNoErrors();
5900 
5901 			this.problemRequestor.reset();
5902 			ICompilationUnit cu = getCompilationUnit("/mod.two/src/client/Client.java");
5903 			cu.getWorkingCopy(this.wcOwner, null);
5904 			assertProblems(
5905 				"Unexpected problems",
5906 				"----------\n" +
5907 				"----------\n",
5908 				this.problemRequestor);
5909 		} finally {
5910 			deleteProject("mod.one");
5911 			deleteProject("mod.two");
5912 		}
5913 	}
testBug522671()5914 	public void testBug522671() throws Exception {
5915 		try {
5916 		IJavaProject p1 = setupModuleProject("util",
5917 			new String[] {
5918 				"src/module-info.java",
5919 				"module util {\n" +
5920 				"	exports my.util;\n" +
5921 				"}\n" +
5922 				"",
5923 				"src/my/util/Data.java",
5924 				"package my.util;\n" +
5925 				"public class Data {\n" +
5926 				"}\n" +
5927 				"",
5928 				"src/my/util/AnnotatedInModule.java",
5929 				"package my.util;\n" +
5930 				"public abstract class AnnotatedInModule {\n" +
5931 				"	abstract public Data getTime();\n" +
5932 				"}\n" +
5933 				"",
5934 			});
5935 		IJavaProject p2 = setupModuleProject("util2",
5936 			new String[] {
5937 				"src/module-info.java",
5938 				"module util2 {\n" +
5939 				"	exports my.util.nested;\n" +
5940 				"}\n" +
5941 				"",
5942 				"src/my/util/nested/Unrelated.java",
5943 				"package my.util.nested;\n" +
5944 				"class Unrelated {\n" +
5945 				"}\n" +
5946 				"",
5947 			});
5948 		String[] sources3 = {
5949 			"src/a/other/AnnotatedInOtherNonModule.java",
5950 			"package a.other;\n" +
5951 			"import my.util.Data;\n" +
5952 			"public class AnnotatedInOtherNonModule {\n" +
5953 			"	Data generationDate;\n" +
5954 			"}\n" +
5955 			"",
5956 		};
5957 		IClasspathAttribute[] attr = { JavaCore.newClasspathAttribute(IClasspathAttribute.MODULE, "true") };
5958 		// modulepath
5959 		IClasspathEntry[] deps3 = { JavaCore.newProjectEntry(p1.getPath(), null, false, attr, false) };
5960 		IJavaProject p3 = setupModuleProject("other", sources3, deps3);
5961 
5962 		String[] sources4 = {
5963 			"src/test/Test.java",
5964 			"package test;\n" +
5965 			"\n" +
5966 			"import a.other.AnnotatedInOtherNonModule;\n" +
5967 			"import my.util.AnnotatedInModule;\n" +
5968 			"import my.util.Data;\n" +
5969 			"\n" +
5970 			"public class Test extends AnnotatedInOtherNonModule {\n" +
5971 			"	public Data f(AnnotatedInModule calendar) {\n" +
5972 			"		return calendar.getTime();\n" +
5973 			"	}\n" +
5974 			"}\n" +
5975 			"",
5976 		};
5977 		IClasspathEntry[] deps4 = { //
5978 				// modulepath (with split package my.util)
5979 				JavaCore.newProjectEntry(p1.getPath(), null, false, attr, false), //
5980 				JavaCore.newProjectEntry(p2.getPath(), null, false, attr, false), //
5981 				// classpath
5982 				JavaCore.newProjectEntry(p3.getPath()) //
5983 		};
5984 		IJavaProject p4 = setupModuleProject("test", sources4, deps4);
5985 		p4.getProject().getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, null);
5986 
5987 		assertNoErrors();
5988 
5989 		this.problemRequestor.reset();
5990 		ICompilationUnit cu = getCompilationUnit("/test/src/test/Test.java");
5991 		cu.getWorkingCopy(this.wcOwner, null);
5992 		assertProblems(
5993 			"Unexpected problems",
5994 			"----------\n" +
5995 			"----------\n",
5996 			this.problemRequestor);
5997 		} finally {
5998 			deleteProject("util");
5999 			deleteProject("util2");
6000 			deleteProject("other");
6001 			deleteProject("test");
6002 		}
6003 	}
testBug522671b()6004 	public void testBug522671b() throws CoreException {
6005 		try {
6006 			String[] sources = new String[] {
6007 				"src/nonmodular1/HasConstructorWithProperties.java",
6008 				"package nonmodular1;\n" +
6009 				"\n" +
6010 				"import java.util.Properties;\n" +
6011 				"\n" +
6012 				"public class HasConstructorWithProperties {\n" +
6013 				"\n" +
6014 				"	public HasConstructorWithProperties(Properties loadedProperties) {\n" +
6015 				"	}\n" +
6016 				"\n" +
6017 				"	protected Properties method() {\n" +
6018 				"		return null;\n" +
6019 				"	}\n" +
6020 				"\n" +
6021 				"}\n" +
6022 				"",
6023 				"src/nonmodular1/HasPropertiesField.java",
6024 				"package nonmodular1;\n" +
6025 				"\n" +
6026 				"import java.util.Properties;\n" +
6027 				"\n" +
6028 				"public class HasPropertiesField {\n" +
6029 				"	Properties properties;\n" +
6030 				"}\n" +
6031 				"",
6032 			};
6033 			IJavaProject p1 = setupModuleProject("nonmodular1", sources);
6034 
6035 			String[] sources2 = new String[] {
6036 					"src/java/util/dummy/Dummy.java",
6037 					"package java.util.dummy;\n" +
6038 					"\n" +
6039 					"public class Dummy {\n" +
6040 					"}\n" +
6041 					"\n" +
6042 					"",
6043 				};
6044 			IJavaProject p2 = setupModuleProject("nonmodular2", sources2);
6045 			p2.setOption(JavaCore.COMPILER_COMPLIANCE, "1.8"); // compile with 1.8 compliance to avoid error about package conflict
6046 
6047 			IClasspathEntry dep1 = JavaCore.newProjectEntry(p1.getPath(), null, false,
6048 					new IClasspathAttribute[] {},
6049 					false/*not exported*/);
6050 			IClasspathEntry dep2 = JavaCore.newProjectEntry(p2.getPath(), null, false,
6051 					new IClasspathAttribute[] {},
6052 					false/*not exported*/);
6053 			String[] src = new String[] {
6054 				"src/test/a/UsesHasPropertiesField.java",
6055 				"package test.a;\n" +
6056 				"\n" +
6057 				"import nonmodular1.HasPropertiesField;\n" +
6058 				"\n" +
6059 				"public class UsesHasPropertiesField extends HasPropertiesField {\n" +
6060 				"}\n" +
6061 				"",
6062 				"src/test/b/Test.java",
6063 				"package test.b;\n" +
6064 				"\n" +
6065 				"import java.util.Properties;\n" +
6066 				"\n" +
6067 				"import nonmodular1.HasConstructorWithProperties;\n" +
6068 				"\n" +
6069 				"public final class Test {\n" +
6070 				"	public static Object test(Properties cassandraConf) {\n" +
6071 				"		return new HasConstructorWithProperties(cassandraConf);\n" +
6072 				"	}\n" +
6073 				"}\n" +
6074 				"",
6075 			};
6076 			IJavaProject p3 = setupModuleProject("nonmodular3", src, new IClasspathEntry[] { dep1, dep2 });
6077 			p3.getProject().getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, null);
6078 			assertNoErrors();
6079 		} finally {
6080 			deleteProject("nonmodular1");
6081 			deleteProject("nonmodular2");
6082 			deleteProject("nonmodular3");
6083 		}
6084 	}
6085 
testBug525522()6086 	public void testBug525522() throws Exception {
6087 		try {
6088 			// non-modular substitute for java.jnlp:
6089 			IClasspathAttribute[] jreAttribs = { JavaCore.newClasspathAttribute(IClasspathAttribute.LIMIT_MODULES, "java.base,java.desktop,java.rmi,java.sql") };
6090 			IJavaProject jnlp = createJava9ProjectWithJREAttributes("jnlp", new String[] {"src"}, jreAttribs);
6091 			createFolder("jnlp/src/javax/jnlp");
6092 			createFile("jnlp/src/javax/jnlp/UnavailableServiceException.java",
6093 						"package javax.jnlp;\n" +
6094 						"@SuppressWarnings(\"serial\")\n" +
6095 						"public class UnavailableServiceException extends Exception {\n" +
6096 						"}\n");
6097 			createFile("jnlp/src/javax/jnlp/ServiceManager.java",
6098 						"package javax.jnlp;\n" +
6099 						"public class ServiceManager {\n" +
6100 						"	public static void lookup(String s) throws UnavailableServiceException {}\n" +
6101 						"}\n");
6102 
6103 			// non-modular project consuming the non-modular jnlp, instead of the module from the JRE:
6104 			IJavaProject p1 = createJava9ProjectWithJREAttributes("nonmod1", new String[] {"src"}, jreAttribs);
6105 			addClasspathEntry(p1, JavaCore.newProjectEntry(jnlp.getPath()));
6106 
6107 			createFolder("nonmod1/src/test");
6108 			createFile("nonmod1/src/test/Test.java",
6109 						"package test;\n" +
6110 						"import javax.jnlp.ServiceManager;\n" +
6111 						"import javax.jnlp.UnavailableServiceException;\n" +
6112 						"\n" +
6113 						"public class Test {\n" +
6114 						"\n" +
6115 						"    void init() {\n" +
6116 						"        try {\n" +
6117 						"            ServiceManager.lookup(\"\");\n" +
6118 						"        } catch (final UnavailableServiceException e) {\n" +
6119 						"            e.printStackTrace();\n" +
6120 						"        }\n" +
6121 						"\n" +
6122 						"    }\n" +
6123 						"}\n");
6124 			p1.getProject().getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, null);
6125 			assertNoErrors();
6126 
6127 			this.problemRequestor.reset();
6128 			ICompilationUnit cu = getCompilationUnit("/nonmod1/src/test/Test.java");
6129 			cu.getWorkingCopy(this.wcOwner, null);
6130 			assertProblems(
6131 				"Unexpected problems",
6132 				"----------\n" +
6133 				"----------\n",
6134 				this.problemRequestor);
6135 
6136 		} finally {
6137 			deleteProject("jnlp");
6138 			deleteProject("nonmod1");
6139 		}
6140 	}
6141 
testBug525603()6142 	public void testBug525603() throws Exception {
6143 		IJavaProject javaProject = null;
6144 		try {
6145 			String[] sources = {
6146 				"com/automod1/pack/DummyA.java",
6147 				"package com.automod1.pack;\n" +
6148 				"public class DummyA {}\n;"
6149 			};
6150 			String outputDirectory = Util.getOutputDirectory();
6151 
6152 			String jarPath = outputDirectory + File.separator + "automod.jar";
6153 			Util.createJar(sources, jarPath, "1.8");
6154 
6155 			javaProject = createJava9Project("mod1", new String[] {"src"});
6156 			IClasspathAttribute[] attributes = { JavaCore.newClasspathAttribute(IClasspathAttribute.MODULE, "true") };
6157 			addClasspathEntry(javaProject, JavaCore.newLibraryEntry(new Path(jarPath), null, null, null, attributes, false));
6158 
6159 			String srcMod =
6160 				"module mod1 {\n" +
6161 				"	exports com.mod1.pack1;\n" +
6162 				"	requires automod;\n" +
6163 				"}";
6164 			createFile("/mod1/src/module-info.java",
6165 				srcMod);
6166 			createFolder("/mod1/src/com/mod1/pack1");
6167 			String srcX =
6168 				"package com.mod1.pack1;\n" +
6169 				"public class Dummy {\n" +
6170 				"}";
6171 			createFile("/mod1/src/com/mod1/pack1/Dummy.java", srcX);
6172 
6173 			this.problemRequestor.initialize(srcMod.toCharArray());
6174 			getWorkingCopy("/mod1/src/module-info.java", srcMod, true);
6175 			assertProblems("module-info should have exactly one warning",
6176 					"----------\n" +
6177 					"1. WARNING in /mod1/src/module-info.java (at line 3)\n" +
6178 					"	requires automod;\n" +
6179 					"	         ^^^^^^^\n" +
6180 					"Name of automatic module \'automod\' is unstable, it is derived from the module\'s file name.\n" +
6181 					"----------\n",
6182 					this.problemRequestor);
6183 
6184 			this.problemRequestor.initialize(srcX.toCharArray());
6185 			getWorkingCopy("/mod1/src/com/mod1/pack1/Dummy.java", srcX, true);
6186 			assertProblems("X should have no problems",
6187 					"----------\n" +
6188 					"----------\n",
6189 					this.problemRequestor);
6190 
6191 			javaProject.getProject().build(IncrementalProjectBuilder.FULL_BUILD, null);
6192 			assertNoErrors();
6193 		} finally {
6194 			if (javaProject != null)
6195 				deleteProject(javaProject);
6196 		}
6197 	}
6198 
testBug522670()6199 	public void testBug522670() throws Exception {
6200 		Hashtable<String, String> javaCoreOptions = JavaCore.getOptions();
6201 		try {
6202 			Hashtable<String, String> newOptions=new Hashtable<>(javaCoreOptions);
6203 			newOptions.put(CompilerOptions.OPTION_Store_Annotations, JavaCore.ENABLED);
6204 			JavaCore.setOptions(newOptions);
6205 			IJavaProject p1 = setupModuleProject("util",
6206 				new String[] {
6207 					"src/module-info.java",
6208 					"module util {\n" +
6209 					"	exports my.util;\n" +
6210 					"}\n" +
6211 					"",
6212 					"src/my/util/Data.java",
6213 					"package my.util;\n" +
6214 					"public class Data {\n" +
6215 					"}\n" +
6216 					"",
6217 					"src/my/util/AnnotatedInModule.java",
6218 					"package my.util;\n" +
6219 					"import static java.lang.annotation.ElementType.TYPE_USE;\n" +
6220 					"import java.lang.annotation.Target;\n" +
6221 					"@Target(TYPE_USE)\n" +
6222 					"@interface Y {\n" +
6223 					"}\n" +
6224 					"public abstract class AnnotatedInModule {\n" +
6225 					"	abstract public @Y Data getTime();\n" +
6226 					"}\n" +
6227 					"",
6228 				});
6229 			IJavaProject p2 = setupModuleProject("util2",
6230 				new String[] {
6231 					"src/module-info.java",
6232 					"module util2 {\n" +
6233 					"	exports my.util.nested;\n" +
6234 					"}\n" +
6235 					"",
6236 					"src/my/util/nested/Unrelated.java",
6237 					"package my.util.nested;\n" +
6238 					"class Unrelated {\n" +
6239 					"}\n" +
6240 					"",
6241 				});
6242 			String[] sources3 = {
6243 				"src/a/other/AnnotatedInOtherNonModule.java",
6244 				"package a.other;\n" +
6245 				"import static java.lang.annotation.ElementType.TYPE_USE;\n" +
6246 				"import java.lang.annotation.Target;\n" +
6247 				"import my.util.Data;\n" +
6248 				"@Target(TYPE_USE)\n" +
6249 				"@interface X {\n" +
6250 				"}\n" +
6251 				"public class AnnotatedInOtherNonModule {\n" +
6252 				"	@X\n" +
6253 				"	Data generationDate;\n" +
6254 				"}\n" +
6255 				"",
6256 			};
6257 			IClasspathAttribute[] attr = { JavaCore.newClasspathAttribute(IClasspathAttribute.MODULE, "true") };
6258 			// modulepath
6259 			IClasspathEntry[] deps3 = { JavaCore.newProjectEntry(p1.getPath(), null, false, attr, false) };
6260 			IJavaProject p3 = setupModuleProject("other", sources3, deps3);
6261 
6262 			String[] sources4 = {
6263 				"src/test/Test.java",
6264 				"package test;\n" +
6265 				"\n" +
6266 				"import a.other.AnnotatedInOtherNonModule;\n" +
6267 				"import my.util.AnnotatedInModule;\n" +
6268 				"import my.util.Data;\n" +
6269 				"\n" +
6270 				"public class Test extends AnnotatedInOtherNonModule {\n" +
6271 				"	public Data f(AnnotatedInModule calendar) {\n" +
6272 				"		return calendar.getTime();\n" +
6273 				"	}\n" +
6274 				"}\n" +
6275 				"",
6276 			};
6277 			IClasspathEntry[] deps4 = { //
6278 					// modulepath (with split package my.util)
6279 					JavaCore.newProjectEntry(p1.getPath(), null, false, attr, false), //
6280 					JavaCore.newProjectEntry(p2.getPath(), null, false, attr, false), //
6281 					// classpath
6282 					JavaCore.newProjectEntry(p3.getPath()) //
6283 			};
6284 			IJavaProject p4 = setupModuleProject("test", sources4, deps4);
6285 			p4.getProject().getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, null);
6286 
6287 			assertNoErrors();
6288 		} finally {
6289 			JavaCore.setOptions(javaCoreOptions);
6290 			deleteProject("util");
6291 			deleteProject("util2");
6292 			deleteProject("other");
6293 			deleteProject("test");
6294 		}
6295 	}
6296 
testBug526054()6297 	public void testBug526054() throws Exception {
6298 		if (!isJRE9) return;
6299 		ClasspathJrt.resetCaches();
6300 		try {
6301 			// jdk.rmic is not be visible to code in an unnamed module, but using requires we can see the module.
6302 			// only, there's nothing exported from it (which is why JEP 261 hides it from unnamed), so we --add-reads:
6303 			IClasspathAttribute[] attrs = new IClasspathAttribute[] {
6304 				JavaCore.newClasspathAttribute(IClasspathAttribute.ADD_EXPORTS, "jdk.rmic/sun.rmi.rmic=mod1")
6305 			};
6306 			IJavaProject javaProject = createJava9ProjectWithJREAttributes("mod1", new String[] {"src"}, attrs);
6307 
6308 			String srcMod =
6309 				"module mod1 {\n" +
6310 				"	exports com.mod1.pack1;\n" +
6311 				"	requires jdk.rmic;\n" +
6312 				"}";
6313 			createFile("/mod1/src/module-info.java",
6314 				srcMod);
6315 			createFolder("/mod1/src/com/mod1/pack1");
6316 			String srcX =
6317 				"package com.mod1.pack1;\n" +
6318 				"import sun.rmi.rmic.Main;\n" +
6319 				"public class Dummy {\n" +
6320 				"	String test() {\n" +
6321 				"		return Main.getString(\"in\");\n" +
6322 				"	}\n" +
6323 				"}";
6324 			createFile("/mod1/src/com/mod1/pack1/Dummy.java", srcX);
6325 
6326 			this.problemRequestor.initialize(srcMod.toCharArray());
6327 			getWorkingCopy("/mod1/src/module-info.java", srcMod, true);
6328 			assertProblems("module-info should have no problems",
6329 					"----------\n" +
6330 					"----------\n",
6331 					this.problemRequestor);
6332 
6333 			this.problemRequestor.initialize(srcX.toCharArray());
6334 			getWorkingCopy("/mod1/src/com/mod1/pack1/Dummy.java", srcX, true);
6335 			assertProblems("Dummy should have no problems",
6336 					"----------\n" +
6337 					"----------\n",
6338 					this.problemRequestor);
6339 
6340 			javaProject.getProject().build(IncrementalProjectBuilder.FULL_BUILD, null);
6341 			assertNoErrors();
6342 		} finally {
6343 			deleteProject("mod1");
6344 		}
6345 	}
6346 
testBug526054b()6347 	public void testBug526054b() throws Exception {
6348 		ClasspathJrt.resetCaches();
6349 		try {
6350 			// one project can see jdk.rmic/sun.rmi.rmic
6351 			IClasspathAttribute[] attrs = new IClasspathAttribute[] {
6352 				JavaCore.newClasspathAttribute(IClasspathAttribute.ADD_EXPORTS, "jdk.rmic/sun.rmi.rmic=mod1")
6353 			};
6354 			createJava9ProjectWithJREAttributes("mod1", new String[] {"src"}, attrs);
6355 
6356 			String srcMod1 =
6357 				"module mod1 {\n" +
6358 				"	exports com.mod1.pack1;\n" +
6359 				"	requires jdk.rmic;\n" +
6360 				"}";
6361 			createFile("/mod1/src/module-info.java",
6362 				srcMod1);
6363 			createFolder("/mod1/src/com/mod1/pack1");
6364 			String srcX1 =
6365 				"package com.mod1.pack1;\n" +
6366 				"import sun.rmi.rmic.Constants;\n" + // this should never be complained against due to above add-exports.
6367 				"public class Dummy implements Constants {\n" +
6368 				"}";
6369 			createFile("/mod1/src/com/mod1/pack1/Dummy.java", srcX1);
6370 
6371 			// second project cannot see jdk.rmic/sun.rmi.rmic:
6372 			createJava9Project("mod2", new String[] {"src"});
6373 
6374 			String srcMod2 =
6375 				"module mod2 {\n" +
6376 				"	exports com.mod2.pack1;\n" +
6377 				"	requires jdk.rmic;\n" +
6378 				"}";
6379 			createFile("/mod2/src/module-info.java",
6380 				srcMod2);
6381 			createFolder("/mod2/src/com/mod2/pack1");
6382 			String srcX2 =
6383 				"package com.mod2.pack1;\n" +
6384 				"import sun.rmi.rmic.Main;\n" +
6385 				"public class Dummy {\n" +
6386 				"	String test() {\n" +
6387 				"		return Main.getString(\"in\");\n" +
6388 				"	}\n" +
6389 				"}";
6390 			createFile("/mod2/src/com/mod2/pack1/Dummy.java", srcX2);
6391 
6392 			// check first:
6393 			this.problemRequestor.initialize(srcX1.toCharArray());
6394 			getWorkingCopy("/mod1/src/com/mod1/pack1/Dummy.java", srcX1, true);
6395 			assertProblems("Dummy in mod1 should have no problems",
6396 					"----------\n" +
6397 					"----------\n",
6398 					this.problemRequestor);
6399 
6400 			// check second:
6401 			this.problemRequestor.initialize(srcX2.toCharArray());
6402 			getWorkingCopy("/mod2/src/com/mod2/pack1/Dummy.java", srcX2, true);
6403 			assertProblems("Dummy in mod2 should have problems",
6404 					"----------\n" +
6405 					"1. ERROR in /mod2/src/com/mod2/pack1/Dummy.java (at line 2)\n" +
6406 					"	import sun.rmi.rmic.Main;\n" +
6407 					"	       ^^^^^^^^^^^^^^^^^\n" +
6408 					"The type sun.rmi.rmic.Main is not accessible\n" +
6409 					"----------\n" +
6410 					"2. ERROR in /mod2/src/com/mod2/pack1/Dummy.java (at line 5)\n" +
6411 					"	return Main.getString(\"in\");\n" +
6412 					"	       ^^^^\n" +
6413 					"Main cannot be resolved\n" +
6414 					"----------\n",
6415 					this.problemRequestor);
6416 
6417 			// check both in a combined build
6418 			getWorkspace().build(IncrementalProjectBuilder.CLEAN_BUILD, null);
6419 			getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, null);
6420 			IMarker[] markers = getWorkspace().getRoot().findMarkers(null, true, IResource.DEPTH_INFINITE);
6421 			sortMarkers(markers);
6422 			assertMarkers("Unexpected markers",
6423 					"The type sun.rmi.rmic.Main is not accessible\n" +
6424 					"Main cannot be resolved",
6425 					markers);
6426 		} finally {
6427 			deleteProject("mod1");
6428 			deleteProject("mod2");
6429 		}
6430 	}
6431 
testBug525918()6432 	public void testBug525918() throws CoreException {
6433 		try {
6434 			String[] sources = new String[] {
6435 				"src/module-info.java",
6436 				"import p.MyAbstractDriver;\n" +
6437 				"import p.MyAbstractDriverWithProvider;\n" +
6438 				"import p.MyDriverInf;\n" +
6439 				"import p.MyInfWithProvider;\n" +
6440 				"module test {\n" +
6441 				"	requires java.sql;\n" +
6442 				"	provides java.sql.Driver with MyDriverInf, MyAbstractDriver, MyInfWithProvider, MyAbstractDriverWithProvider;" +
6443 				"}",
6444 				"src/p/MyDriverInf.java",
6445 				"package p;\n" +
6446 				"public interface MyDriverInf extends java.sql.Driver { }",
6447 				"src/p/MyAbstractDriver.java",
6448 				"package p;\n" +
6449 				"public abstract class MyAbstractDriver {\n" +
6450 				"	public MyAbstractDriver() { }\n" +
6451 				"}",
6452 				"src/p/MyInfWithProvider.java",
6453 				"package p;\n" +
6454 				"public interface MyInfWithProvider {\n" +
6455 				"	public static java.sql.Driver provider() {\n" +
6456 				"		return null;\n" +
6457 				"	}\n" +
6458 				"}\n",
6459 				"src/p/MyAbstractDriverWithProvider.java",
6460 				"package p;\n" +
6461 				"public abstract class MyAbstractDriverWithProvider {\n" +
6462 				"	public static java.sql.Driver provider() {\n" +
6463 				"		return null;\n" +
6464 				"	}\n" +
6465 				"}"
6466 			};
6467 			IJavaProject p1 = setupModuleProject("test", sources);
6468 			p1.getProject().getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, null);
6469 			IMarker[] markers = p1.getProject().findMarkers(null, true, IResource.DEPTH_INFINITE);
6470 			super.sortMarkers(markers);
6471 			assertMarkers("Unexpected markers",
6472 				"Invalid service implementation, the type p.MyAbstractDriver is abstract\n" +
6473 				"Invalid service implementation, the type p.MyDriverInf is abstract\n" +
6474 				"Type mismatch: cannot convert from MyAbstractDriver to Driver"
6475 				, markers);
6476 		} finally {
6477 			deleteProject("test");
6478 		}
6479 	}
6480 
testBug527576()6481 	public void testBug527576() throws Exception {
6482 		IJavaProject javaProject = null;
6483 		try {
6484 
6485 			javaProject = createJava9Project("mod1", new String[] {"src"});
6486 			String[] sources = {
6487 					"org/junit/Assert.java",
6488 					"package org.junit;\n" +
6489 					"public class Assert {}\n;"
6490 				};
6491 
6492 			Path jarPath = new Path('/' + javaProject.getProject().getName() + '/' + "localjunit.jar");
6493 			Util.createJar(sources, javaProject.getProject().getWorkspace().getRoot().getFile(jarPath).getRawLocation().toOSString(), "1.8");
6494 			javaProject.getProject().refreshLocal(IResource.DEPTH_INFINITE, null);
6495 
6496 			addClasspathEntry(javaProject, JavaCore.newLibraryEntry(jarPath, null, null, null, null, false));
6497 
6498 			String srcMod =
6499 				"module mod1 {\n" +
6500 				"}";
6501 			createFile("/mod1/src/module-info.java",
6502 				srcMod);
6503 			createFolder("/mod1/src/com/mod1/pack1");
6504 			String srcX =
6505 				"package com.mod1.pack1;\n" +
6506 				"import org.junit.Assert;\n" +
6507 				"public class Dummy extends Assert {\n" +
6508 				"}";
6509 			createFile("/mod1/src/com/mod1/pack1/Dummy.java", srcX);
6510 
6511 			this.problemRequestor.initialize(srcMod.toCharArray());
6512 			getWorkingCopy("/mod1/src/module-info.java", srcMod, true);
6513 			assertProblems("module-info should have no problems",
6514 					"----------\n" +
6515 					"----------\n",
6516 					this.problemRequestor);
6517 
6518 			this.problemRequestor.initialize(srcX.toCharArray());
6519 			getWorkingCopy("/mod1/src/com/mod1/pack1/Dummy.java", srcX, true);
6520 			assertProblems("X should have errors because Assert should not be visible",
6521 					"----------\n" +
6522 					"1. ERROR in /mod1/src/com/mod1/pack1/Dummy.java (at line 2)\n" +
6523 					"	import org.junit.Assert;\n" +
6524 					"	       ^^^^^^^^^^^^^^^^\n" +
6525 					"The type org.junit.Assert is not accessible\n" +
6526 					"----------\n" +
6527 					"2. ERROR in /mod1/src/com/mod1/pack1/Dummy.java (at line 3)\n" +
6528 					"	public class Dummy extends Assert {\n" +
6529 					"	                           ^^^^^^\n" +
6530 					"Assert cannot be resolved to a type\n" +
6531 					"----------\n",
6532 					this.problemRequestor);
6533 
6534 			javaProject.getProject().build(IncrementalProjectBuilder.FULL_BUILD, null);
6535 			IMarker[] markers = javaProject.getProject().findMarkers(null, true, IResource.DEPTH_INFINITE);
6536 			sortMarkers(markers);
6537 			assertMarkers("Unexpected markers",
6538 					"The type org.junit.Assert is not accessible\n" +
6539 					"Assert cannot be resolved to a type",
6540 					markers);
6541 		} finally {
6542 			if (javaProject != null)
6543 				deleteProject(javaProject);
6544 		}
6545 	}
testBug528467a()6546 	public void testBug528467a() throws CoreException {
6547 		IJavaProject p1 = createJava9Project("mod.one");
6548 		try {
6549 			IClasspathEntry[] rawClasspath = p1.getRawClasspath();
6550 			String jrtPath = null;
6551 			for (int i = 0; i < rawClasspath.length; i++) {
6552 				IClasspathEntry iClasspathEntry = rawClasspath[i];
6553 				if (iClasspathEntry.getEntryKind() == IClasspathEntry.CPE_LIBRARY &&
6554 						iClasspathEntry.getPath().toString().endsWith("jrt-fs.jar")) {
6555 					jrtPath = iClasspathEntry.getPath().toOSString();
6556 					IAccessRule[] pathRules = new IAccessRule[1];
6557 					pathRules[0] = JavaCore.newAccessRule(new Path("java/awt/**"), IAccessRule.K_NON_ACCESSIBLE);
6558 					IClasspathEntry newEntry = JavaCore.newLibraryEntry(iClasspathEntry.getPath(),
6559 							iClasspathEntry.getSourceAttachmentPath(),
6560 							iClasspathEntry.getSourceAttachmentRootPath(),
6561 								pathRules,
6562 								iClasspathEntry.getExtraAttributes(),
6563 								iClasspathEntry.isExported());
6564 					rawClasspath[i] = newEntry;
6565 					break;
6566 				}
6567 			}
6568 			p1.setRawClasspath(rawClasspath, null);
6569 			createFolder("/mod.one/src/p1");
6570 			createFile("/mod.one/src/module-info.java",
6571 					"module mod.one {\n" +
6572 					"	exports p1;\n" +
6573 					"	requires java.desktop;\n" +
6574 					"}\n");
6575 			createFile("/mod.one/src/p1/X.java",
6576 					"package p1;\n" +
6577 							"public class X {\n"
6578 							+ "    java.awt.Image im = null;\n"
6579 							+ "}\n");
6580 
6581 			waitForManualRefresh();
6582 			waitForAutoBuild();
6583 			p1.getProject().build(IncrementalProjectBuilder.FULL_BUILD, null);
6584 			IMarker[] markers = p1.getProject().findMarkers(null, true, IResource.DEPTH_INFINITE);
6585 
6586 			assertMarkers("Unexpected markers", "Access restriction: The type 'Image' is not API (restriction on required library '"+
6587 																							jrtPath + "')", markers);
6588 		} finally {
6589 			deleteProject(p1);
6590 		}
6591 	}
testBug528467b()6592 	public void testBug528467b() throws CoreException {
6593 		IJavaProject p1 = createJava9Project("mod.one");
6594 		try {
6595 			IClasspathEntry[] rawClasspath = p1.getRawClasspath();
6596 			String jrtPath = null;
6597 			for (int i = 0; i < rawClasspath.length; i++) {
6598 				IClasspathEntry iClasspathEntry = rawClasspath[i];
6599 				if (iClasspathEntry.getEntryKind() == IClasspathEntry.CPE_LIBRARY &&
6600 						iClasspathEntry.getPath().toString().endsWith("jrt-fs.jar")) {
6601 					jrtPath = iClasspathEntry.getPath().toOSString();
6602 					IAccessRule[] pathRules = new IAccessRule[1];
6603 					pathRules[0] = JavaCore.newAccessRule(new Path("java/awt/Image"), IAccessRule.K_NON_ACCESSIBLE);
6604 					IClasspathEntry newEntry = JavaCore.newLibraryEntry(iClasspathEntry.getPath(),
6605 							iClasspathEntry.getSourceAttachmentPath(),
6606 							iClasspathEntry.getSourceAttachmentRootPath(),
6607 								pathRules,
6608 								iClasspathEntry.getExtraAttributes(),
6609 								iClasspathEntry.isExported());
6610 					rawClasspath[i] = newEntry;
6611 					break;
6612 				}
6613 			}
6614 			p1.setRawClasspath(rawClasspath, null);
6615 			createFolder("/mod.one/src/p1");
6616 			createFile("/mod.one/src/module-info.java",
6617 					"module mod.one {\n" +
6618 					"	exports p1;\n" +
6619 					"	requires java.desktop;\n" +
6620 					"}\n");
6621 			createFile("/mod.one/src/p1/X.java",
6622 					"package p1;\n" +
6623 					"import java.awt.*;\n" +
6624 					"public abstract class X extends Image {\n" +
6625 					"	public Graphics foo() {\n" +
6626 					"		return getGraphics();\n" +
6627 					"	}\n"
6628 					+ "}\n");
6629 
6630 			waitForManualRefresh();
6631 			waitForAutoBuild();
6632 			p1.getProject().build(IncrementalProjectBuilder.FULL_BUILD, null);
6633 			IMarker[] markers = p1.getProject().findMarkers(null, true, IResource.DEPTH_INFINITE);
6634 			sortMarkers(markers);
6635 
6636 			assertMarkers("Unexpected markers",
6637 					"Access restriction: The type \'Image\' is not API (restriction on required library '"+ jrtPath + "')\n" +
6638 					"The type Graphics from module java.desktop may not be accessible to clients due to missing \'requires transitive\'\n" +
6639 					"Access restriction: The method \'Image.getGraphics()\' is not API (restriction on required library '"+ jrtPath + "')", markers);
6640 		} finally {
6641 			deleteProject(p1);
6642 		}
6643 	}
testBug528467c()6644 	public void testBug528467c() throws CoreException {
6645 		IJavaProject p1 = createJava9Project("unnamed");
6646 		try {
6647 			IClasspathEntry[] rawClasspath = p1.getRawClasspath();
6648 			String jrtPath = null;
6649 			for (int i = 0; i < rawClasspath.length; i++) {
6650 				IClasspathEntry iClasspathEntry = rawClasspath[i];
6651 				if (iClasspathEntry.getEntryKind() == IClasspathEntry.CPE_LIBRARY &&
6652 						iClasspathEntry.getPath().toString().endsWith("jrt-fs.jar")) {
6653 					jrtPath = iClasspathEntry.getPath().toOSString();
6654 					IAccessRule[] pathRules = new IAccessRule[1];
6655 					pathRules[0] = JavaCore.newAccessRule(new Path("java/awt/**"), IAccessRule.K_NON_ACCESSIBLE);
6656 					IClasspathEntry newEntry = JavaCore.newLibraryEntry(iClasspathEntry.getPath(),
6657 							iClasspathEntry.getSourceAttachmentPath(),
6658 							iClasspathEntry.getSourceAttachmentRootPath(),
6659 								pathRules,
6660 								iClasspathEntry.getExtraAttributes(),
6661 								iClasspathEntry.isExported());
6662 					rawClasspath[i] = newEntry;
6663 					break;
6664 				}
6665 			}
6666 			p1.setRawClasspath(rawClasspath, null);
6667 			createFolder("/unnamed/src/p1");
6668 			createFile("/unnamed/src/p1/X.java",
6669 					"package p1;\n" +
6670 							"public class X {\n"
6671 							+ "    java.awt.Image im = null;\n"
6672 							+ "}\n");
6673 
6674 			waitForManualRefresh();
6675 			waitForAutoBuild();
6676 			p1.getProject().build(IncrementalProjectBuilder.FULL_BUILD, null);
6677 			IMarker[] markers = p1.getProject().findMarkers(null, true, IResource.DEPTH_INFINITE);
6678 
6679 			assertMarkers("Unexpected markers", "Access restriction: The type 'Image' is not API (restriction on required library '"+
6680 																							jrtPath + "')", markers);
6681 		} finally {
6682 			deleteProject(p1);
6683 		}
6684 	}
6685 	// Bug 520713: allow test code to access code on the classpath
testWithTestAttributeAndTestDependencyOnClassPath()6686 	public void testWithTestAttributeAndTestDependencyOnClassPath() throws CoreException, IOException {
6687 		String outputDirectory = Util.getOutputDirectory();
6688 
6689 		String jarPath = outputDirectory + File.separator + "mytestlib.jar";
6690 		IJavaProject project1 = null;
6691 		IJavaProject project2 = null;
6692 		try {
6693 			String[] sources = {
6694 				"my/test/Test.java",
6695 				"package my.test;\n" +
6696 				"public class Test {}\n;"
6697 			};
6698 			Util.createJar(sources, jarPath, "1.8");
6699 
6700 			project1 = createJava9Project("Project1", new String[] {"src"});
6701 			addClasspathEntry(project1, JavaCore.newSourceEntry(new Path("/Project1/src-tests"), null, null, new Path("/Project1/bin-tests"), new IClasspathAttribute[] { JavaCore.newClasspathAttribute(IClasspathAttribute.TEST, "true") }));
6702 			addClasspathEntry(project1, JavaCore.newLibraryEntry(new Path(jarPath), null, null, null, new IClasspathAttribute[] { JavaCore.newClasspathAttribute(IClasspathAttribute.TEST, "true") }, false));
6703 
6704 			createFolder("/Project1/src/p1");
6705 			createFolder("/Project1/src-tests/p1");
6706 			createFile("/Project1/src/module-info.java",
6707 					"module m1 {\n" +
6708 					"	exports p1;\n" +
6709 					"}");
6710 			createFile("/Project1/src/p1/P1Class.java",
6711 					"package p1;\n" +
6712 					"\n" +
6713 					"public class P1Class {\n"+
6714 					"}\n"
6715 					);
6716 			createFile("/Project1/src/p1/Production1.java",
6717 					"package p1;\n" +
6718 					"\n" +
6719 					"public class Production1 {\n" +
6720 					"	void p1() {\n" +
6721 					"		new P1Class(); // ok\n" +
6722 					"		new T1Class(); // forbidden\n" +
6723 					"	}\n" +
6724 					"}\n" +
6725 					""
6726 					);
6727 			createFile("/Project1/src-tests/p1/T1Class.java",
6728 					"package p1;\n" +
6729 					"\n" +
6730 					"public class T1Class {\n"+
6731 					"}\n"
6732 					);
6733 			createFile("/Project1/src-tests/p1/Test1.java",
6734 					"package p1;\n" +
6735 					"\n" +
6736 					"public class Test1 extends my.test.Test {\n" +
6737 					"	void test1() {\n" +
6738 					"		new P1Class(); // ok\n" +
6739 					"		new T1Class(); // ok\n" +
6740 					"	}\n" +
6741 					"}\n" +
6742 					""
6743 					);
6744 			project1.getProject().getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, null);
6745 
6746 			IMarker[] markers = project1.getProject().findMarkers(null, true, IResource.DEPTH_INFINITE);
6747 			sortMarkers(markers);
6748 			assertMarkers("Unexpected markers",
6749 					"T1Class cannot be resolved to a type" +
6750 					"",
6751 					markers);
6752 
6753 			project2 = createJava9Project("Project2", new String[] {"src"});
6754 			addClasspathEntry(project2, JavaCore.newProjectEntry(new Path("/Project1"), null, false, new IClasspathAttribute[] { JavaCore.newClasspathAttribute(IClasspathAttribute.MODULE, "true") }, false));
6755 			addClasspathEntry(project2, JavaCore.newSourceEntry(new Path("/Project2/src-tests"), null, null, new Path("/Project2/bin-tests"), new IClasspathAttribute[] { JavaCore.newClasspathAttribute(IClasspathAttribute.TEST, "true") }));
6756 			addClasspathEntry(project2, JavaCore.newLibraryEntry(new Path(jarPath), null, null, null, new IClasspathAttribute[] { JavaCore.newClasspathAttribute(IClasspathAttribute.TEST, "true") }, false));
6757 			createFolder("/Project2/src/p2");
6758 			createFolder("/Project2/src-tests/p2");
6759 			createFile("/Project2/src/module-info.java",
6760 					"module m2 {\n" +
6761 					"	requires m1;\n" +
6762 					"}");
6763 			createFile("/Project2/src/p2/P2Class.java",
6764 					"package p2;\n" +
6765 					"\n" +
6766 					"public class P2Class {\n"+
6767 					"}\n"
6768 					);
6769 			createFile("/Project2/src/p2/Production2.java",
6770 					"package p2;\n" +
6771 					"\n" +
6772 					"import p1.P1Class;\n" +
6773 					"import p1.T1Class;\n" +
6774 					"\n" +
6775 					"public class Production2 {\n" +
6776 					"	void p2() {\n" +
6777 					"		new P1Class(); // ok\n" +
6778 					"		new P2Class(); // ok\n" +
6779 					"		new T1Class(); // forbidden\n" +
6780 					"		new T2Class(); // forbidden\n" +
6781 					"	}\n" +
6782 					"}\n" +
6783 					""
6784 					);
6785 			createFile("/Project2/src-tests/p2/T2Class.java",
6786 					"package p2;\n" +
6787 					"\n" +
6788 					"public class T2Class {\n"+
6789 					"}\n"
6790 					);
6791 			createFile("/Project2/src-tests/p2/Test2.java",
6792 					"package p2;\n" +
6793 					"\n" +
6794 					"import p1.P1Class;\n" +
6795 					"import p1.T1Class;\n" +
6796 					"\n" +
6797 					"public class Test2 extends p1.Test1 {\n" +
6798 					"	void test2() {\n" +
6799 					"		new P1Class(); // ok\n" +
6800 					"		new P2Class(); // ok\n" +
6801 					"		new T1Class(); // ok\n" +
6802 					"		new T2Class(); // ok\n" +
6803 					"	}\n" +
6804 					"}\n" +
6805 					""
6806 					);
6807 			project1.getProject().getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, null);
6808 
6809 			IMarker[] markers2 = project2.getProject().findMarkers(null, true, IResource.DEPTH_INFINITE);
6810 			sortMarkers(markers2);
6811 			assertMarkers("Unexpected markers",
6812 					"The import p1.T1Class cannot be resolved\n" +
6813 					"T1Class cannot be resolved to a type\n" +
6814 					"T2Class cannot be resolved to a type",
6815 					markers2);
6816 		} finally {
6817 			if (project1 != null)
6818 				deleteProject(project1);
6819 			if (project2 != null)
6820 				deleteProject(project2);
6821 			new File(jarPath).delete();
6822 		}
6823 	}
6824 
testBug531579()6825 	public void testBug531579() throws Exception {
6826 		String outputDirectory = Util.getOutputDirectory();
6827 
6828 		String jarPath = outputDirectory + File.separator + "jaxb-api.jar";
6829 		IJavaProject project1 = null;
6830 		try {
6831 			// these types replace inaccessible types from JRE/javax.xml.bind:
6832 			// (not a problem during IDE builds)
6833 			String[] sources = {
6834 				"javax/xml/bind/JAXBContext.java",
6835 				"package javax.xml.bind;\n" +
6836 				"public abstract class JAXBContext {\n" +
6837 				"	public static JAXBContext newInstance( String contextPath )\n" +
6838 				"		throws JAXBException {\n" +
6839 				"		return null;\n" +
6840 				"	}\n" +
6841 				"}\n",
6842 				"javax/xml/bind/JAXBException.java",
6843 				"package javax.xml.bind;\n" +
6844 				"public class JAXBException extends Exception {}\n"
6845 			};
6846 			Util.createJar(sources, jarPath, "1.8");
6847 
6848 			project1 = createJava9Project("Project1", new String[] {"src"});
6849 			addClasspathEntry(project1, JavaCore.newLibraryEntry(new Path(jarPath), null, null));
6850 
6851 			createFolder("/Project1/src/p1");
6852 			createFile("/Project1/src/p1/ImportJAXBType.java",
6853 					"package p1;\n" +
6854 					"\n" +
6855 					"import javax.xml.bind.JAXBContext;\n" +
6856 					"\n" +
6857 					"public class ImportJAXBType {\n" +
6858 					"\n" +
6859 					"	public static void main(String[] args) throws Exception {\n" +
6860 					"		JAXBContext context = JAXBContext.newInstance(\"\");\n" +
6861 					"	}\n" +
6862 					"\n" +
6863 					"}\n"
6864 					);
6865 
6866 			project1.getProject().getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, null);
6867 
6868 			IMarker[] markers = project1.getProject().findMarkers(null, true, IResource.DEPTH_INFINITE);
6869 			sortMarkers(markers);
6870 			assertMarkers("Unexpected markers",
6871 					"The value of the local variable context is not used",
6872 					markers);
6873 		} finally {
6874 			if (project1 != null)
6875 				deleteProject(project1);
6876 			new File(jarPath).delete();
6877 		}
6878 	}
testBug527569a()6879 	public void testBug527569a() throws CoreException {
6880 		IJavaProject p1 = createJava9Project("Bug527569", "9");
6881 		try {
6882 			createFolder("/Bug527569/src/p1");
6883 			createFile("/Bug527569/src/p1/X.java",
6884 					"package p1;\n" +
6885 					"public class X {\n" +
6886 					"	public java.util.stream.Stream<String> emptyStream() {\n" +
6887 					"		return null;\n" +
6888 					"	}\n" +
6889 					"}");
6890 
6891 			waitForManualRefresh();
6892 			waitForAutoBuild();
6893 			p1.getProject().build(IncrementalProjectBuilder.FULL_BUILD, null);
6894 			IMarker[] markers = p1.getProject().findMarkers(null, true, IResource.DEPTH_INFINITE);
6895 			assertMarkers("Unexpected markers", "", markers);
6896 		} finally {
6897 			deleteProject(p1);
6898 		}
6899 	}
testBug527569b()6900 	public void testBug527569b() throws CoreException {
6901 		IJavaProject p1 = createJava9Project("Bug527569", "1.7");
6902 		try {
6903 			createFolder("/Bug527569/src/p1");
6904 			createFile("/Bug527569/src/p1/X.java",
6905 					"package p1;\n" +
6906 					"public class X {\n" +
6907 					"	public java.util.stream.Stream<String> emptyStream() {\n" +
6908 					"		return null;\n" +
6909 					"	}\n" +
6910 					"}");
6911 
6912 			waitForManualRefresh();
6913 			waitForAutoBuild();
6914 			p1.getProject().build(IncrementalProjectBuilder.FULL_BUILD, null);
6915 			IMarker[] markers = p1.getProject().findMarkers(null, true, IResource.DEPTH_INFINITE);
6916 			assertMarkers("Unexpected markers", "", markers);
6917 		} finally {
6918 			deleteProject(p1);
6919 		}
6920 	}
testBug527569c()6921 	public void testBug527569c() throws CoreException {
6922 		if (!isJRE9) return;
6923 		IJavaProject p1 = createJava9Project("Bug527569", "1.7");
6924 		Map<String, String> options = new HashMap<>();
6925 		// Make sure the new options map doesn't reset.
6926 		options.put(CompilerOptions.OPTION_Compliance, "1.7");
6927 		options.put(CompilerOptions.OPTION_Source, "1.7");
6928 		options.put(CompilerOptions.OPTION_TargetPlatform, "1.7");
6929 		options.put(CompilerOptions.OPTION_Release, "enabled");
6930 		p1.setOptions(options);
6931 		try {
6932 			createFolder("/Bug527569/src/p1");
6933 			createFile("/Bug527569/src/p1/X.java",
6934 					"package p1;\n" +
6935 					"public class X {\n" +
6936 					"	public java.util.stream.Stream<String> emptyStream() {\n" +
6937 					"		return null;\n" +
6938 					"	}\n" +
6939 					"}");
6940 
6941 			waitForManualRefresh();
6942 			waitForAutoBuild();
6943 			p1.getProject().build(IncrementalProjectBuilder.FULL_BUILD, null);
6944 			IMarker[] markers = p1.getProject().findMarkers(null, true, IResource.DEPTH_INFINITE);
6945 			assertMarkers("Unexpected markers", "java.util.stream.Stream cannot be resolved to a type", markers);
6946 		} finally {
6947 			deleteProject(p1);
6948 		}
6949 	}
testBug527569d()6950 	public void testBug527569d() throws CoreException {
6951 		IJavaProject p1 = createJava9Project("Bug527569", "9");
6952 		try {
6953 			createFolder("/Bug527569/src/p1");
6954 			createFile("/Bug527569/src/p1/X.java",
6955 					"package p1;\n" +
6956 					"public class X {\n" +
6957 					"	public java.lang.Compiler getCompiler() {\n" +
6958 					"		return null;\n" +
6959 					"	}\n" +
6960 					"}");
6961 
6962 			waitForManualRefresh();
6963 			waitForAutoBuild();
6964 			p1.getProject().build(IncrementalProjectBuilder.FULL_BUILD, null);
6965 			IMarker[] markers = p1.getProject().findMarkers(null, true, IResource.DEPTH_INFINITE);
6966 			assertMarkers("Unexpected markers", "The type Compiler has been deprecated since version 9 and marked for removal", markers);
6967 		} finally {
6968 			deleteProject(p1);
6969 		}
6970 	}
testBug527569e()6971 	public void testBug527569e() throws CoreException {
6972 		if (!isJRE9 || isJRE12) return;
6973 		IJavaProject p1 = createJava9Project("Bug527569", "1.8");
6974 		Map<String, String> options = new HashMap<>();
6975 		// Make sure the new options map doesn't reset.
6976 		options.put(CompilerOptions.OPTION_Compliance, "1.7");
6977 		options.put(CompilerOptions.OPTION_Source, "1.7");
6978 		options.put(CompilerOptions.OPTION_TargetPlatform, "1.7");
6979 		options.put(CompilerOptions.OPTION_Release, "enabled");
6980 		p1.setOptions(options);
6981 		try {
6982 			createFolder("/Bug527569/src/p1");
6983 			createFile("/Bug527569/src/p1/X.java",
6984 					"package p1;\n" +
6985 					"public class X {\n" +
6986 					"	public java.lang.Compiler getCompiler() {\n" +
6987 					"		return null;\n" +
6988 					"	}\n" +
6989 					"}");
6990 
6991 			waitForManualRefresh();
6992 			waitForAutoBuild();
6993 			p1.getProject().build(IncrementalProjectBuilder.FULL_BUILD, null);
6994 			IMarker[] markers = p1.getProject().findMarkers(null, true, IResource.DEPTH_INFINITE);
6995 			assertMarkers("Unexpected markers", "", markers);
6996 		} finally {
6997 			deleteProject(p1);
6998 		}
6999 	}
testBug522601()7000 	public void testBug522601() throws CoreException {
7001 		IJavaProject p1 = createJava9Project("Bug522601", "9");
7002 		try {
7003 			IFile file = createFile("/Bug522601/test.txt", "not a jar");
7004 			IClasspathAttribute modAttr = JavaCore.newClasspathAttribute(IClasspathAttribute.MODULE, "true");
7005 			addLibraryEntry(p1, file.getFullPath(), null, null, null, null, new IClasspathAttribute[] { modAttr }, false);
7006 			p1.getProject().build(IncrementalProjectBuilder.FULL_BUILD, null);
7007 			IMarker[] markers = p1.getProject().findMarkers(null, true, IResource.DEPTH_INFINITE);
7008 			sortMarkers(markers);
7009 			assertMarkers("Unexpected markers",
7010 					"Archive for required library: \'test.txt\' in project \'Bug522601\' cannot be read or is not a valid ZIP file\n" +
7011 					"The project cannot be built until build path errors are resolved", markers);
7012 		} finally {
7013 			deleteProject(p1);
7014 		}
7015 	}
7016 	// automatic modules export all their packages
testBug532724()7017 	public void testBug532724() throws CoreException, IOException {
7018 		try {
7019 			String libPath = "externalLib/test.jar";
7020 			Util.createJar(
7021 					new String[] {
7022 						"test/src/org/astro/World.java", //$NON-NLS-1$
7023 						"package org.astro;\n" +
7024 						"public interface World {\n" +
7025 						"	public String name();\n" +
7026 						"}",
7027 					},
7028 					null,
7029 					new HashMap<>(),
7030 					null,
7031 					getExternalResourcePath(libPath));
7032 			String[] src = new String[] {
7033 					"src/module-info.java",
7034 					"module com.greetings {\n" +
7035 					"	requires transitive test;\n" +
7036 					"	exports com.greetings;\n" +
7037 					"}",
7038 					"src/com/greetings/MyWorld.java",
7039 					"package com.greetings;\n" +
7040 					"import org.astro.World;\n"	+
7041 					"public class MyWorld {\n" +
7042 					"	public World name() {\n" +
7043 					"		return null;\n" +
7044 					"	}\n" +
7045 					"}"
7046 			};
7047 			IClasspathAttribute modAttr = new ClasspathAttribute("module", "true");
7048 			IClasspathEntry dep = JavaCore.newLibraryEntry(new Path(getExternalResourcePath(libPath)), null, null, ClasspathEntry.NO_ACCESS_RULES,
7049 					new IClasspathAttribute[] {modAttr},
7050 					false/*not exported*/);
7051 			IJavaProject p2 = setupModuleProject("com.greetings", src, new IClasspathEntry[] { dep });
7052 			p2.setOption(JavaCore.COMPILER_PB_UNSTABLE_AUTO_MODULE_NAME, JavaCore.IGNORE);
7053 			p2.setOption(JavaCore.COMPILER_PB_API_LEAKS, JavaCore.ERROR);
7054 
7055 			getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, null);
7056 			IMarker[] markers = p2.getProject().findMarkers(null, true, IResource.DEPTH_INFINITE);
7057 			assertMarkers("Unexpected markers", "", markers);
7058 		} finally {
7059 			deleteExternalResource("externalLib");
7060 			this.deleteProject("com.greetings");
7061 		}
7062 	}
testBug534624a()7063 	public void testBug534624a() throws CoreException, IOException {
7064 		IJavaProject project = null;
7065 		Hashtable<String, String> options = JavaCore.getOptions();
7066 		try {
7067 			project = setUpJavaProject("bug.test.b534624");
7068 			IClasspathEntry[] rawClasspath = project.getRawClasspath();
7069 			IClasspathEntry jrtEntry = getJRTLibraryEntry();
7070 			for(int i = 0; i < rawClasspath.length; i++) {
7071 				if (rawClasspath[i].getEntryKind() == IClasspathEntry.CPE_CONTAINER)
7072 					rawClasspath[i] = jrtEntry;
7073 			}
7074 			project.setRawClasspath(rawClasspath, null);
7075 			project.setOption(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_10);
7076 			project.setOption(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_10);
7077 			project.setOption(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_10);
7078 			getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, null);
7079 			IMarker[] markers = project.getProject().findMarkers(null, true, IResource.DEPTH_INFINITE);
7080 			assertMarkers("Unexpected markers", "Version9 cannot be resolved to a module", markers);
7081 		} finally {
7082 			if (project != null)
7083 				deleteProject(project);
7084 			JavaCore.setOptions(options);
7085 		}
7086 	}
testBug534624b()7087 	public void testBug534624b() throws CoreException, IOException {
7088 		IJavaProject project = null;
7089 		Hashtable<String, String> options = JavaCore.getOptions();
7090 		try {
7091 			project = setUpJavaProject("bug.test.b534624");
7092 			IClasspathEntry[] rawClasspath = project.getRawClasspath();
7093 			IClasspathEntry jrtEntry = getJRTLibraryEntry();
7094 			for(int i = 0; i < rawClasspath.length; i++) {
7095 				if (rawClasspath[i].getEntryKind() == IClasspathEntry.CPE_CONTAINER)
7096 					rawClasspath[i] = jrtEntry;
7097 			}
7098 			project.setRawClasspath(rawClasspath, null);
7099 			project.setOption(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_9);
7100 			project.setOption(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_9);
7101 			project.setOption(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_9);
7102 			getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, null);
7103 			IMarker[] markers = project.getProject().findMarkers(null, true, IResource.DEPTH_INFINITE);
7104 			assertMarkers("Unexpected markers", "Version10 cannot be resolved to a module", markers);
7105 
7106 			project.setOption(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_10);
7107 			project.setOption(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_10);
7108 			project.setOption(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_10);
7109 			getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, null);
7110 			markers = project.getProject().findMarkers(null, true, IResource.DEPTH_INFINITE);
7111 			assertMarkers("Unexpected markers", "Version9 cannot be resolved to a module", markers);
7112 		} finally {
7113 			if (project != null)
7114 				deleteProject(project);
7115 			JavaCore.setOptions(options);
7116 		}
7117 	}
7118 	// missing linked jar must not cause NPE
testBug540904()7119 	public void testBug540904() throws CoreException, IOException {
7120 		try {
7121 			String[] src = new String[] {
7122 					"src/test/Test.java",
7123 					"package test;\n" +
7124 					"public class Test {\n" +
7125 					"}"
7126 			};
7127 			IJavaProject p2 = setupModuleProject("Bug540904", src, new IClasspathEntry[] {  });
7128 			IFile file = getFile("/Bug540904/link.jar");
7129 			file.createLink(new Path("MISSING/missing.jar"), IResource.ALLOW_MISSING_LOCAL, null);
7130 			addLibraryEntry(p2, file.getFullPath(), false);
7131 			getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, null);
7132 			IMarker[] markers = p2.getProject().findMarkers(null, true, IResource.DEPTH_INFINITE);
7133 			assertMarkers("Unexpected markers", "", markers);
7134 		} finally {
7135 			this.deleteProject("Bug540904");
7136 		}
7137 	}
testBug540788()7138 	public void testBug540788() throws Exception {
7139 		try {
7140 			// project common:
7141 			IJavaProject common = createJava9Project("Bug540788.common", new String[] { "src/main/java" });
7142 			createSourceFiles(common,
7143 					new String[] {
7144 						"src/main/java/module-info.java",
7145 						"module org.sheepy.common {\n" +
7146 						"	requires transitive org.eclipse.emf.common;\n" +
7147 						"	requires transitive org.eclipse.emf.ecore;\n" +
7148 						"}\n"
7149 					});
7150 			IFolder libs = createFolder("/Bug540788.common/libs");
7151 			String emfCommonLocation = libs.getLocation()+"/org.eclipse.emf.common.jar";
7152 			Path emfCommonPath = new Path(emfCommonLocation);
7153 			Util.createJar(
7154 					new String[] {
7155 							"src/org/eclipse/emf/common/Foo.java",
7156 							"package org.eclipse.emf.common;\n" +
7157 							"public interface Foo {\n" +
7158 							"}",
7159 					},
7160 					null,
7161 					new HashMap<>(),
7162 					null,
7163 					emfCommonLocation);
7164 			addModularLibraryEntry(common, emfCommonPath, null);
7165 
7166 			String ecoreLocation = libs.getLocation()+"/org.eclipse.emf.ecore.jar";
7167 			Path ecorePath = new Path(ecoreLocation);
7168 			Util.createJar(
7169 					new String[] {
7170 						"src/org/eclipse/emf/ecore/EObject.java",
7171 						"package org.eclipse.emf.ecore;\n" +
7172 						"public interface EObject {\n" +
7173 						"}",
7174 					},
7175 					null,
7176 					new HashMap<>(),
7177 					null,
7178 					ecoreLocation);
7179 			addModularLibraryEntry(common, ecorePath, null);
7180 			// project vulkan:
7181 			IJavaProject vulkan = createJava9Project("Bug540788.vulkan", new String[] { "src/main/java" });
7182 			createSourceFiles(vulkan,
7183 					new String[] {
7184 						"src/main/java/module-info.java",
7185 						"module org.sheepy.vulkan {\n" +
7186 						"	requires transitive org.sheepy.common;\n" +
7187 						"	exports org.sheepy.vulkan.model.resource;\n" +
7188 						"}\n",
7189 						"src/main/java/org/sheepy/vulkan/model/resource/Resource.java",
7190 						"package org.sheepy.vulkan.model.resource;\n" +
7191 						"import org.eclipse.emf.ecore.EObject;\n" +
7192 						"public interface Resource extends EObject {\n" +
7193 						"}\n",
7194 						"src/main/java/org/sheepy/vulkan/model/resource/VulkanBuffer.java",
7195 						"package org.sheepy.vulkan.model.resource;\n" +
7196 						"public interface VulkanBuffer extends Resource {\n" +
7197 						"}\n",
7198 					});
7199 			addModularProjectEntry(vulkan, common);
7200 			addModularLibraryEntry(vulkan, emfCommonPath, null);
7201 			addModularLibraryEntry(vulkan, ecorePath, null);
7202 			// project vulkan.demo
7203 			IJavaProject vulkan_demo = createJava9Project("Bug540788.vulkan.demo", new String[] { "src/main/java" });
7204 			createSourceFiles(vulkan_demo,
7205 					new String[] {
7206 						"src/main/java/module-info.java",
7207 						"module org.sheepy.vulkan.demo {\n" +
7208 						"	exports org.sheepy.vulkan.demo.model;\n" +
7209 						"	requires org.sheepy.vulkan;\n" +
7210 						"}\n",
7211 						"src/main/java/org/sheepy/vulkan/demo/model/UniformBuffer.java",
7212 						"package org.sheepy.vulkan.demo.model;\n" +
7213 						"import org.sheepy.vulkan.model.resource.VulkanBuffer;\n" +
7214 						"public interface UniformBuffer extends VulkanBuffer {\n" +
7215 						"}\n",
7216 					});
7217 			addModularProjectEntry(vulkan_demo, vulkan);
7218 			addModularProjectEntry(vulkan_demo, common);
7219 			addModularLibraryEntry(vulkan_demo, emfCommonPath, null);
7220 			addModularLibraryEntry(vulkan_demo, ecorePath, null);
7221 
7222 			getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, null);
7223 			IMarker[] markers = vulkan_demo.getProject().findMarkers(null, true, IResource.DEPTH_INFINITE);
7224 			assertMarkers("Unexpected markers", "", markers);
7225 		} finally {
7226 			deleteProject("Bug540788.common");
7227 			deleteProject("Bug540788.vulkan");
7228 			deleteProject("Bug540788.vulkan.demo");
7229 		}
7230 	}
testBug541015()7231 	public void testBug541015() throws Exception {
7232 		try {
7233 			IJavaProject m1 = createJava9Project("m1", new String[] { "src" });
7234 			createSourceFiles(m1,
7235 					new String[] {
7236 						"src/module-info.java",
7237 						"module m1 { exports org.p1; }\n",
7238 						"src/org/p1/T1.java",
7239 						"package org.p1;\n" +
7240 						"public class T1 {}\n"
7241 					});
7242 			IJavaProject m2 = createJava9Project("m2", new String[] { "src" });
7243 			createSourceFiles(m2,
7244 					new String[] {
7245 						"src/module-info.java",
7246 						"module m2 { exports org.p1; }\n",
7247 						"src/org/p1/T1.java",
7248 						"package org.p1;\n" +
7249 						"public class T1 {}\n"
7250 					});
7251 			IJavaProject m3 = createJava9Project("m3", new String[] { "src" });
7252 			createSourceFiles(m3,
7253 					new String[] {
7254 						"src/module-info.java",
7255 						"module m3 { exports org.p1; }\n",
7256 						"src/org/p1/T1.java",
7257 						"package org.p1;\n" +
7258 						"public class T1 {}\n"
7259 					});
7260 			IJavaProject unnamed = createJava9Project("unnamed", new String[] { "src" });
7261 			String testSource = "package test;\n" +
7262 			"import org.p1.T1;\n" +
7263 			"public class Test {\n" +
7264 			"	T1 t1;\n" +
7265 			"}\n";
7266 			createSourceFiles(unnamed,
7267 					new String[] {
7268 						"src/test/Test.java",
7269 						testSource
7270 					});
7271 			addModularProjectEntry(unnamed, m1);
7272 			addModularProjectEntry(unnamed, m2);
7273 			addModularProjectEntry(unnamed, m3);
7274 
7275 			getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, null);
7276 			IMarker[] markers = unnamed.getProject().findMarkers(null, true, IResource.DEPTH_INFINITE);
7277 			sortMarkers(markers);
7278 			assertMarkers("Unexpected markers",
7279 					"The package org.p1 is accessible from more than one module: m1, m2, m3\n" +
7280 					"T1 cannot be resolved to a type",
7281 					markers);
7282 
7283 			char[] sourceChars = testSource.toCharArray();
7284 			this.problemRequestor.initialize(sourceChars);
7285 			getCompilationUnit("/unnamed/src/test/Test.java").getWorkingCopy(this.wcOwner, null);
7286 			assertProblems(
7287 					"Unexpected problems",
7288 					"----------\n" +
7289 					"1. ERROR in /unnamed/src/test/Test.java (at line 2)\n" +
7290 					"	import org.p1.T1;\n" +
7291 					"	       ^^^^^^\n" +
7292 					"The package org.p1 is accessible from more than one module: m1, m2, m3\n" +
7293 					"----------\n" +
7294 					"2. ERROR in /unnamed/src/test/Test.java (at line 4)\n" +
7295 					"	T1 t1;\n" +
7296 					"	^^\n" +
7297 					"T1 cannot be resolved to a type\n" +
7298 					"----------\n",
7299 					this.problemRequestor);
7300 		} finally {
7301 			deleteProject("m1");
7302 			deleteProject("m2");
7303 			deleteProject("m3");
7304 			deleteProject("unnamed");
7305 		}
7306 	}
testBug536928_comment22()7307 	public void testBug536928_comment22() throws CoreException, IOException {
7308 		try {
7309 			IJavaProject project = createJava9Project("ztest", new String[] { "src" });
7310 			createFolder("/ztest/lib");
7311 			Util.createJar(new String[] {
7312 					"javax/xml/transform/Transformer.java",
7313 					"package javax.xml.transform;\n" +
7314 					"public class Transformer {}\n",
7315 					"javax/xml/transform/Result.java",
7316 					"package javax.xml.transform;\n" +
7317 					"public class Result {}\n"
7318 				},
7319 				project.getProject().getLocation().toString() + "/lib/xml-apis.jar",
7320 				"1.8");
7321 			project.getProject().refreshLocal(IResource.DEPTH_INFINITE, null);
7322 			IClasspathEntry libraryEntry = JavaCore.newLibraryEntry(new Path("/ztest/lib/xml-apis.jar"), null, null);
7323 			addClasspathEntry(project, libraryEntry, 1); // right after src and before jrt-fs.jar
7324 
7325 			String testSource =
7326 					"package com.ztest;\n" +
7327 					"import javax.xml.transform.Transformer;\n" +
7328 					"\n" +
7329 					"public class TestApp {\n" +
7330 					"	Transformer ts;\n" +
7331 					"	javax.xml.transform.Result result;\n" +
7332 					"}\n";
7333 			createFolder("/ztest/src/com/ztest");
7334 			createFile("/ztest/src/com/ztest/TestApp.java", testSource);
7335 			String test2Source =
7336 					"package com.ztest;\n" +
7337 					"import javax.xml.transform.*;\n" +
7338 					"public class Test2 {\n" +
7339 					"	Transformer ts;\n" +
7340 					"}\n";
7341 			createFile("/ztest/src/com/ztest/Test2.java", test2Source);
7342 			getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, null);
7343 			IMarker[] markers = project.getProject().findMarkers(null, true, IResource.DEPTH_INFINITE);
7344 			sortMarkers(markers);
7345 			assertMarkers("Unexpected Markers",
7346 					"The package javax.xml.transform is accessible from more than one module: <unnamed>, java.xml\n" +
7347 					"The package javax.xml.transform is accessible from more than one module: <unnamed>, java.xml\n" +
7348 					"Transformer cannot be resolved to a type\n" +
7349 					"Transformer cannot be resolved to a type\n" +
7350 					"The package javax.xml.transform is accessible from more than one module: <unnamed>, java.xml",
7351 					markers);
7352 
7353 			char[] sourceChars = testSource.toCharArray();
7354 			this.problemRequestor.initialize(sourceChars);
7355 			getCompilationUnit("/ztest/src/com/ztest/TestApp.java").getWorkingCopy(this.wcOwner, null);
7356 			assertProblems(
7357 					"Unexpected problems",
7358 					"----------\n" +
7359 					"1. ERROR in /ztest/src/com/ztest/TestApp.java (at line 2)\n" +
7360 					"	import javax.xml.transform.Transformer;\n" +
7361 					"	       ^^^^^^^^^^^^^^^^^^^\n" +
7362 					"The package javax.xml.transform is accessible from more than one module: <unnamed>, java.xml\n" +
7363 					"----------\n" +
7364 					"2. ERROR in /ztest/src/com/ztest/TestApp.java (at line 5)\n" +
7365 					"	Transformer ts;\n" +
7366 					"	^^^^^^^^^^^\n" +
7367 					"Transformer cannot be resolved to a type\n" +
7368 					"----------\n" +
7369 					"3. ERROR in /ztest/src/com/ztest/TestApp.java (at line 6)\n" +
7370 					"	javax.xml.transform.Result result;\n" +
7371 					"	^^^^^^^^^^^^^^^^^^^\n" +
7372 					"The package javax.xml.transform is accessible from more than one module: <unnamed>, java.xml\n" +
7373 					"----------\n",
7374 					this.problemRequestor);
7375 
7376 			sourceChars = test2Source.toCharArray();
7377 			this.problemRequestor.initialize(sourceChars);
7378 			getCompilationUnit("/ztest/src/com/ztest/Test2.java").getWorkingCopy(this.wcOwner, null);
7379 			assertProblems(
7380 					"Unexpected problems",
7381 					"----------\n" +
7382 					"1. ERROR in /ztest/src/com/ztest/Test2.java (at line 2)\n" +
7383 					"	import javax.xml.transform.*;\n" +
7384 					"	       ^^^^^^^^^^^^^^^^^^^\n" +
7385 					"The package javax.xml.transform is accessible from more than one module: <unnamed>, java.xml\n" +
7386 					"----------\n" +
7387 					"2. ERROR in /ztest/src/com/ztest/Test2.java (at line 4)\n" +
7388 					"	Transformer ts;\n" +
7389 					"	^^^^^^^^^^^\n" +
7390 					"Transformer cannot be resolved to a type\n" +
7391 					"----------\n",
7392 					this.problemRequestor);
7393 		} finally {
7394 			deleteProject("ztest");
7395 		}
7396 	}
testBug536928_comment22b()7397 	public void testBug536928_comment22b() throws CoreException, IOException {
7398 		try {
7399 			IJavaProject project = createJava9Project("ztest", new String[] { "src" });
7400 			createFolder("/ztest/lib");
7401 			Util.createJar(new String[] {
7402 					"javax/xml/transform/Transformer.java",
7403 					"package javax.xml.transform;\n" +
7404 					"public class Transformer {}\n",
7405 					"javax/xml/transform/Result.java",
7406 					"package javax.xml.transform;\n" +
7407 					"public class Result {}\n"
7408 				},
7409 				project.getProject().getLocation().toString() + "/lib/xml-apis.jar",
7410 				"1.8");
7411 			project.getProject().refreshLocal(IResource.DEPTH_INFINITE, null);
7412 			IClasspathEntry libraryEntry = JavaCore.newLibraryEntry(new Path("/ztest/lib/xml-apis.jar"), null, null);
7413 			addClasspathEntry(project, libraryEntry, 2); // DIFFERENCE HERE: place xml-apis.jar AFTER jrt-fs.jar
7414 
7415 			String testSource =
7416 					"package com.ztest;\n" +
7417 					"import javax.xml.transform.Transformer;\n" +
7418 					"\n" +
7419 					"public class TestApp {\n" +
7420 					"	Transformer ts;\n" +
7421 					"	javax.xml.transform.Result result;\n" +
7422 					"}\n";
7423 			createFolder("/ztest/src/com/ztest");
7424 			createFile("/ztest/src/com/ztest/TestApp.java", testSource);
7425 			String test2Source =
7426 					"package com.ztest;\n" +
7427 					"import javax.xml.transform.*;\n" +
7428 					"public class Test2 {\n" +
7429 					"	Transformer ts;\n" +
7430 					"}\n";
7431 			createFile("/ztest/src/com/ztest/Test2.java", test2Source);
7432 			getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, null);
7433 			IMarker[] markers = project.getProject().findMarkers(null, true, IResource.DEPTH_INFINITE);
7434 			sortMarkers(markers);
7435 			assertMarkers("Unexpected Markers",
7436 					"The package javax.xml.transform is accessible from more than one module: <unnamed>, java.xml\n" +
7437 					"The package javax.xml.transform is accessible from more than one module: <unnamed>, java.xml\n" +
7438 					"Transformer cannot be resolved to a type\n" +
7439 					"Transformer cannot be resolved to a type\n" +
7440 					"The package javax.xml.transform is accessible from more than one module: <unnamed>, java.xml",
7441 					markers);
7442 
7443 			char[] sourceChars = testSource.toCharArray();
7444 			this.problemRequestor.initialize(sourceChars);
7445 			getCompilationUnit("/ztest/src/com/ztest/TestApp.java").getWorkingCopy(this.wcOwner, null);
7446 			assertProblems(
7447 					"Unexpected problems",
7448 					"----------\n" +
7449 					"1. ERROR in /ztest/src/com/ztest/TestApp.java (at line 2)\n" +
7450 					"	import javax.xml.transform.Transformer;\n" +
7451 					"	       ^^^^^^^^^^^^^^^^^^^\n" +
7452 					"The package javax.xml.transform is accessible from more than one module: <unnamed>, java.xml\n" +
7453 					"----------\n" +
7454 					"2. ERROR in /ztest/src/com/ztest/TestApp.java (at line 5)\n" +
7455 					"	Transformer ts;\n" +
7456 					"	^^^^^^^^^^^\n" +
7457 					"Transformer cannot be resolved to a type\n" +
7458 					"----------\n" +
7459 					"3. ERROR in /ztest/src/com/ztest/TestApp.java (at line 6)\n" +
7460 					"	javax.xml.transform.Result result;\n" +
7461 					"	^^^^^^^^^^^^^^^^^^^\n" +
7462 					"The package javax.xml.transform is accessible from more than one module: <unnamed>, java.xml\n" +
7463 					"----------\n",
7464 					this.problemRequestor);
7465 
7466 			sourceChars = test2Source.toCharArray();
7467 			this.problemRequestor.initialize(sourceChars);
7468 			getCompilationUnit("/ztest/src/com/ztest/Test2.java").getWorkingCopy(this.wcOwner, null);
7469 			assertProblems(
7470 					"Unexpected problems",
7471 					"----------\n" +
7472 					"1. ERROR in /ztest/src/com/ztest/Test2.java (at line 2)\n" +
7473 					"	import javax.xml.transform.*;\n" +
7474 					"	       ^^^^^^^^^^^^^^^^^^^\n" +
7475 					"The package javax.xml.transform is accessible from more than one module: <unnamed>, java.xml\n" +
7476 					"----------\n" +
7477 					"2. ERROR in /ztest/src/com/ztest/Test2.java (at line 4)\n" +
7478 					"	Transformer ts;\n" +
7479 					"	^^^^^^^^^^^\n" +
7480 					"Transformer cannot be resolved to a type\n" +
7481 					"----------\n",
7482 					this.problemRequestor);
7483 		} finally {
7484 			deleteProject("ztest");
7485 		}
7486 	}
testBug536928_comment22_limited()7487 	public void testBug536928_comment22_limited() throws CoreException, IOException {
7488 		try {
7489 			IClasspathAttribute[] limitModules = {
7490 				JavaCore.newClasspathAttribute(IClasspathAttribute.LIMIT_MODULES, "java.base")
7491 			};
7492 			IJavaProject project = createJava9ProjectWithJREAttributes("ztest", new String[] { "src" }, limitModules);
7493 			createFolder("/ztest/lib");
7494 			Util.createJar(new String[] {
7495 					"javax/xml/transform/Transformer.java",
7496 					"package javax.xml.transform;\n" +
7497 					"public class Transformer {}\n",
7498 					"javax/xml/transform/Result.java",
7499 					"package javax.xml.transform;\n" +
7500 					"public class Result {}\n"
7501 				},
7502 				project.getProject().getLocation().toString() + "/lib/xml-apis.jar",
7503 				"1.8");
7504 			project.getProject().refreshLocal(IResource.DEPTH_INFINITE, null);
7505 			IClasspathEntry libraryEntry = JavaCore.newLibraryEntry(new Path("/ztest/lib/xml-apis.jar"), null, null);
7506 			addClasspathEntry(project, libraryEntry, 1); // right after src and before jrt-fs.jar
7507 
7508 			String testSource =
7509 					"package com.ztest;\n" +
7510 					"import javax.xml.transform.Transformer;\n" +
7511 					"\n" +
7512 					"public class TestApp {\n" +
7513 					"	Transformer ts;\n" +
7514 					"	javax.xml.transform.Result result;\n" +
7515 					"}\n";
7516 			createFolder("/ztest/src/com/ztest");
7517 			createFile("/ztest/src/com/ztest/TestApp.java", testSource);
7518 			String test2Source =
7519 					"package com.ztest;\n" +
7520 					"import javax.xml.transform.*;\n" +
7521 					"public class Test2 {\n" +
7522 					"	Transformer ts;\n" +
7523 					"}\n";
7524 			createFile("/ztest/src/com/ztest/Test2.java", test2Source);
7525 			getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, null);
7526 			assertNoErrors();
7527 
7528 			char[] sourceChars = testSource.toCharArray();
7529 			this.problemRequestor.initialize(sourceChars);
7530 			getCompilationUnit("/ztest/src/com/ztest/TestApp.java").getWorkingCopy(this.wcOwner, null);
7531 			assertProblems(
7532 					"Unexpected problems",
7533 					"----------\n" +
7534 					"----------\n",
7535 					this.problemRequestor);
7536 			sourceChars = test2Source.toCharArray();
7537 			this.problemRequestor.initialize(sourceChars);
7538 			getCompilationUnit("/ztest/src/com/ztest/Test2.java").getWorkingCopy(this.wcOwner, null);
7539 			assertProblems(
7540 					"Unexpected problems",
7541 					"----------\n" +
7542 					"----------\n",
7543 					this.problemRequestor);
7544 		} finally {
7545 			deleteProject("ztest");
7546 		}
7547 	}
testBug542896()7548 	public void testBug542896() throws CoreException {
7549 		IJavaProject java10Project = createJava10Project("bug", new String[] { "src" });
7550 		try {
7551 			createFolder("/bug/src/test/platform");
7552 			createFile("/bug/src/test/platform/Context.java",
7553 					"package test.platform;\n" +
7554 					"\n" +
7555 					"import java.net.URI;\n" +
7556 					"\n" +
7557 					"public interface Context {\n" +
7558 					"	public URI getURI();\n" +
7559 					"}\n");
7560 			createFile("/bug/src/test/platform/AbstractContext.java",
7561 					"package test.platform;\n" +
7562 					"\n" +
7563 					"import java.net.URI;\n" +
7564 					"import java.util.*;\n" +
7565 					"import test.*;\n" +
7566 					"\n" +
7567 					"public abstract class AbstractContext implements Context {\n" +
7568 					"	Iterable<URI> uris = new ArrayList<URI>();\n" +
7569 					"	Application application;\n" +
7570 					"}\n");
7571 			String testSource =
7572 					"package test;\n" +
7573 					"\n" +
7574 					"import java.io.*;\n" +
7575 					"import java.net.*;\n" +
7576 					"import java.util.*;\n" +
7577 					"\n" +
7578 					"import test.platform.*;\n" +
7579 					"\n" +
7580 					"public interface Application // extends Foo\n" +
7581 					"{\n" +
7582 					"}\n";
7583 			String testPath = "/bug/src/test/Application.java";
7584 			createFile(testPath, testSource);
7585 			// first compile: no error:
7586 			getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, null);
7587 			assertNoErrors();
7588 			char[] sourceChars = testSource.toCharArray();
7589 			this.problemRequestor.initialize(sourceChars);
7590 			getCompilationUnit(testPath).getWorkingCopy(this.wcOwner, null);
7591 			assertProblems(
7592 					"Unexpected problems",
7593 					"----------\n" +
7594 					"1. WARNING in /bug/src/test/Application.java (at line 3)\n" +
7595 					"	import java.io.*;\n" +
7596 					"	       ^^^^^^^\n" +
7597 					"The import java.io is never used\n" +
7598 					"----------\n" +
7599 					"2. WARNING in /bug/src/test/Application.java (at line 4)\n" +
7600 					"	import java.net.*;\n" +
7601 					"	       ^^^^^^^^\n" +
7602 					"The import java.net is never used\n" +
7603 					"----------\n" +
7604 					"3. WARNING in /bug/src/test/Application.java (at line 5)\n" +
7605 					"	import java.util.*;\n" +
7606 					"	       ^^^^^^^^^\n" +
7607 					"The import java.util is never used\n" +
7608 					"----------\n" +
7609 					"4. WARNING in /bug/src/test/Application.java (at line 7)\n" +
7610 					"	import test.platform.*;\n" +
7611 					"	       ^^^^^^^^^^^^^\n" +
7612 					"The import test.platform is never used\n" +
7613 					"----------\n",
7614 					this.problemRequestor);
7615 			// introduce error:
7616 			String testSourceEdited =
7617 					"package test;\n" +
7618 					"\n" +
7619 					"import java.io.*;\n" +
7620 					"import java.net.*;\n" +
7621 					"import java.util.*;\n" +
7622 					"\n" +
7623 					"import test.platform.*;\n" +
7624 					"\n" +
7625 					"public interface Application extends Foo\n" +
7626 					"{\n" +
7627 					"}\n";
7628 			editFile(testPath, testSourceEdited);
7629 			java10Project.getProject().build(IncrementalProjectBuilder.INCREMENTAL_BUILD, null);
7630 			IMarker[] markers = java10Project.getProject().findMarkers(null, true, IResource.DEPTH_INFINITE);
7631 			assertMarkers("Unexpected markers", "Foo cannot be resolved to a type", markers);
7632 		} finally {
7633 			if (java10Project != null)
7634 				deleteProject(java10Project);
7635 		}
7636 	}
testBug543392a()7637 	public void testBug543392a() throws Exception {
7638 		bug543392(null);
7639 	}
testBug543392b()7640 	public void testBug543392b() throws Exception {
7641 		// put other on the *modulepath*:
7642 		IClasspathAttribute[] attrs = { JavaCore.newClasspathAttribute(IClasspathAttribute.MODULE, "true") };
7643 		bug543392(attrs);
7644 	}
bug543392(IClasspathAttribute[] dependencyAttrs)7645 	void bug543392(IClasspathAttribute[] dependencyAttrs) throws Exception {
7646 		IJavaProject other = createJava9Project("other");
7647 		IJavaProject current = createJava9Project("current");
7648 		try {
7649 			createFile("other/src/module-info.java",
7650 					"module other {\n" +
7651 					"	exports other.p;\n" +
7652 					"}\n");
7653 			createFolder("other/src/other/p");
7654 			createFile("other/src/other/p/C.java",
7655 					"package other.p;\n" +
7656 					"public class C {}\n");
7657 
7658 			addClasspathEntry(current,
7659 					JavaCore.newProjectEntry(other.getProject().getFullPath(), null, false, dependencyAttrs, false)); // dependency, but ..
7660 			createFile("current/src/module-info.java", "module current {}\n"); // ... no 'requires'!
7661 			createFolder("current/src/current");
7662 
7663 			String test1path = "current/src/current/Test1.java";
7664 			String test1source =
7665 					"package current;\n" +
7666 					"import other.p.C;\n" +
7667 					"public class Test1 {\n" +
7668 					"}\n";
7669 			createFile(test1path, test1source);
7670 			String test2path = "current/src/current/Test2.java";
7671 			String test2source =
7672 					"package current;\n" +
7673 					"public class Test2 {\n" +
7674 					"	other.p.C c;\n" +
7675 					"}\n";
7676 			createFile(test2path, test2source);
7677 
7678 			getWorkspace().build(IncrementalProjectBuilder.INCREMENTAL_BUILD, null);
7679 			IMarker[] markers = current.getProject().findMarkers(null, true, IResource.DEPTH_INFINITE);
7680 			sortMarkers(markers);
7681 			assertMarkers("Unexpected markers",
7682 					"The type other.p.C is not accessible\n" +
7683 					"The type other.p.C is not accessible",
7684 					markers);
7685 
7686 			char[] sourceChars = test1source.toCharArray();
7687 			this.problemRequestor.initialize(sourceChars);
7688 			getCompilationUnit(test1path).getWorkingCopy(this.wcOwner, null);
7689 			assertProblems("unexpected problems",
7690 					"----------\n" +
7691 					"1. ERROR in /current/src/current/Test1.java (at line 2)\n" +
7692 					"	import other.p.C;\n" +
7693 					"	       ^^^^^^^^^\n" +
7694 					"The type other.p.C is not accessible\n" +
7695 					"----------\n",
7696 					this.problemRequestor);
7697 			sourceChars = test2source.toCharArray();
7698 			this.problemRequestor.initialize(sourceChars);
7699 			getCompilationUnit(test2path).getWorkingCopy(this.wcOwner, null);
7700 			assertProblems("unexpected problems",
7701 					"----------\n" +
7702 					"1. ERROR in /current/src/current/Test2.java (at line 3)\n" +
7703 					"	other.p.C c;\n" +
7704 					"	^^^^^^^^^\n" +
7705 					"The type other.p.C is not accessible\n" +
7706 					"----------\n",
7707 					this.problemRequestor);
7708 		} finally {
7709 			deleteProject(other);
7710 			deleteProject(current);
7711 		}
7712 	}
testBug541328()7713 	public void testBug541328() throws Exception {
7714 		IJavaProject pa = createJava9Project("m.a");
7715 		IJavaProject pb = createJava9Project("m.b");
7716 		IJavaProject test = createJava9Project("test");
7717 		try {
7718 			createFolder("m.a/src/a/foo");
7719 			createFile("m.a/src/a/foo/Bar.java", "package a.foo;\n public class Bar {}\n");
7720 			createFile("m.a/src/module-info.java",
7721 					"module m.a {\n" +
7722 					"	exports a.foo to m.b;\n" +
7723 					"}\n");
7724 			createFile("m.b/src/module-info.java",
7725 					"module m.b {\n" +
7726 					"	requires m.a;\n" +
7727 					"	exports b;\n" +
7728 					"}\n");
7729 			createFolder("m.b/src/b");
7730 			createFile("m.b/src/b/Boo.java",
7731 					"package b;\n" +
7732 					"import a.foo.Bar;\n" +
7733 					"public class Boo extends Bar {}\n");
7734 			addModularProjectEntry(pb, pa);
7735 
7736 			IClasspathAttribute[] forceExport = {
7737 						JavaCore.newClasspathAttribute(IClasspathAttribute.MODULE, "true"),
7738 						JavaCore.newClasspathAttribute(IClasspathAttribute.ADD_EXPORTS, "m.a/a.foo=ALL-UNNAMED")
7739 					};
7740 			addClasspathEntry(test, JavaCore.newProjectEntry(pa.getPath(), null, false, forceExport, false));
7741 			addModularProjectEntry(test, pb);
7742 
7743 			String testSource =
7744 					"import a.foo.Bar;\n" +
7745 					"import b.Boo;\n" +
7746 					"public class Test {\n" +
7747 					"	Bar b = new Boo();\n" +
7748 					"}\n";
7749 			String testPath = "test/src/Test.java";
7750 			createFile(testPath, testSource);
7751 			getWorkspace().build(IncrementalProjectBuilder.INCREMENTAL_BUILD, null);
7752 			assertNoErrors();
7753 
7754 			this.problemRequestor.initialize(testSource.toCharArray());
7755 			getCompilationUnit(testPath).getWorkingCopy(this.wcOwner, null);
7756 			assertProblems("unexpected problems",
7757 					"----------\n" +
7758 					"----------\n",
7759 					this.problemRequestor);
7760 		} finally {
7761 			deleteProject(pa);
7762 			deleteProject(pb);
7763 			deleteProject(test);
7764 		}
7765 	}
testBug543195()7766 	public void testBug543195() throws CoreException {
7767 		IJavaProject pj1 = createJava9Project("pj1");
7768 		IJavaProject pj2 = createJava9Project("pj2");
7769 		IJavaProject ptest = createJava9Project("ptest");
7770 		try {
7771 			addModularProjectEntry(pj2, pj1);
7772 			addModularProjectEntry(ptest, pj2);
7773 
7774 			createFolder("pj1/src/p");
7775 			createFile("pj1/src/p/Missing.java",
7776 					"package p;\n" +
7777 					"public class Missing {\n" +
7778 					"	public void miss() {}\n" +
7779 					"}\n");
7780 			createFile("pj1/src/module-info.java",
7781 					"module pj1 {\n" +
7782 					"	exports p;\n" +
7783 					"}\n");
7784 
7785 			createFolder("pj2/src/q");
7786 			createFile("pj2/src/q/API.java",
7787 					"package q;\n" +
7788 					"public class API extends p.Missing {}\n");
7789 			createFile("pj2/src/q/API2.java",
7790 					"package q;\n" +
7791 					"public class API2 extends API {}\n");
7792 			createFile("pj2/src/module-info.java",
7793 					"module pj2 {\n" +
7794 					"	requires pj1;\n" +
7795 					"	exports q;\n" +
7796 					"}\n");
7797 			getWorkspace().build(IncrementalProjectBuilder.INCREMENTAL_BUILD, null);
7798 
7799 			deleteFile("pj1/bin/p/Missing.class");
7800 			pj1.getProject().close(null);
7801 
7802 			createFolder("ptest/src/p/r");
7803 			createFile("ptest/src/p/r/P.java", "package p.r;\n public class P {}\n");
7804 			createFolder("ptest/src/t");
7805 			createFile("ptest/src/t/Test1.java",
7806 					"package t;\n" +
7807 					"import q.API2;\n" +
7808 					"public class Test1 {\n" +
7809 					"	void m(API2 a) {\n" +
7810 					"		a.miss();\n" +
7811 					"	}\n" +
7812 					"}\n");
7813 			String test2Path = "ptest/src/t/Test2.java";
7814 			String test2Content =
7815 					"package t;\n" +
7816 					"import p.Missing;\n" +
7817 					"public class Test2 {}\n";
7818 			createFile(test2Path, test2Content);
7819 			ptest.getProject().build(IncrementalProjectBuilder.INCREMENTAL_BUILD, null);
7820 			IMarker[] markers = ptest.getProject().findMarkers(null, true, IResource.DEPTH_INFINITE);
7821 			sortMarkers(markers);
7822 			assertMarkers("unexpected markers",
7823 					"The import p.Missing cannot be resolved\n" +
7824 					"The method miss() is undefined for the type API2",
7825 					markers);
7826 
7827 			this.problemRequestor.initialize(test2Content.toCharArray());
7828 			getCompilationUnit(test2Path).getWorkingCopy(this.wcOwner, null);
7829 			assertProblems("unexpected problems",
7830 					"----------\n" +
7831 					"1. ERROR in /ptest/src/t/Test2.java (at line 2)\n" +
7832 					"	import p.Missing;\n" +
7833 					"	       ^^^^^^^^^\n" +
7834 					"The import p.Missing cannot be resolved\n" +
7835 					"----------\n",
7836 					this.problemRequestor);
7837 		} finally {
7838 			deleteProject(pj1);
7839 			deleteProject(pj2);
7840 			deleteProject(ptest);
7841 		}
7842 	}
7843 
testBug543701()7844 	public void testBug543701() throws Exception {
7845 		IJavaProject p = createJava9Project("p");
7846 		String outputDirectory = Util.getOutputDirectory();
7847 		try {
7848 			String jar1Path = outputDirectory + File.separator + "lib1.jar";
7849 			Util.createJar(new String[] {
7850 						"javax/xml/transform/Result.java",
7851 						"package javax.xml.transform;\n" +
7852 						"public class Result {}\n"
7853 					}, new HashMap<>(), jar1Path);
7854 
7855 			String jar2Path = outputDirectory + File.separator + "lib2.jar";
7856 			Util.createJar(new String[] {
7857 						"p2/C2.java",
7858 						"package p2;\n" +
7859 						"import javax.xml.transform.Result;\n" +
7860 						"public class C2 {\n" +
7861 						"	public void m(Number n) {}\n" +
7862 						"	public void m(Result r) {}\n" + // Result will be ambiguous looking from project 'p', but should not break compilation
7863 						"}\n"
7864 					}, new HashMap<>(), jar2Path);
7865 
7866 			addLibraryEntry(p, jar1Path, false);
7867 			addLibraryEntry(p, jar2Path, false);
7868 
7869 			createFolder("p/src/pp");
7870 			String testPath = "p/src/pp/Test.java";
7871 			String testSource =
7872 					"package pp;\n" +
7873 					"import p2.C2;\n" +
7874 					"public class Test {\n" +
7875 					"	void test(C2 c2) {\n" +
7876 					"		c2.m(Integer.valueOf(1));\n" +
7877 					"	}\n" +
7878 					"}\n";
7879 			createFile(testPath, testSource);
7880 
7881 			p.getProject().build(IncrementalProjectBuilder.INCREMENTAL_BUILD, null);
7882 			assertNoErrors();
7883 
7884 			this.problemRequestor.initialize(testSource.toCharArray());
7885 			getCompilationUnit(testPath).getWorkingCopy(this.wcOwner, null);
7886 			assertProblems("unexpected problems",
7887 					"----------\n" +
7888 					"----------\n",
7889 					this.problemRequestor);
7890 		} finally {
7891 			deleteProject(p);
7892 			// clean up output dir
7893 			File outputDir = new File(outputDirectory);
7894 			if (outputDir.exists())
7895 				Util.flushDirectoryContent(outputDir);
7896 		}
7897 	}
7898 
testBug543441()7899 	public void testBug543441() throws Exception {
7900 		// unsuccessful attempt at triggering NPE on null required module
7901 		IJavaProject p = createJava9Project("p");
7902 		String outputDirectory = Util.getOutputDirectory();
7903 		try {
7904 			String jar1Path = outputDirectory + File.separator + "lib1.jar";
7905 			Util.createJar(new String[] {
7906 						"module-info.java",
7907 						"module lib1 {}\n"
7908 					}, jar1Path, "9");
7909 
7910 			String jar2Path = outputDirectory + File.separator + "lib2.jar";
7911 			Util.createJar(new String[] {
7912 						"module-info.java",
7913 						"module lib2 {\n" +
7914 						"	requires lib1;\n" + // will be messing when seen from project 'p'
7915 						"	exports p2;\n" +
7916 						"}\n",
7917 						"p2/C2.java",
7918 						"package p2;\n" +
7919 						"public class C2 {}\n"
7920 					},
7921 					null, jar2Path, new String[] { jar1Path }, "9");
7922 
7923 			File jar1File = new File(jar1Path);
7924 			jar1File.delete();
7925 
7926 			addModularLibraryEntry(p, new Path(jar2Path), null);
7927 			createFile("p/src/module-info.java",
7928 					"module p {\n" +
7929 					"	requires transitive lib2;\n" + // not lib1
7930 					"}\n");
7931 			createFolder("p/src/pkg");
7932 			createFile("p/src/pkg/Test.java",
7933 					"package pkg;\n" +
7934 					"import p2.C2;\n" +
7935 					"public class Test {\n" +
7936 					"	void test(C2 c) {}\n" +
7937 					"}\n");
7938 
7939 			p.getProject().build(IncrementalProjectBuilder.INCREMENTAL_BUILD, null);
7940 			assertNoErrors();
7941 
7942 		} finally {
7943 			deleteProject(p);
7944 			File outputDir = new File(outputDirectory);
7945 			if (outputDir.exists())
7946 				Util.flushDirectoryContent(outputDir);
7947 		}
7948 	}
7949 
testBug543765()7950 	public void testBug543765() throws CoreException, IOException {
7951 		// failure never seen in this test
7952 		IJavaProject m = createJava9Project("M");
7953 		IJavaProject n = createJava9Project("N");
7954 		IJavaProject x = createJava9Project("X");
7955 		IJavaProject y = createJava9Project("Y");
7956 		String outputDirectory = Util.getOutputDirectory();
7957 		try {
7958 			// ------ W ------
7959 			String wJarLocation = outputDirectory + File.separator + "w-0.0.1-SNAPSHOT.jar";
7960 			IPath wJarPath = new Path(wJarLocation);
7961 			Util.createJar(new String[] {
7962 						"external/W.java",
7963 						"public class W {\n" +
7964 						"	public static void main(String... args) {}\n" +
7965 						"}\n"
7966 					}, wJarLocation, "9");
7967 
7968 			// ------ X ------
7969 			addModularLibraryEntry(x, wJarPath, null);
7970 			createFolder("X/src/com/example/x");
7971 			createFile("X/src/com/example/x/X.java",
7972 					"package com.example.x;\n" +
7973 					"public class X {\n" +
7974 					"    public static void main(String[] args) { \n" +
7975 					"        System.out.println(\"X\");\n" +
7976 					"    }\n" +
7977 					"}\n");
7978 			createFile("X/src/module-info.java",
7979 					"open module com.example.x {\n" +
7980 					"    exports com.example.x;\n" +
7981 					"    requires w;\n" +
7982 					"}\n");
7983 
7984 			// ------ Y ------
7985 			addModularLibraryEntry(y, wJarPath, null);
7986 			addModularProjectEntry(y, x);
7987 			createFolder("Y/src/com/example/y");
7988 			createFile("Y/src/com/example/y/Y.java",
7989 					"package com.example.y;\n" +
7990 					"public class Y {\n" +
7991 					"    public static void main(String[] args) { \n" +
7992 					"        System.out.println(\"Y\");\n" +
7993 					"    }\n" +
7994 					"}\n");
7995 			createFile("Y/src/module-info.java",
7996 					"open module com.example.y {\n" +
7997 					"    exports com.example.y;\n" +
7998 					"    requires com.example.x;\n" +
7999 					"}\n");
8000 
8001 			// ------ N ------
8002 			createFolder("N/src/com/example/n");
8003 			createFile("N/src/com/example/n/N.java",
8004 					"package com.example.n;\n" +
8005 					"public class N {\n" +
8006 					"    public static void main(String[] args) { \n" +
8007 					"        System.out.println(\"N\");\n" +
8008 					"    } \n" +
8009 					"}\n");
8010 			createFile("N/src/module-info.java",
8011 					"open module n {\n" +
8012 					"    exports com.example.n;\n" +
8013 					"}\n");
8014 
8015 			// ------ M ------
8016 			// insert new entries before JRE:
8017 			IClasspathEntry[] entries = m.getRawClasspath();
8018 			int length = entries.length;
8019 			System.arraycopy(entries, 0, entries = new IClasspathEntry[length + 4], 4, length);
8020 			entries[0] = entries[4];
8021 			entries[1] = newModularLibraryEntry(wJarPath, null, null);
8022 			entries[2] = newModularProjectEntry(n);
8023 			entries[3] = newModularProjectEntry(x);
8024 			entries[4] = newModularProjectEntry(y);
8025 			m.setRawClasspath(entries, null);
8026 
8027 			createFolder("M/src/m");
8028 			String mSource =
8029 					"package m;\n" +
8030 					"import com.example.n.N;\n" +
8031 					"public class M {\n" +
8032 					"    public static void main(String[] args) {\n" +
8033 					"        System.out.println(\"M\");\n" +
8034 					"        N.main(null);\n" +
8035 					"    }\n" +
8036 					"}\n";
8037 			String mPath = "M/src/m/M.java";
8038 			createFile(mPath, mSource);
8039 			createFile("M/src/module-info.java",
8040 					"open module m {\n" +
8041 					"    requires n;\n" +
8042 					"    requires w;\n" +
8043 					"}\n");
8044 
8045 			getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, null);
8046 			assertNoErrors();
8047 
8048 			m.getProject().build(IncrementalProjectBuilder.FULL_BUILD, null);
8049 			assertNoErrors();
8050 
8051 			this.problemRequestor.initialize(mSource.toCharArray());
8052 			getCompilationUnit(mPath).getWorkingCopy(this.wcOwner, null);
8053 			assertProblems("unexpected problems",
8054 					"----------\n" +
8055 					"----------\n",
8056 					this.problemRequestor);
8057 		} finally {
8058 			deleteProject(m);
8059 			deleteProject(n);
8060 			deleteProject(x);
8061 			deleteProject(y);
8062 			File outputDir = new File(outputDirectory);
8063 			if (outputDir.exists())
8064 				Util.flushDirectoryContent(outputDir);
8065 		}
8066 	}
8067 
testBug544126()8068 	public void testBug544126() throws CoreException, IOException {
8069 		String outputDirectory = Util.getOutputDirectory();
8070 		IJavaProject p = createJava9Project("p");
8071 		try {
8072 			String jar1Path = outputDirectory + File.separator + "auto1Lib.jar";
8073 			createJar(
8074 					new String[] {
8075 						"org/test/Root.java",
8076 						"package org.test;\n" +
8077 						"public class Root {}\n"
8078 					},
8079 					jar1Path);
8080 			String jar2Path = outputDirectory + File.separator + "auto2Lib.jar";
8081 			createJar(
8082 					new String[] {
8083 						"org/test/ext/Ext.java",
8084 						"package org.test.ext;\n" +
8085 						"public class Ext {}\n"
8086 					},
8087 					jar2Path);
8088 			addModularLibraryEntry(p, new Path(jar1Path), null);
8089 			addModularLibraryEntry(p, new Path(jar2Path), null);
8090 			createFolder("p/src/test");
8091 			String testPath = "p/src/test/Test.java";
8092 			String testSource =
8093 					"package test;\n" +
8094 					"import org.test.Root;\n" +
8095 					"public class Test {\n" +
8096 					"    public static void main(String[] args) { \n" +
8097 					"        System.out.println(new Root());\n" +
8098 					"    }\n" +
8099 					"}\n";
8100 			createFile(testPath, testSource);
8101 			createFile("p/src/module-info.java",
8102 					"module test {\n" +
8103 					"    requires auto1Lib;\n" +
8104 					"    requires auto2Lib;\n" +
8105 					"}\n");
8106 			getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, null);
8107 			assertNoErrors();
8108 
8109 			this.problemRequestor.initialize(testSource.toCharArray());
8110 			getCompilationUnit(testPath).getWorkingCopy(this.wcOwner, null);
8111 			assertProblems("unexpected problems",
8112 					"----------\n" +
8113 					"----------\n",
8114 					this.problemRequestor);
8115 		} finally {
8116 			deleteProject(p);
8117 			File outputDir = new File(outputDirectory);
8118 			if (outputDir.exists())
8119 				Util.flushDirectoryContent(outputDir);
8120 		}
8121 	}
8122 
testBug544432()8123 	public void testBug544432() throws CoreException {
8124 		IJavaProject prjA = createJava9Project("A");
8125 		IJavaProject prjB = createJava9Project("B");
8126 		try {
8127 			createFolder("A/src/com/a");
8128 			createFile("A/src/com/a/A.java",
8129 				"package com.a;\n" +
8130 				"\n" +
8131 				"public class A {}\n");
8132 			createFile("A/src/module-info.java",
8133 				"open module com.a {\n" +
8134 				"	exports com.a;\n" +
8135 				"}\n");
8136 
8137 			addModularProjectEntry(prjB, prjA);
8138 			createFolder("B/src/com/a/b");
8139 			String bPath = "B/src/com/a/b/B.java";
8140 			String bSource =
8141 				"package com.a.b;\n" +
8142 				"import com.a.A;\n" +
8143 				"public class B {\n" +
8144 				"	\n" +
8145 				"	public static void main(String[] args) {\n" +
8146 				"		A a = new A();\n" +
8147 				"		System.out.println(a);\n" +
8148 				"	}\n" +
8149 				"}\n";
8150 			createFile(bPath, bSource);
8151 			createFile("B/src/module-info.java",
8152 				"open module com.a.b {\n" +
8153 				"	requires com.a;\n" +
8154 				"}\n");
8155 			getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, null);
8156 			assertNoErrors();
8157 
8158 			this.problemRequestor.initialize(bSource.toCharArray());
8159 			getCompilationUnit(bPath).getWorkingCopy(this.wcOwner, null);
8160 			assertProblems("unexpected problems",
8161 					"----------\n" +
8162 					"----------\n",
8163 					this.problemRequestor);
8164 		} finally {
8165 			deleteProject(prjA);
8166 			deleteProject(prjB);
8167 		}
8168 	}
8169 
testReleaseOption1()8170 	public void testReleaseOption1() throws Exception {
8171 		Hashtable<String, String> options = JavaCore.getOptions();
8172 		IJavaProject p = createJava9Project("p");
8173 		p.setOption(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_7);
8174 		p.setOption(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_7);
8175 		p.setOption(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_1_7);
8176 		p.setOption(JavaCore.COMPILER_RELEASE, JavaCore.ENABLED);
8177 		String outputDirectory = Util.getOutputDirectory();
8178 		try {
8179 			String testSource = "public class X {\n" +
8180 								"}";
8181 			String mPath = "p/src/X.java";
8182 			createFile(mPath,
8183 					testSource);
8184 			p.getProject().build(IncrementalProjectBuilder.INCREMENTAL_BUILD, null);
8185 			waitForAutoBuild();
8186 			IMarker[] markers = p.getProject().findMarkers(null, true, IResource.DEPTH_INFINITE);
8187 			assertMarkers("Unexpected markers",
8188 					"",  markers);
8189 
8190 		} finally {
8191 			JavaCore.setOptions(options);
8192 			deleteProject(p);
8193 			File outputDir = new File(outputDirectory);
8194 			if (outputDir.exists())
8195 				Util.flushDirectoryContent(outputDir);
8196 		}
8197 	}
testReleaseOption2()8198 	public void testReleaseOption2() throws Exception {
8199 		if (!isJRE12)
8200 			return;
8201 		Hashtable<String, String> options = JavaCore.getOptions();
8202 		IJavaProject p = createJava9Project("p");
8203 		p.setOption(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_6);
8204 		p.setOption(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_6);
8205 		p.setOption(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_1_6);
8206 		p.setOption(JavaCore.COMPILER_RELEASE, JavaCore.ENABLED);
8207 		String outputDirectory = Util.getOutputDirectory();
8208 		try {
8209 			String testSource = "public class X {\n" +
8210 								"	public java.util.stream.Stream<String> emptyStream() {\n" +
8211 								"		return null;\n" +
8212 								"	}\n" +
8213 								"}";
8214 			String mPath = "p/src/X.java";
8215 			createFile(mPath,
8216 					testSource);
8217 			p.getProject().build(IncrementalProjectBuilder.INCREMENTAL_BUILD, null);
8218 			waitForAutoBuild();
8219 			IMarker[] markers = p.getProject().findMarkers(null, true, IResource.DEPTH_INFINITE);
8220 			assertMarkers("Unexpected markers",
8221 					"The project was not built due to \"release 6 is not found in the system\". "
8222 					+ "Fix the problem, then try refreshing this project and building it since it may be inconsistent",  markers);
8223 
8224 		} finally {
8225 			JavaCore.setOptions(options);
8226 			deleteProject(p);
8227 			File outputDir = new File(outputDirectory);
8228 			if (outputDir.exists())
8229 				Util.flushDirectoryContent(outputDir);
8230 		}
8231 	}
testReleaseOption3()8232 	public void testReleaseOption3() throws Exception {
8233 		if (isJRE12)
8234 			return;
8235 		Hashtable<String, String> options = JavaCore.getOptions();
8236 		IJavaProject p = createJava9Project("p");
8237 		p.setOption(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_7);
8238 		p.setOption(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_7);
8239 		p.setOption(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_1_7);
8240 		p.setOption(JavaCore.COMPILER_RELEASE, JavaCore.ENABLED);
8241 		String outputDirectory = Util.getOutputDirectory();
8242 		try {
8243 			String testSource = "public class X {\n" +
8244 								"	public java.util.stream.Stream<String> emptyStream() {\n" +
8245 								"		return null;\n" +
8246 								"	}\n" +
8247 								"}";
8248 			String mPath = "p/src/X.java";
8249 			createFile(mPath,
8250 					testSource);
8251 			p.getProject().build(IncrementalProjectBuilder.INCREMENTAL_BUILD, null);
8252 			waitForAutoBuild();
8253 			IMarker[] markers = p.getProject().findMarkers(null, true, IResource.DEPTH_INFINITE);
8254 			assertMarkers("Unexpected markers",
8255 					"java.util.stream.Stream cannot be resolved to a type",  markers);
8256 
8257 		} finally {
8258 			JavaCore.setOptions(options);
8259 			deleteProject(p);
8260 			File outputDir = new File(outputDirectory);
8261 			if (outputDir.exists())
8262 				Util.flushDirectoryContent(outputDir);
8263 		}
8264 	}
testReleaseOption4()8265 	public void testReleaseOption4() throws Exception {
8266 		Hashtable<String, String> options = JavaCore.getOptions();
8267 		IJavaProject p = createJava9Project("p");
8268 		p.setOption(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_8);
8269 		p.setOption(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_8);
8270 		p.setOption(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_1_8);
8271 		p.setOption(JavaCore.COMPILER_RELEASE, JavaCore.ENABLED);
8272 		String outputDirectory = Util.getOutputDirectory();
8273 		try {
8274 			String testSource = "public class X {\n" +
8275 								"	public java.util.stream.Stream<String> emptyStream() {\n" +
8276 								"		return null;\n" +
8277 								"	}\n" +
8278 								"}";
8279 			String mPath = "p/src/X.java";
8280 			createFile(mPath,
8281 					testSource);
8282 			p.getProject().build(IncrementalProjectBuilder.INCREMENTAL_BUILD, null);
8283 			waitForAutoBuild();
8284 			IMarker[] markers = p.getProject().findMarkers(null, true, IResource.DEPTH_INFINITE);
8285 			assertMarkers("Unexpected markers",
8286 					"",  markers);
8287 
8288 		} finally {
8289 			JavaCore.setOptions(options);
8290 			deleteProject(p);
8291 			File outputDir = new File(outputDirectory);
8292 			if (outputDir.exists())
8293 				Util.flushDirectoryContent(outputDir);
8294 		}
8295 	}
testReleaseOption5()8296 	public void testReleaseOption5() throws Exception {
8297 		Hashtable<String, String> options = JavaCore.getOptions();
8298 		IJavaProject p = createJava9Project("p");
8299 		p.setOption(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_7);
8300 		p.setOption(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_7);
8301 		p.setOption(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_1_7);
8302 		p.setOption(JavaCore.COMPILER_RELEASE, JavaCore.ENABLED);
8303 		String outputDirectory = Util.getOutputDirectory();
8304 		try {
8305 			String testSource = "public class X {\n" +
8306 								"	public java.util.stream.Stream<String> emptyStream() {\n" +
8307 								"		return null;\n" +
8308 								"	}\n" +
8309 								"}";
8310 			String mPath = "p/src/X.java";
8311 			createFile(mPath,
8312 					testSource);
8313 			p.getProject().build(IncrementalProjectBuilder.INCREMENTAL_BUILD, null);
8314 			waitForAutoBuild();
8315 			IMarker[] markers = p.getProject().findMarkers(null, true, IResource.DEPTH_INFINITE);
8316 			assertMarkers("Unexpected markers",
8317 					"java.util.stream.Stream cannot be resolved to a type",  markers);
8318 
8319 		} finally {
8320 			JavaCore.setOptions(options);
8321 			deleteProject(p);
8322 			File outputDir = new File(outputDirectory);
8323 			if (outputDir.exists())
8324 				Util.flushDirectoryContent(outputDir);
8325 		}
8326 	}
testReleaseOption6()8327 	public void testReleaseOption6() throws Exception {
8328 		Hashtable<String, String> options = JavaCore.getOptions();
8329 		IJavaProject p = createJava9Project("p");
8330 		p.setOption(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_7);
8331 		p.setOption(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_7);
8332 		p.setOption(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_1_7);
8333 		p.setOption(JavaCore.COMPILER_RELEASE, JavaCore.ENABLED);
8334 		String outputDirectory = Util.getOutputDirectory();
8335 		try {
8336 			String testSource = "interface I {\n" +
8337 								"  int add(int x, int y);\n" +
8338 								"}\n" +
8339 								"public class X {\n" +
8340 								"  public static void main(String[] args) {\n" +
8341 								"    I i = (x, y) -> {\n" +
8342 								"      return x + y;\n" +
8343 								"    };\n" +
8344 								"  }\n" +
8345 								"}\n";
8346 			String mPath = "p/src/X.java";
8347 			createFile(mPath,
8348 					testSource);
8349 			p.getProject().build(IncrementalProjectBuilder.INCREMENTAL_BUILD, null);
8350 			waitForAutoBuild();
8351 			IMarker[] markers = p.getProject().findMarkers(null, true, IResource.DEPTH_INFINITE);
8352 			assertMarkers("Unexpected markers",
8353 					"Lambda expressions are allowed only at source level 1.8 or above",  markers);
8354 
8355 		} finally {
8356 			JavaCore.setOptions(options);
8357 			deleteProject(p);
8358 			File outputDir = new File(outputDirectory);
8359 			if (outputDir.exists())
8360 				Util.flushDirectoryContent(outputDir);
8361 		}
8362 	}
testReleaseOption7()8363 	public void testReleaseOption7() throws Exception {
8364 		if (isJRE12)
8365 			return;
8366 		Hashtable<String, String> options = JavaCore.getOptions();
8367 		IJavaProject p = createJava9Project("p");
8368 		p.setOption(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_6);
8369 		p.setOption(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_6);
8370 		p.setOption(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_1_6);
8371 		p.setOption(JavaCore.COMPILER_RELEASE, JavaCore.ENABLED);
8372 		String outputDirectory = Util.getOutputDirectory();
8373 		try {
8374 			String testSource = "import java.io.*;\n" +
8375 								"public class X {\n" +
8376 								"	public static void main(String[] args) {\n" +
8377 								"		try {\n" +
8378 								"			System.out.println();\n" +
8379 								"			Reader r = new FileReader(args[0]);\n" +
8380 								"			r.read();\n" +
8381 								"		} catch(IOException | FileNotFoundException e) {\n" +
8382 								"			e.printStackTrace();\n" +
8383 								"		}\n" +
8384 								"	}\n" +
8385 								"}";
8386 			String mPath = "p/src/X.java";
8387 			createFile(mPath,
8388 					testSource);
8389 			p.getProject().build(IncrementalProjectBuilder.INCREMENTAL_BUILD, null);
8390 			waitForAutoBuild();
8391 			IMarker[] markers = p.getProject().findMarkers(null, true, IResource.DEPTH_INFINITE);
8392 			sortMarkers(markers);
8393 			assertMarkers("Unexpected markers",
8394 							"Multi-catch parameters are not allowed for source level below 1.7\n" +
8395 							"The exception FileNotFoundException is already caught by the alternative IOException",  markers);
8396 
8397 		} finally {
8398 			JavaCore.setOptions(options);
8399 			deleteProject(p);
8400 			File outputDir = new File(outputDirectory);
8401 			if (outputDir.exists())
8402 				Util.flushDirectoryContent(outputDir);
8403 		}
8404 	}
testReleaseOption8()8405 	public void testReleaseOption8() throws Exception {
8406 		Hashtable<String, String> options = JavaCore.getOptions();
8407 		IJavaProject p = createJava9Project("p");
8408 		p.setOption(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_9);
8409 		p.setOption(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_9);
8410 		p.setOption(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_9);
8411 		p.setOption(JavaCore.COMPILER_RELEASE, JavaCore.ENABLED);
8412 		String outputDirectory = Util.getOutputDirectory();
8413 		try {
8414 			String testSource = "module mod.one { \n" +
8415 								"	requires java.base;\n" +
8416 								"}";
8417 			String mPath = "p/src/module-info.java";
8418 			createFile(mPath,
8419 					testSource);
8420 			p.getProject().build(IncrementalProjectBuilder.INCREMENTAL_BUILD, null);
8421 			waitForAutoBuild();
8422 			IMarker[] markers = p.getProject().findMarkers(null, true, IResource.DEPTH_INFINITE);
8423 			assertMarkers("Unexpected markers",
8424 					"",  markers);
8425 
8426 		} finally {
8427 			JavaCore.setOptions(options);
8428 			deleteProject(p);
8429 			File outputDir = new File(outputDirectory);
8430 			if (outputDir.exists())
8431 				Util.flushDirectoryContent(outputDir);
8432 		}
8433 	}
testReleaseOption9()8434 	public void testReleaseOption9() throws Exception {
8435 		if (!isJRE10) return;
8436 		Hashtable<String, String> options = JavaCore.getOptions();
8437 		IJavaProject p = createJava9Project("p");
8438 		p.setOption(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_10);
8439 		p.setOption(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_10);
8440 		p.setOption(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_10);
8441 		p.setOption(JavaCore.COMPILER_RELEASE, JavaCore.ENABLED);
8442 		String outputDirectory = Util.getOutputDirectory();
8443 		try {
8444 			String testSource = "module mod.one { \n" +
8445 								"	requires java.base;\n" +
8446 								"}";
8447 			String mPath = "p/src/module-info.java";
8448 			createFile(mPath,
8449 					testSource);
8450 			p.getProject().build(IncrementalProjectBuilder.INCREMENTAL_BUILD, null);
8451 			waitForAutoBuild();
8452 			IMarker[] markers = p.getProject().findMarkers(null, true, IResource.DEPTH_INFINITE);
8453 			assertMarkers("Unexpected markers",
8454 					"",  markers);
8455 
8456 		} finally {
8457 			JavaCore.setOptions(options);
8458 			deleteProject(p);
8459 			File outputDir = new File(outputDirectory);
8460 			if (outputDir.exists())
8461 				Util.flushDirectoryContent(outputDir);
8462 		}
8463 	}
testReleaseOption10()8464 	public void testReleaseOption10() throws Exception {
8465 		Hashtable<String, String> options = JavaCore.getOptions();
8466 		IJavaProject p = createJava9Project("p");
8467 		p.setOption(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_8);
8468 		p.setOption(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_8);
8469 		p.setOption(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_1_8);
8470 		p.setOption(JavaCore.COMPILER_RELEASE, JavaCore.ENABLED);
8471 		String outputDirectory = Util.getOutputDirectory();
8472 		try {
8473 			String testSource = "module mod.one { \n" +
8474 					"	requires java.base;\n" +
8475 					"}";
8476 			String mPath = "p/src/module-info.java";
8477 			createFile(mPath,
8478 					testSource);
8479 			p.getProject().build(IncrementalProjectBuilder.INCREMENTAL_BUILD, null);
8480 			waitForAutoBuild();
8481 			IMarker[] markers = p.getProject().findMarkers(null, true, IResource.DEPTH_INFINITE);
8482 			sortMarkers(markers);
8483 			String expected =
8484 					"Syntax error on token \"module\", package expected\n" +
8485 					"Syntax error on token(s), misplaced construct(s)\n" +
8486 					"Syntax error on token \".\", , expected\n" +
8487 					"Syntax error on token \"}\", delete this token";
8488 			assertMarkers("Unexpected markers",
8489 							expected,  markers);
8490 
8491 		} finally {
8492 			JavaCore.setOptions(options);
8493 			deleteProject(p);
8494 			File outputDir = new File(outputDirectory);
8495 			if (outputDir.exists())
8496 				Util.flushDirectoryContent(outputDir);
8497 		}
8498 	}
testReleaseOption11()8499 	public void testReleaseOption11() throws Exception {
8500 		Hashtable<String, String> options = JavaCore.getOptions();
8501 		IJavaProject p = createJava9Project("p");
8502 		p.setOption(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_8);
8503 		p.setOption(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_8);
8504 		p.setOption(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_1_8);
8505 		p.setOption(JavaCore.COMPILER_RELEASE, JavaCore.ENABLED);
8506 		String outputDirectory = Util.getOutputDirectory();
8507 		try {
8508 			createFolder("p/src/foo");
8509 			createFile(
8510 					"p/src/foo/Module.java",
8511 					"package foo;\n" +
8512 					"public class Module {}\n");
8513 			createFile(
8514 					"p/src/foo/X.java",
8515 					"package foo;\n" +
8516 					"public class X { \n" +
8517 					"	public Module getModule(String name) {\n" +
8518 					"		return null;\n" +
8519 					"	}\n" +
8520 					"}");
8521 			p.getProject().build(IncrementalProjectBuilder.INCREMENTAL_BUILD, null);
8522 			waitForAutoBuild();
8523 			IMarker[] markers = p.getProject().findMarkers(null, true, IResource.DEPTH_INFINITE);
8524 			assertMarkers("Unexpected markers",
8525 					"",  markers);
8526 
8527 		} finally {
8528 			JavaCore.setOptions(options);
8529 			deleteProject(p);
8530 			File outputDir = new File(outputDirectory);
8531 			if (outputDir.exists())
8532 				Util.flushDirectoryContent(outputDir);
8533 		}
8534 	}
testReleaseOption12()8535 	public void testReleaseOption12() throws Exception {
8536 		if (!isJRE12)
8537 			return;
8538 		Hashtable<String, String> options = JavaCore.getOptions();
8539 		IJavaProject p = createJava9Project("p");
8540 		p.setOption(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_7);
8541 		p.setOption(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_7);
8542 		p.setOption(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_1_7);
8543 		p.setOption(JavaCore.COMPILER_RELEASE, JavaCore.ENABLED);
8544 		String outputDirectory = Util.getOutputDirectory();
8545 		try {
8546 			String testSource = "import java.io.*;\n" +
8547 								"\n" +
8548 								"public class X {\n" +
8549 								"	public static void main(String[] args) {\n" +
8550 								"		String str = Integer.toUnsignedString(1, 1);\n" +
8551 								"	}\n" +
8552 								"}";
8553 			String mPath = "p/src/X.java";
8554 			createFile(mPath,
8555 					testSource);
8556 			p.getProject().build(IncrementalProjectBuilder.INCREMENTAL_BUILD, null);
8557 			waitForAutoBuild();
8558 			IMarker[] markers = p.getProject().findMarkers(null, true, IResource.DEPTH_INFINITE);
8559 			assertMarkers("Unexpected markers",
8560 					"The method toUnsignedString(int, int) is undefined for the type Integer",  markers);
8561 
8562 		} finally {
8563 			JavaCore.setOptions(options);
8564 			deleteProject(p);
8565 			File outputDir = new File(outputDirectory);
8566 			if (outputDir.exists())
8567 				Util.flushDirectoryContent(outputDir);
8568 		}
8569 	}
testReleaseOption13()8570 	public void testReleaseOption13() throws Exception {
8571 		if (!isJRE12)
8572 			return;
8573 		Hashtable<String, String> options = JavaCore.getOptions();
8574 		IJavaProject p = createJava9Project("p");
8575 		p.setOption(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_8);
8576 		p.setOption(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_8);
8577 		p.setOption(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_1_8);
8578 		p.setOption(JavaCore.COMPILER_RELEASE, JavaCore.ENABLED);
8579 		String outputDirectory = Util.getOutputDirectory();
8580 		try {
8581 			String testSource = "\n" +
8582 								"public class X {\n" +
8583 								"	public static void main(String[] args) {\n" +
8584 								"		Integer.toUnsignedString(1, 1);\n" +
8585 								"	}\n" +
8586 								"}";
8587 			String mPath = "p/src/X.java";
8588 			createFile(mPath,
8589 					testSource);
8590 			p.getProject().build(IncrementalProjectBuilder.INCREMENTAL_BUILD, null);
8591 			waitForAutoBuild();
8592 			IMarker[] markers = p.getProject().findMarkers(null, true, IResource.DEPTH_INFINITE);
8593 			assertMarkers("Unexpected markers",
8594 					"",  markers);
8595 
8596 		} finally {
8597 			JavaCore.setOptions(options);
8598 			deleteProject(p);
8599 			File outputDir = new File(outputDirectory);
8600 			if (outputDir.exists())
8601 				Util.flushDirectoryContent(outputDir);
8602 		}
8603 	}
testBug547114a()8604 	public void testBug547114a() throws CoreException, IOException {
8605 		String outputDirectory = Util.getOutputDirectory();
8606 		String jarPath = outputDirectory + File.separator + "lib.jar";
8607 		try {
8608 			// focus project has no module-info, to trigger path where LE#knownPackages is not empty when processing add-reads
8609 			String[] sources = new String[] {
8610 					"src/org/astro/World.java",
8611 					"package org.astro;\n" +
8612 					"import p.C;\n" +
8613 					"public class World {\n" +
8614 					"	C f;\n" +
8615 					"}\n"
8616 			};
8617 			IJavaProject p = setupModuleProject("org.astro", sources);
8618 
8619 			Util.createJar(new String[] {
8620 					"/lib/src/module-info.java",
8621 					"module lib {\n" +
8622 					"	exports p;\n" +
8623 					"}\n",
8624 					"/lib/src/p/C.java",
8625 					"package p;\n" +
8626 					"public class C {}\n",
8627 				},
8628 				jarPath,
8629 				"9");
8630 			addClasspathEntry(p, JavaCore.newLibraryEntry(new Path(jarPath), null, null, null,
8631 					new IClasspathAttribute[] {
8632 						JavaCore.newClasspathAttribute(IClasspathAttribute.MODULE, "true"),
8633 						JavaCore.newClasspathAttribute(IClasspathAttribute.ADD_READS, "lib=missing.module") // problematic directive on jar-dependency
8634 					},
8635 					false));
8636 
8637 			p.getProject().build(IncrementalProjectBuilder.INCREMENTAL_BUILD, null);
8638 			waitForAutoBuild();
8639 
8640 			IMarker[] markers = p.getProject().findMarkers(null, true, IResource.DEPTH_INFINITE);
8641 			// 1. marker is on the project, second on the "current" CU: World.java.
8642 			assertMarkers("Unexpected markers",
8643 					"The project was not built since its build path has a problem: missing.module cannot be resolved to a module, it is referenced from an add-reads directive. Fix the build path then try building this project\n" +
8644 					"missing.module cannot be resolved to a module, it is referenced from an add-reads directive",
8645 					markers);
8646 		} finally {
8647 			deleteProject("org.astro");
8648 			deleteFile(jarPath);
8649 		}
8650 	}
testBug547114b()8651 	public void testBug547114b() throws CoreException, IOException {
8652 		try {
8653 			IJavaProject p = setupModuleProject("org.astro", new String[] {
8654 					"src/module-info.java",
8655 					"module org.astro {\n" +
8656 					"	requires lib;\n" +
8657 					"}\n",
8658 					"src/org/astro/World.java",
8659 					"package org.astro;\n" +
8660 					"import p.C;\n" +
8661 					"public class World {\n" +
8662 					"	C f;\n" +
8663 					"}\n"
8664 			});
8665 
8666 			IJavaProject lib = setupModuleProject("lib", new String[] {
8667 					"src/module-info.java",
8668 					"module lib {\n" +
8669 					"	exports p;\n" +
8670 					"}\n",
8671 					"src/p/C.java",
8672 					"package p;\n" +
8673 					"public class C {}\n",
8674 			});
8675 			addClasspathEntry(p, JavaCore.newProjectEntry(lib.getPath(), null, false,
8676 					new IClasspathAttribute[] {
8677 						JavaCore.newClasspathAttribute(IClasspathAttribute.MODULE, "true"),
8678 						JavaCore.newClasspathAttribute(IClasspathAttribute.ADD_READS, "lib=missing.module") // problematic directive on project dependency
8679 					},
8680 					false));
8681 
8682 			ResourcesPlugin.getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, null);
8683 			waitForAutoBuild();
8684 
8685 			IMarker[] markers = p.getProject().findMarkers(null, true, IResource.DEPTH_INFINITE);
8686 			// 1. marker is on the project, second on the "current" CU: World.java.
8687 			assertMarkers("Unexpected markers",
8688 					"The project was not built since its build path has a problem: missing.module cannot be resolved to a module, it is referenced from an add-reads directive. Fix the build path then try building this project\n" +
8689 					"missing.module cannot be resolved to a module, it is referenced from an add-reads directive",
8690 					markers);
8691 		} finally {
8692 			deleteProject("org.astro");
8693 			deleteProject("lib");
8694 		}
8695 	}
8696 
testBug558004()8697 	public void testBug558004() throws CoreException {
8698 		IJavaProject prj = createJava9Project("A");
8699 		try {
8700 			String moduleinfopath = "A/src/module-info.java";
8701 			String moduleinfosrc =
8702 				"/**\n" +
8703 				" * The {@link java.nio.file.FileSystems#newFileSystem FileSystems.newFileSystem(URI.create(\"jrt:/\"))}\n" +
8704 				" */\n" +
8705 				"module modulartest11 {\n" +
8706 				"}\n";
8707 			createFile(moduleinfopath, moduleinfosrc);
8708 			getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, null);
8709 			assertNoErrors();
8710 			this.problemRequestor.initialize(moduleinfosrc.toCharArray());
8711 			getCompilationUnit("A/src/module-info.java").getWorkingCopy(this.wcOwner, null);
8712 			assertProblems("unexpected problems",
8713 					"----------\n" +
8714 					"----------\n",
8715 					this.problemRequestor);
8716 		} finally {
8717 			deleteProject(prj);
8718 		}
8719 	}
8720 
testBug547479()8721 	public void testBug547479() throws CoreException {
8722 		int max = org.eclipse.jdt.internal.core.builder.AbstractImageBuilder.MAX_AT_ONCE;
8723 
8724 		IJavaProject prjA = createJava9Project("A");
8725 		IJavaProject prjB = createJava9Project("B");
8726 		try {
8727 			createFile("A/src/module-info.java",
8728 				"module A {\n" +
8729 				"}\n");
8730 
8731 			addModularProjectEntry(prjB, prjA);
8732 			// prepare files to be compiled in two batches à 2 files:
8733 			org.eclipse.jdt.internal.core.builder.AbstractImageBuilder.MAX_AT_ONCE = 2;
8734 			// ---1---
8735 			createFolder("B/src/b");
8736 			createFile("B/src/b/Class1.java",
8737 				"package b;\n" +
8738 				"import java.sql.Connection;\n" +
8739 				"public class Class1 {\n" +
8740 				"	Connection connection;\n" +
8741 				"}\n");
8742 			createFile("B/src/b/Class2.java",
8743 				"package b;\n" +
8744 				"import java.sql.Connection;\n" +
8745 				"public class Class2 {\n" +
8746 				"	Connection connection;\n" +
8747 				"}\n");
8748 			// ---2---
8749 			createFile("B/src/module-info.java",
8750 				"module B {\n" +
8751 				"	requires java.sql;\n" +
8752 				"	requires A;\n" +
8753 				"}\n");
8754 			String bPath = "B/src/b/Class3.java";
8755 			String bSource =
8756 				"package b;\n" + // <= this triggered createPackage in an inconsistent state
8757 				"import java.sql.Connection;\n" +
8758 				"public class Class3 {\n" +
8759 				"	Connection connection;\n" +
8760 				"}\n";
8761 			createFile(bPath, bSource);
8762 			getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, null);
8763 			assertNoErrors();
8764 
8765 			this.problemRequestor.initialize(bSource.toCharArray());
8766 			getCompilationUnit(bPath).getWorkingCopy(this.wcOwner, null);
8767 			assertProblems("unexpected problems",
8768 					"----------\n" +
8769 					"----------\n",
8770 					this.problemRequestor);
8771 		} finally {
8772 			org.eclipse.jdt.internal.core.builder.AbstractImageBuilder.MAX_AT_ONCE = max;
8773 			deleteProject(prjA);
8774 			deleteProject(prjB);
8775 		}
8776 	}
testBug547181()8777 	public void testBug547181() throws CoreException {
8778 		IJavaProject prjA = createJava9Project("A");
8779 		IJavaProject prjB = createJava9Project("B");
8780 		IJavaProject prjC = createJava9Project("C");
8781 		IJavaProject prjD = createJava9Project("D");
8782 		try {
8783 			createFile("A/src/module-info.java",
8784 				"module A {\n" +
8785 				" exports p1.p2;\n" +
8786 				"}\n");
8787 			createFolder("A/src/p1/p2");
8788 			createFile("A/src/p1/p2/X.java",
8789 					"package p1.p2;\n" +
8790 					"public class X {\n" +
8791 					"}\n");
8792 
8793 			addModularProjectEntry(prjB, prjA);
8794 			addModularProjectEntry(prjD, prjA);
8795 			addModularProjectEntry(prjD, prjB);
8796 			addModularProjectEntry(prjD, prjC);
8797 
8798 			createFile("B/src/module-info.java",
8799 					"module B {\n" +
8800 						" requires A;\n" +
8801 						" exports p1;\n" +
8802 					"}\n");
8803 			createFolder("B/src/p1");
8804 			createFile("B/src/p1/Y.java",
8805 				"package p1;\n" +
8806 				"import p1.p2.X;\n" +
8807 				"public class Y {\n" +
8808 				"	private void f(X x) {}\n" +
8809 				"}\n");
8810 
8811 			createFile("C/src/module-info.java",
8812 					"module C {\n" +
8813 					" exports p1.p2;\n" +
8814 					"}\n");
8815 			createFolder("C/src/p1/p2");
8816 			createFile("C/src/p1/p2/X.java",
8817 					"package p1.p2;\n" +
8818 					"public class X {\n" +
8819 					"}\n");
8820 
8821 			createFile("D/src/module-info.java",
8822 					"module D {\n" +
8823 						" requires B;\n" +
8824 						" requires C;\n" +
8825 					"}\n");
8826 
8827 			createFolder("D/src/usage");
8828 			createFile("D/src/usage/AAA.java",
8829 					"package usage;\n" +
8830 					"import p1.Y;\n" +
8831 					"public class AAA {\n" +
8832 					" Y y;\n" +
8833 					"}\n");
8834 			createFile("D/src/usage/Usage.java",
8835 					"package usage;\n" +
8836 					"import p1.p2.X;\n" +
8837 					"public class Usage {\n" +
8838 					" X x;\n" +
8839 					"}\n");
8840 
8841 			getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, null);
8842 			assertNoErrors();
8843 
8844 		} finally {
8845 			deleteProject(prjA);
8846 			deleteProject(prjB);
8847 			deleteProject(prjC);
8848 			deleteProject(prjD);
8849 		}
8850 	}
testBug547181Comment104()8851 	public void testBug547181Comment104() throws CoreException {
8852 
8853 		IJavaProject prjA = createJava9Project("A");
8854 		IJavaProject prjB = createJava9Project("B");
8855 		try {
8856 			// NO module-info.java, so A is accessed as automatic module
8857 			createFolder("A/src/pack/a");
8858 
8859 			createFile("A/src/pack/_some_resource_without_extension",
8860 					"dummy content\n");
8861 
8862 			addModularProjectEntry(prjB, prjA);
8863 			// ---1---
8864 			createFolder("B/src/pack/b");
8865 			createFile("B/src/pack/b/Usage.java",
8866 				"package pack.b;\n" +
8867 				"public class Usage {\n" +
8868 				"}\n");
8869 			createFile("B/src/module-info.java",
8870 					"module B {\n" +
8871 					" requires A;\n" +
8872 					"}\n");
8873 			getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, null);
8874 			assertNoErrors();
8875 		} finally {
8876 			deleteProject(prjA);
8877 			deleteProject(prjB);
8878 		}
8879 	}
testBug538512_comment9()8880 	public void testBug538512_comment9() throws CoreException, IOException {
8881 		try {
8882 			IJavaProject project = createJava9Project("ztest", new String[] { "src" });
8883 			createFolder("/ztest/lib");
8884 			Util.createJar(new String[] {
8885 					"org/xml/sax/Parser.java",
8886 					"package org.xml.sax;\n" +
8887 					"public class Parser {}\n"
8888 				},
8889 				project.getProject().getLocation().toString() + "/lib/xml-apis.jar", // conflicts with module 'java.xml'
8890 				"1.8");
8891 			IClasspathEntry libraryEntry = JavaCore.newLibraryEntry(new Path("/ztest/lib/xml-apis.jar"), null, null);
8892 			addClasspathEntry(project, libraryEntry, 1); // right after src and before jrt-fs.jar
8893 			Util.createJar(new String[] {
8894 					"org/apache/xerces/parsers/SAXParser.java",
8895 					"package org.apache.xerces.parsers;\n" +
8896 					"public abstract class SAXParser implements org.xml.sax.Parser, java.io.Serializable {}\n"
8897 				},
8898 				project.getProject().getLocation().toString() + "/lib/xercesImpl.jar",
8899 				"1.8");
8900 			project.getProject().refreshLocal(IResource.DEPTH_INFINITE, null);
8901 			libraryEntry = JavaCore.newLibraryEntry(new Path("/ztest/lib/xercesImpl.jar"), null, null);
8902 			addClasspathEntry(project, libraryEntry, 1); // right after src and before jrt-fs.jar
8903 
8904 			String testSource =
8905 					"package com.ztest;\n" +
8906 					"import org.apache.xerces.parsers.SAXParser;\n" +
8907 					"\n" +
8908 					"public class MySAXParser extends SAXParser {\n" +
8909 					"	static final long serialVersionUID = 0;\n" +
8910 					"}\n";
8911 			createFolder("/ztest/src/com/ztest");
8912 			createFile("/ztest/src/com/ztest/MySAXParser.java", testSource);
8913 			getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, null);
8914 			IMarker[] markers = project.getProject().findMarkers(null, true, IResource.DEPTH_INFINITE);
8915 			sortMarkers(markers);
8916 			assertMarkers("Unexpected Markers",
8917 					"",
8918 					markers);
8919 
8920 			char[] sourceChars = testSource.toCharArray();
8921 			this.problemRequestor.initialize(sourceChars);
8922 			getCompilationUnit("/ztest/src/com/ztest/MySAXParser.java").getWorkingCopy(this.wcOwner, null);
8923 			assertProblems(
8924 					"Unexpected problems",
8925 					"----------\n" +
8926 					"----------\n",
8927 					this.problemRequestor);
8928 
8929 		} finally {
8930 			deleteProject("ztest");
8931 		}
8932 	}
assertNoErrors()8933 	protected void assertNoErrors() throws CoreException {
8934 		for (IProject p : getWorkspace().getRoot().getProjects()) {
8935 			int maxSeverity = p.findMaxProblemSeverity(null, true, IResource.DEPTH_INFINITE);
8936 			if (maxSeverity == IMarker.SEVERITY_ERROR) {
8937 				for (IMarker marker : p.findMarkers(null, true, IResource.DEPTH_INFINITE))
8938 					System.err.println("Marker "+ marker.toString());
8939 			}
8940 			assertFalse("Unexpected errors in project " + p.getName(), maxSeverity == IMarker.SEVERITY_ERROR);
8941 		}
8942 	}
8943 	// sort by CHAR_START then MESSAGE
8944 	@Override
sortMarkers(IMarker[] markers)8945 	protected void sortMarkers(IMarker[] markers) {
8946 		Arrays.sort(markers, Comparator.comparingInt((IMarker a) -> a.getAttribute(IMarker.CHAR_START, 0))
8947 									   .thenComparing((IMarker a) -> a.getAttribute(IMarker.MESSAGE, "")));
8948 	}
8949 }
8950