diff options
3 files changed, 131 insertions, 11 deletions
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ReconcilerTests9.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ReconcilerTests9.java index d92f13fd2e..4627f89ea4 100644 --- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ReconcilerTests9.java +++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ReconcilerTests9.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2019 IBM Corporation and others. + * Copyright (c) 2000, 2020 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -55,7 +55,7 @@ public ReconcilerTests9(String name) { static { // JavaModelManager.VERBOSE = true; // TESTS_PREFIX = "testAnnotations"; -// TESTS_NAMES = new String[] { "testAnnotations2" }; +// TESTS_NAMES = new String[] { "testBug564289_001" }; // TESTS_NUMBERS = new int[] { 118823 }; // TESTS_RANGE = new int[] { 16, -1 }; } @@ -950,4 +950,78 @@ public void testBug547113() throws CoreException { deleteProject(c); } } +public void testBug564289_001() throws Exception { + if (!isJRE9) + return; + IJavaProject p = null; + String outputDirectory = Util.getOutputDirectory(); + try { + String lib1path = "externalLib/foo.jar"; + Util.createJar( + new String[] { + "net/openhft/chronicle/core/io/IORuntimeException.java", + "package net.openhft.chronicle.core.io;\n" + + "public class IORuntimeException extends java.lang.RuntimeException {\n" + + " private static final long serialVersionUID = 1L;\n" + + " public IORuntimeException(java.lang.String message) {}\n" + + "}", + "net/openhft/chronicle/bytes/ReadBytesMarshallable.java", + "package net.openhft.chronicle.bytes;\n" + + "public abstract interface ReadBytesMarshallable {\n" + + " public abstract void readMarshallable() throws net.openhft.chronicle.core.io.IORuntimeException;\n" + + "}", + "net/openhft/chronicle/bytes/BytesMarshallable.java", + "package net.openhft.chronicle.bytes;\n" + + "public abstract interface BytesMarshallable extends net.openhft.chronicle.bytes.ReadBytesMarshallable {\n" + + " public default void readMarshallable() throws net.openhft.chronicle.core.io.IORuntimeException {\n" + + " }\n" + + "}", + "java/lang/Sri420.java", + "package java.lang;\n" + + "public class Sri420 {\n" + + "}", + }, + null, + getExternalResourcePath(lib1path), + JavaCore.VERSION_1_8); + + p = createJava9Project("p", "11"); + addLibraryEntry(p, new Path(getExternalResourcePath(lib1path)), null, null, null, null, null, false); + + createFolder("p/src/X"); + createFile("p/src/X.java", + "import net.openhft.chronicle.bytes.BytesMarshallable; \n" + + "/** */\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " System.out.println(\"BytesMarshallable: \" + new BytesMarshallable() {});\n" + + " } \n" + + "}\n"); + p.getProject().build(IncrementalProjectBuilder.INCREMENTAL_BUILD, null); + waitForAutoBuild(); + IMarker[] markers = p.getProject().findMarkers(null, true, IResource.DEPTH_INFINITE); + assertMarkers("Unexpected markers", "The package java.lang.String conflicts with a package accessible from another module: <unnamed>", markers); + + this.workingCopy.discardWorkingCopy(); + this.workingCopy = getCompilationUnit("p/src/X.java").getWorkingCopy(this.wcOwner, null); + this.problemRequestor.initialize(this.workingCopy.getSource().toCharArray()); + this.workingCopy.reconcile(JLS_LATEST, true, this.wcOwner, null); + String expected = "----------\n" + + "1. ERROR in /p/src/X.java (at line 1)\n" + + " import net.openhft.chronicle.bytes.BytesMarshallable; \n" + + " ^\n" + + "The package java.lang.String conflicts with a package accessible from another module: <unnamed>\n" + + "----------\n"; + assertProblems("Expecting problems",expected, this.problemRequestor); + + markers = p.getProject().findMarkers(null, true, IResource.DEPTH_INFINITE); + assertMarkers("Unexpected markers", "The package java.lang.String conflicts with a package accessible from another module: <unnamed>", markers); + } finally { + deleteExternalResource("externalLib"); + deleteProject(p); + File outputDir = new File(outputDirectory); + if (outputDir.exists()) + Util.flushDirectoryContent(outputDir); + } +} } diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/LookupEnvironment.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/LookupEnvironment.java index 564f75d56e..ffbb3b5aea 100644 --- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/LookupEnvironment.java +++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/LookupEnvironment.java @@ -1479,6 +1479,34 @@ public ReferenceBinding getCachedType(char[][] compoundName) { } return result; } +private boolean flaggedJavaBaseTypeErrors(ReferenceBinding result, char[][] compoundName) { + assert result != null && !result.isValidBinding(); + if (CharOperation.equals(TypeConstants.JAVA, compoundName[0])) { + ReferenceBinding type = getType(compoundName, javaBaseModule()); + if (type != null && type.isValidBinding()) { + PackageBinding pack = type.getPackage(); + char[] readableName = pack != null ? pack.readableName() : null; + if (readableName != null) { + // 7.4.3 : The packages java, java.lang, and java.io are always observable. + if (CharOperation.equals(readableName, TypeConstants.JAVA) + || CharOperation.equals(readableName, CharOperation.concatWith(TypeConstants.JAVA_LANG, '.')) + || CharOperation.equals(readableName, CharOperation.concatWith(TypeConstants.JAVA_IO, '.'))) { + PackageBinding currentPack = getTopLevelPackage(readableName); + ModuleBinding visibleModule = currentPack != null ? currentPack.enclosingModule : null; + if (visibleModule != null && visibleModule != javaBaseModule()) { + // A type from java.base is not visible + if (!this.globalOptions.enableJdtDebugCompileMode) { + this.problemReporter.isClassPathCorrect(compoundName, this.root.unitBeingCompleted, this.missingClassFileLocation, visibleModule.readableName()); + return true; + } + } + } + } + } + } + return false; +} + public ReferenceBinding getCachedType0(char[][] compoundName) { if (compoundName.length == 1) { return this.defaultPackage.getType0(compoundName[0]); @@ -1754,7 +1782,7 @@ private ReferenceBinding getTypeFromCompoundName(char[][] compoundName, boolean } if (binding == TheNotFoundType) { // report the missing class file first - if (!wasMissingType) { + if (!wasMissingType && !flaggedJavaBaseTypeErrors(binding, compoundName)) { /* Since missing types have been already been complained against while producing binaries, there is no class path * misconfiguration now that did not also exist in some equivalent form while producing the class files which encode * these missing types. So no need to bark again. Note that wasMissingType == true signals a type referenced in a .class diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java index b0acb468cb..ed00cd8ea2 100644 --- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java +++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java @@ -5045,13 +5045,13 @@ public void illegalTypeAnnotationsInStaticMemberAccess(Annotation first, Annotat first.sourceStart, last.sourceEnd); } -public void isClassPathCorrect(char[][] wellKnownTypeName, CompilationUnitDeclaration compUnitDecl, Object location, boolean implicitAnnotationUse) { +public void isClassPathCorrect(char[][] wellKnownTypeName, CompilationUnitDeclaration compUnitDecl, Object location, boolean implicitAnnotationUse, + char[] visibleModuleName) { // ProblemReporter is not designed to be reentrant. Just in case, we discovered a build path problem while we are already // in the midst of reporting some other problem, save and restore reference context thereby mimicking a stack. // See https://bugs.eclipse.org/bugs/show_bug.cgi?id=442755. ReferenceContext savedContext = this.referenceContext; this.referenceContext = compUnitDecl; - String[] arguments = new String[] {CharOperation.toString(wellKnownTypeName)}; int start = 0, end = 0; if (location != null) { if (location instanceof InvocationSite) { @@ -5065,16 +5065,34 @@ public void isClassPathCorrect(char[][] wellKnownTypeName, CompilationUnitDeclar } } try { - this.handle( - implicitAnnotationUse ? IProblem.MissingNullAnnotationImplicitlyUsed : IProblem.IsClassPathCorrect, - arguments, - arguments, - start, - end); + if (visibleModuleName == null) { + String[] arguments = new String[] {CharOperation.toString(wellKnownTypeName)}; + this.handle( + implicitAnnotationUse ? IProblem.MissingNullAnnotationImplicitlyUsed : IProblem.IsClassPathCorrect, + arguments, + arguments, + start, + end); + } else { + String[] arguments = new String[] {CharOperation.toString(wellKnownTypeName), new String(visibleModuleName)}; + this.handle( + IProblem.ConflictingPackageFromOtherModules, + arguments, + arguments, + start, + end); + } } finally { this.referenceContext = savedContext; } } +public void isClassPathCorrect(char[][] wellKnownTypeName, CompilationUnitDeclaration compUnitDecl, Object location, char[] visibleModuleName) { + assert visibleModuleName != null; + isClassPathCorrect(wellKnownTypeName, compUnitDecl, location, false /* donot care */, visibleModuleName); +} +public void isClassPathCorrect(char[][] wellKnownTypeName, CompilationUnitDeclaration compUnitDecl, Object location, boolean implicitAnnotationUse) { + isClassPathCorrect(wellKnownTypeName, compUnitDecl, location, implicitAnnotationUse, null); +} private boolean isIdentifier(int token) { return token == TerminalTokens.TokenNameIdentifier; } |