Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/CompilerInvocationTests.java2
-rw-r--r--org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ModuleBuilderTests.java93
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/core/compiler/IProblem.java2
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/LookupEnvironment.java3
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/ModuleBinding.java8
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java5
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/messages.properties1
-rw-r--r--org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/AbstractImageBuilder.java15
-rw-r--r--org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/util/Messages.java1
-rw-r--r--org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/util/messages.properties1
10 files changed, 120 insertions, 11 deletions
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/CompilerInvocationTests.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/CompilerInvocationTests.java
index 355791bf2b..671b104925 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/CompilerInvocationTests.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/CompilerInvocationTests.java
@@ -1041,6 +1041,7 @@ public void test011_problem_categories() {
expectedProblemAttributes.put("UndefinedLabel", new ProblemAttributes(CategorizedProblem.CAT_INTERNAL));
expectedProblemAttributes.put("UndefinedMethod", new ProblemAttributes(CategorizedProblem.CAT_MEMBER));
expectedProblemAttributes.put("UndefinedModule", new ProblemAttributes(CategorizedProblem.CAT_MODULE));
+ expectedProblemAttributes.put("UndefinedModuleAddReads", new ProblemAttributes(CategorizedProblem.CAT_BUILDPATH));
expectedProblemAttributes.put("UndefinedName", new ProblemAttributes(CategorizedProblem.CAT_MEMBER));
expectedProblemAttributes.put("UndefinedType", new ProblemAttributes(CategorizedProblem.CAT_TYPE));
expectedProblemAttributes.put("UndefinedTypeVariable", new ProblemAttributes(CategorizedProblem.CAT_INTERNAL));
@@ -1987,6 +1988,7 @@ public void test012_compiler_problems_tuning() {
expectedProblemAttributes.put("UndefinedLabel", SKIP);
expectedProblemAttributes.put("UndefinedMethod", SKIP);
expectedProblemAttributes.put("UndefinedModule", SKIP);
+ expectedProblemAttributes.put("UndefinedModuleAddReads", SKIP);
expectedProblemAttributes.put("UndefinedName", SKIP);
expectedProblemAttributes.put("UndefinedType", SKIP);
expectedProblemAttributes.put("UndefinedTypeVariable", SKIP);
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 967662fa78..69256ef59c 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
@@ -28,6 +28,7 @@ import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IWorkspaceDescription;
import org.eclipse.core.resources.IncrementalProjectBuilder;
+import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
@@ -8490,6 +8491,98 @@ public class ModuleBuilderTests extends ModifyingResourceTests {
Util.flushDirectoryContent(outputDir);
}
}
+ public void testBug547114a() throws CoreException, IOException {
+ String outputDirectory = Util.getOutputDirectory();
+ String jarPath = outputDirectory + File.separator + "lib.jar";
+ try {
+ // focus project has no module-info, to trigger path where LE#knownPackages is not empty when processing add-reads
+ String[] sources = new String[] {
+ "src/org/astro/World.java",
+ "package org.astro;\n" +
+ "import p.C;\n" +
+ "public class World {\n" +
+ " C f;\n" +
+ "}\n"
+ };
+ IJavaProject p = setupModuleProject("org.astro", sources);
+
+ Util.createJar(new String[] {
+ "/lib/src/module-info.java",
+ "module lib {\n" +
+ " exports p;\n" +
+ "}\n",
+ "/lib/src/p/C.java",
+ "package p;\n" +
+ "public class C {}\n",
+ },
+ jarPath,
+ "9");
+ addClasspathEntry(p, JavaCore.newLibraryEntry(new Path(jarPath), null, null, null,
+ new IClasspathAttribute[] {
+ JavaCore.newClasspathAttribute(IClasspathAttribute.MODULE, "true"),
+ JavaCore.newClasspathAttribute(IClasspathAttribute.ADD_READS, "lib=missing.module") // problematic directive on jar-dependency
+ },
+ false));
+
+ p.getProject().build(IncrementalProjectBuilder.INCREMENTAL_BUILD, null);
+ waitForAutoBuild();
+
+ IMarker[] markers = p.getProject().findMarkers(null, true, IResource.DEPTH_INFINITE);
+ // 1. marker is on the project, second on the "current" CU: World.java.
+ assertMarkers("Unexpected markers",
+ "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" +
+ "missing.module cannot be resolved to a module, it is referenced from an add-reads directive",
+ markers);
+ } finally {
+ deleteProject("org.astro");
+ deleteFile(jarPath);
+ }
+ }
+ public void testBug547114b() throws CoreException, IOException {
+ try {
+ IJavaProject p = setupModuleProject("org.astro", new String[] {
+ "src/module-info.java",
+ "module org.astro {\n" +
+ " requires lib;\n" +
+ "}\n",
+ "src/org/astro/World.java",
+ "package org.astro;\n" +
+ "import p.C;\n" +
+ "public class World {\n" +
+ " C f;\n" +
+ "}\n"
+ });
+
+ IJavaProject lib = setupModuleProject("lib", new String[] {
+ "src/module-info.java",
+ "module lib {\n" +
+ " exports p;\n" +
+ "}\n",
+ "src/p/C.java",
+ "package p;\n" +
+ "public class C {}\n",
+ });
+ addClasspathEntry(p, JavaCore.newProjectEntry(lib.getPath(), null, false,
+ new IClasspathAttribute[] {
+ JavaCore.newClasspathAttribute(IClasspathAttribute.MODULE, "true"),
+ JavaCore.newClasspathAttribute(IClasspathAttribute.ADD_READS, "lib=missing.module") // problematic directive on project dependency
+ },
+ false));
+
+ ResourcesPlugin.getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, null);
+ waitForAutoBuild();
+
+ IMarker[] markers = p.getProject().findMarkers(null, true, IResource.DEPTH_INFINITE);
+ // 1. marker is on the project, second on the "current" CU: World.java.
+ assertMarkers("Unexpected markers",
+ "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" +
+ "missing.module cannot be resolved to a module, it is referenced from an add-reads directive",
+ markers);
+ } finally {
+ deleteProject("org.astro");
+ deleteProject("lib");
+ }
+ }
protected void assertNoErrors() throws CoreException {
for (IProject p : getWorkspace().getRoot().getProjects()) {
int maxSeverity = p.findMaxProblemSeverity(null, true, IResource.DEPTH_INFINITE);
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/core/compiler/IProblem.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/core/compiler/IProblem.java
index f79bbdce1e..c7b59bd6da 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/core/compiler/IProblem.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/core/compiler/IProblem.java
@@ -1951,6 +1951,8 @@ void setSourceStart(int sourceStart);
int InvalidServiceImplType = ModuleRelated + 1317;
/** @since 3.14 */
int IllegalModifierForModule = ModuleRelated + 1318;
+ /** @since 3.18 */
+ int UndefinedModuleAddReads = ModuleRelated + 1319;
/** @since 3.14 */
int DuplicateResource = Internal + 1251;
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 11b6f4fe15..bf84ff6884 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
@@ -1572,8 +1572,7 @@ private void initializeUsesNullTypeAnnotation() {
this.mayTolerateMissingType = true;
try {
nullable = this.nullableAnnotation != null ? this.nullableAnnotation.getAnnotationType()
- : getType(this.getNullableAnnotationName(), this.UnNamedModule); // FIXME(SHMOD) module for null
- // annotations??
+ : getType(this.getNullableAnnotationName(), this.UnNamedModule); // FIXME(SHMOD) module for null annotations??
nonNull = this.nonNullAnnotation != null ? this.nonNullAnnotation.getAnnotationType()
: getType(this.getNonNullAnnotationName(), this.UnNamedModule);
} finally {
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/ModuleBinding.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/ModuleBinding.java
index 953bcebc3a..642fe17b1a 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/ModuleBinding.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/ModuleBinding.java
@@ -254,7 +254,8 @@ public class ModuleBinding extends Binding implements IUpdatableModule {
this.requires[len] = requiredModule;
}
} else {
- // TODO(SHMOD) report error
+ this.environment.problemReporter.missingModuleAddReads(requiredModuleName);
+ return;
}
// update known packages:
HashtableOfPackage knownPackages = this.environment.knownPackages;
@@ -308,7 +309,7 @@ public class ModuleBinding extends Binding implements IUpdatableModule {
public void addResolvedExport(PackageBinding declaredPackage, char[][] targetModules) {
int len = this.exportedPackages.length;
if (declaredPackage == null || !declaredPackage.isValidBinding()) {
- // FIXME(SHMOD) use a problem binding? See https://bugs.eclipse.org/518794#c13
+ // TODO(SHMOD) use a problem binding (if needed by DOM clients)? See https://bugs.eclipse.org/518794#c13
return;
}
if (len == 0) {
@@ -324,7 +325,7 @@ public class ModuleBinding extends Binding implements IUpdatableModule {
public void addResolvedOpens(PackageBinding declaredPackage, char[][] targetModules) {
int len = this.openedPackages.length;
if (declaredPackage == null || !declaredPackage.isValidBinding()) {
- // FIXME(SHMOD) use a problem binding? See https://bugs.eclipse.org/518794#c13
+ // TODO(SHMOD) use a problem binding (if needed by DOM clients)? See https://bugs.eclipse.org/518794#c13
return;
}
if (len == 0) {
@@ -426,7 +427,6 @@ public class ModuleBinding extends Binding implements IUpdatableModule {
Collection<ModuleBinding> allRequires = dependencyCollector().get();
if (allRequires.contains(this)) {
- // TODO(SHMOD): report (when? where?)
return NO_MODULES; // avoid entering unbounded recursion due to cyclic requires
}
ModuleBinding javaBase = this.environment.javaBaseModule();
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 2d627e1209..40eca8656d 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
@@ -795,6 +795,7 @@ public static int getProblemCategory(int severity, int problemID) {
switch (problemID) {
case IProblem.IsClassPathCorrect :
case IProblem.CorruptedSignature :
+ case IProblem.UndefinedModuleAddReads :
return CategorizedProblem.CAT_BUILDPATH;
case IProblem.ProblemNotAnalysed :
return CategorizedProblem.CAT_UNNECESSARY_CODE;
@@ -10931,6 +10932,10 @@ public void invalidModule(ModuleReference ref) {
NoArgument, new String[] { CharOperation.charToString(ref.moduleName) },
ref.sourceStart, ref.sourceEnd);
}
+public void missingModuleAddReads(char[] requiredModuleName) {
+ String[] args = new String[] { new String(requiredModuleName) };
+ this.handle(IProblem.UndefinedModuleAddReads, args, args, 0, 0);
+}
public void invalidOpensStatement(OpensStatement statement, ModuleDeclaration module) {
this.handle(IProblem.InvalidOpensStatement,
NoArgument, new String[] { CharOperation.charToString(module.moduleName) },
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/messages.properties b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/messages.properties
index 83166a776e..0f079fa529 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/messages.properties
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/messages.properties
@@ -909,6 +909,7 @@
1316 = Invalid service interface {0}, must be a class, interface or annotation type
1317 = Invalid service implementation {0}, must be a public class or interface type
1318 = Illegal modifier for module {0}; only open is permitted
+1319 = {0} cannot be resolved to a module, it is referenced from an add-reads directive
#### Java 9
1351 = Variable resource not allowed here for source level below 9
diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/AbstractImageBuilder.java b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/AbstractImageBuilder.java
index 704ee85a3b..abd540201d 100644
--- a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/AbstractImageBuilder.java
+++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/AbstractImageBuilder.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2018 IBM Corporation and others.
+ * Copyright (c) 2000, 2019 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -697,11 +697,16 @@ protected void storeProblemsFor(SourceFile sourceFile, CategorizedProblem[] prob
// but at the start of the next problem we should reset it to the source file's resource
IResource resource = sourceFile.resource;
- // handle missing classfile situation
+ // handle buildpath problems (missing classfile, unresolved add-reads...)
+ String buildPathProblemMessage = null;
if (id == IProblem.IsClassPathCorrect) {
- String missingClassfileName = problem.getArguments()[0];
+ buildPathProblemMessage = Messages.bind(Messages.build_incompleteClassPath, problem.getArguments()[0]);
+ } else if (id == IProblem.UndefinedModuleAddReads) {
+ buildPathProblemMessage = Messages.bind(Messages.build_errorOnModuleDirective, problem.getMessage());
+ }
+ if (buildPathProblemMessage != null) {
if (JavaBuilder.DEBUG)
- System.out.println(Messages.bind(Messages.build_incompleteClassPath, missingClassfileName));
+ System.out.println(buildPathProblemMessage);
boolean isInvalidClasspathError = JavaCore.ERROR.equals(this.javaBuilder.javaProject.getOption(JavaCore.CORE_INCOMPLETE_CLASSPATH, true));
// insert extra classpath problem, and make it the only problem for this project (optional)
if (isInvalidClasspathError && JavaCore.ABORT.equals(this.javaBuilder.javaProject.getOption(JavaCore.CORE_JAVA_BUILD_INVALID_CLASSPATH, true))) {
@@ -712,7 +717,7 @@ protected void storeProblemsFor(SourceFile sourceFile, CategorizedProblem[] prob
marker.setAttributes(
new String[] {IMarker.MESSAGE, IMarker.SEVERITY, IJavaModelMarker.CATEGORY_ID, IMarker.SOURCE_ID},
new Object[] {
- Messages.bind(Messages.build_incompleteClassPath, missingClassfileName),
+ buildPathProblemMessage,
Integer.valueOf(isInvalidClasspathError ? IMarker.SEVERITY_ERROR : IMarker.SEVERITY_WARNING),
Integer.valueOf(CategorizedProblem.CAT_BUILDPATH),
JavaBuilder.SOURCE_ID
diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/util/Messages.java b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/util/Messages.java
index f1fe4d648a..a75bd65ad2 100644
--- a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/util/Messages.java
+++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/util/Messages.java
@@ -111,6 +111,7 @@ public final class Messages extends NLS {
public static String build_inconsistentClassFile;
public static String build_inconsistentProject;
public static String build_incompleteClassPath;
+ public static String build_errorOnModuleDirective;
public static String build_missingSourceFile;
public static String build_prereqProjectHasClasspathProblems;
public static String build_prereqProjectMustBeRebuilt;
diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/util/messages.properties b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/util/messages.properties
index 305dbb8237..ec02740544 100644
--- a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/util/messages.properties
+++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/util/messages.properties
@@ -103,6 +103,7 @@ build_duplicateResource = The resource is a duplicate of {0} and was not copied
build_inconsistentClassFile = A class file was not written. The project may be inconsistent, if so try refreshing this project and building it
build_inconsistentProject = The project was not built due to "{0}". Fix the problem, then try refreshing this project and building it since it may be inconsistent
build_incompleteClassPath = The project was not built since its build path is incomplete. Cannot find the class file for {0}. Fix the build path then try building this project
+build_errorOnModuleDirective = The project was not built since its build path has a problem: {0}. Fix the build path then try building this project
build_missingSourceFile = The project was not built since the source file {0} could not be read
build_prereqProjectHasClasspathProblems = The project was not built since it depends on {0}, which has build path errors
build_prereqProjectMustBeRebuilt = The project cannot be built until its prerequisite {0} is built. Cleaning and building all projects is recommended

Back to the top