diff options
author | Stephan Herrmann | 2018-11-15 23:55:17 +0000 |
---|---|---|
committer | Stephan Herrmann | 2018-11-17 20:47:26 +0000 |
commit | bcd6c4d80d66085378212b006e60707c11391c1a (patch) | |
tree | 95cd480859b09a10a53ed078c6d325467f871041 | |
parent | 8ff9ccc5ce46767cc19538a21f925e5e217e35d6 (diff) | |
download | eclipse.jdt.core-bcd6c4d80d66085378212b006e60707c11391c1a.tar.gz eclipse.jdt.core-bcd6c4d80d66085378212b006e60707c11391c1a.tar.xz eclipse.jdt.core-bcd6c4d80d66085378212b006e60707c11391c1a.zip |
Bug 539749 - [test] rewrite tests that use a JDK module removed in 11I20181119-2315I20181119-1800I20181119-0600I20181118-1800I20181118-0600I20181117-1800
- one out of three tests
- includes minimal fix for JME due to using a JrtPFR from a closed Prj
Change-Id: I73e6a4980d9990eccd3762b037657bf101b93d83
-rw-r--r-- | org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ModuleBuilderTests.java | 102 | ||||
-rw-r--r-- | org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/ClassFile.java | 9 |
2 files changed, 106 insertions, 5 deletions
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ModuleBuilderTests.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ModuleBuilderTests.java index 63276624ab..3c7e20fc36 100644 --- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ModuleBuilderTests.java +++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ModuleBuilderTests.java @@ -6290,21 +6290,28 @@ public class ModuleBuilderTests extends ModifyingResourceTests { if (!isJRE9) return; ClasspathJrt.resetCaches(); try { - IJavaProject javaProject = createJava9Project("mod1", new String[] {"src"}); + // jdk.rmic is not be visible to code in an unnamed module, but using requires we can see the module. + // only, there's nothing exported from it (which is why JEP 261 hides it from unnamed), so we --add-reads: + IClasspathAttribute[] attrs = new IClasspathAttribute[] { + JavaCore.newClasspathAttribute(IClasspathAttribute.ADD_EXPORTS, "jdk.rmic/sun.rmi.rmic=mod1") + }; + IJavaProject javaProject = createJava9ProjectWithJREAttributes("mod1", new String[] {"src"}, attrs); String srcMod = - "@SuppressWarnings(\"removal\")\n" + // javax.xml.ws.annotation is deprecated for removal "module mod1 {\n" + " exports com.mod1.pack1;\n" + - " requires java.xml.ws.annotation;\n" + + " requires jdk.rmic;\n" + "}"; createFile("/mod1/src/module-info.java", srcMod); createFolder("/mod1/src/com/mod1/pack1"); String srcX = "package com.mod1.pack1;\n" + - "@javax.annotation.Generated(\"com.acme.generator.CodeGen\")\n" + + "import sun.rmi.rmic.Main;\n" + "public class Dummy {\n" + + " String test() {\n" + + " return Main.getString(\"in\");\n" + + " }\n" + "}"; createFile("/mod1/src/com/mod1/pack1/Dummy.java", srcX); @@ -6329,6 +6336,92 @@ public class ModuleBuilderTests extends ModifyingResourceTests { } } + public void testBug526054b() throws Exception { + if (!isJRE9) return; + ClasspathJrt.resetCaches(); + try { + // one project can see jdk.rmic/sun.rmi.rmic + IClasspathAttribute[] attrs = new IClasspathAttribute[] { + JavaCore.newClasspathAttribute(IClasspathAttribute.ADD_EXPORTS, "jdk.rmic/sun.rmi.rmic=mod1") + }; + createJava9ProjectWithJREAttributes("mod1", new String[] {"src"}, attrs); + + String srcMod1 = + "module mod1 {\n" + + " exports com.mod1.pack1;\n" + + " requires jdk.rmic;\n" + + "}"; + createFile("/mod1/src/module-info.java", + srcMod1); + createFolder("/mod1/src/com/mod1/pack1"); + String srcX1 = + "package com.mod1.pack1;\n" + + "import sun.rmi.rmic.Constants;\n" + // this should never be complained against due to above add-exports. + "public class Dummy implements Constants {\n" + + "}"; + createFile("/mod1/src/com/mod1/pack1/Dummy.java", srcX1); + + // second project cannot see jdk.rmic/sun.rmi.rmic: + createJava9Project("mod2", new String[] {"src"}); + + String srcMod2 = + "module mod2 {\n" + + " exports com.mod2.pack1;\n" + + " requires jdk.rmic;\n" + + "}"; + createFile("/mod2/src/module-info.java", + srcMod2); + createFolder("/mod2/src/com/mod2/pack1"); + String srcX2 = + "package com.mod2.pack1;\n" + + "import sun.rmi.rmic.Main;\n" + + "public class Dummy {\n" + + " String test() {\n" + + " return Main.getString(\"in\");\n" + + " }\n" + + "}"; + createFile("/mod2/src/com/mod2/pack1/Dummy.java", srcX2); + + // check first: + this.problemRequestor.initialize(srcX1.toCharArray()); + getWorkingCopy("/mod1/src/com/mod1/pack1/Dummy.java", srcX1, true); + assertProblems("Dummy in mod1 should have no problems", + "----------\n" + + "----------\n", + this.problemRequestor); + + // check second: + this.problemRequestor.initialize(srcX2.toCharArray()); + getWorkingCopy("/mod2/src/com/mod2/pack1/Dummy.java", srcX2, true); + assertProblems("Dummy in mod2 should have problems", + "----------\n" + + "1. ERROR in /mod2/src/com/mod2/pack1/Dummy.java (at line 2)\n" + + " import sun.rmi.rmic.Main;\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "The type sun.rmi.rmic.Main is not accessible\n" + + "----------\n" + + "2. ERROR in /mod2/src/com/mod2/pack1/Dummy.java (at line 5)\n" + + " return Main.getString(\"in\");\n" + + " ^^^^\n" + + "Main cannot be resolved\n" + + "----------\n", + this.problemRequestor); + + // check both in a combined build + getWorkspace().build(IncrementalProjectBuilder.CLEAN_BUILD, null); + getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, null); + IMarker[] markers = getWorkspace().getRoot().findMarkers(null, true, IResource.DEPTH_INFINITE); + sortMarkers(markers); + assertMarkers("Unexpected markers", + "The type sun.rmi.rmic.Main is not accessible\n" + + "Main cannot be resolved", + markers); + } finally { + deleteProject("mod1"); + deleteProject("mod2"); + } + } + public void testBug525918() throws CoreException { if (!isJRE9) return; try { @@ -7187,6 +7280,7 @@ public class ModuleBuilderTests extends ModifyingResourceTests { getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, null); IMarker[] markers = unnamed.getProject().findMarkers(null, true, IResource.DEPTH_INFINITE); + sortMarkers(markers); assertMarkers("Unexpected markers", "The import org.p1.T1 cannot be resolved\n" + "T1 cannot be resolved to a type", diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/ClassFile.java b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/ClassFile.java index 6dff56a3ee..c8dbd47dd9 100644 --- a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/ClassFile.java +++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/ClassFile.java @@ -246,7 +246,14 @@ private IBinaryType getJarBinaryTypeInfo() throws CoreException, IOException, Cl // TODO(sxenos): setup the external annotation provider if the IBinaryType came from the index if (root.getKind() == IPackageFragmentRoot.K_BINARY) { JavaProject javaProject = (JavaProject) getAncestor(IJavaElement.JAVA_PROJECT); - IClasspathEntry entry = javaProject.getClasspathEntryFor(getPath()); + IClasspathEntry entry; + try { + entry = javaProject.getClasspathEntryFor(getPath()); + } catch (JavaModelException jme) { + // Access via cached ClassFile/PF/PFR of a closed project? + // Ignore and continue with result undecorated + return result; + } if (entry != null) { PackageFragment pkg = (PackageFragment) getParent(); String entryName = Util.concatWith(pkg.names, getElementName(), '/'); |