Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJay Arthanareeswaran2019-08-18 16:59:27 +0000
committerJay Arthanareeswaran2019-08-19 02:55:35 +0000
commitef0329ec086fb5e9a373140acb0d40bd8ddf2d1c (patch)
tree38eff64603ab071e314500697fa1b44934a1d64b
parentb7cb75ad308cdfd0a16f029d800d9cc0a3c5246e (diff)
downloadeclipse.jdt.core-ef0329ec086fb5e9a373140acb0d40bd8ddf2d1c.tar.gz
eclipse.jdt.core-ef0329ec086fb5e9a373140acb0d40bd8ddf2d1c.tar.xz
eclipse.jdt.core-ef0329ec086fb5e9a373140acb0d40bd8ddf2d1c.zip
Bug 550178 - NPE when an invalid package is exported or opened
Change-Id: Ia3014a954d02789deafa5ccf2219bb18e642a5d6 Signed-off-by: Jay Arthanareeswaran <jarthana@in.ibm.com>
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ModuleCompilationTests.java34
-rw-r--r--org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/ClasspathDirectory.java5
2 files changed, 38 insertions, 1 deletions
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ModuleCompilationTests.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ModuleCompilationTests.java
index b69c75b599..d952bab1cb 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ModuleCompilationTests.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ModuleCompilationTests.java
@@ -5443,4 +5443,38 @@ public void testBug521362_emptyFile() {
false,
"package p1.p2.t3 clashes with class of same name");
}
+ public void testBug550178() throws Exception {
+ Util.flushDirectoryContent(new File(OUTPUT_DIR));
+ String outDir = OUTPUT_DIR + File.separator + "bin";
+ String srcDir = OUTPUT_DIR + File.separator + "src";
+ File modDir = new File(OUTPUT_DIR + File.separator + "mod");
+ createReusableModules(srcDir, outDir, modDir);
+ String moduleLoc = srcDir + File.separator + "mod.three";
+ List<String> files = new ArrayList<>();
+ writeFileCollecting(files, moduleLoc, "module-info.java",
+ "module mod.three { \n" +
+ " exports pkg.invalid;\n" +
+ "}");
+
+
+ StringBuffer buffer = new StringBuffer();
+ buffer.append("-d " + outDir )
+ .append(" -9 ")
+ .append(" --module-path \"")
+ .append(Util.getJavaClassLibsAsString())
+ .append(modDir.getAbsolutePath())
+ .append("\" ")
+ .append(" --module-source-path " + "\"" + srcDir + "\" ");
+ runNegativeModuleTest(files, buffer,
+ "",
+ "----------\n" +
+ "1. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/src/mod.three/module-info.java (at line 2)\n" +
+ " exports pkg.invalid;\n" +
+ " ^^^^^^^^^^^\n" +
+ "The package pkg.invalid does not exist or is empty\n" +
+ "----------\n" +
+ "1 problem (1 error)\n",
+ false,
+ "");
+ }
}
diff --git a/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/ClasspathDirectory.java b/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/ClasspathDirectory.java
index 0f05fbd865..b59f9fc4bf 100644
--- a/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/ClasspathDirectory.java
+++ b/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/ClasspathDirectory.java
@@ -318,7 +318,10 @@ public boolean hasCompilationUnit(String qualifiedPackageName, String moduleName
@Override
public boolean hasCUDeclaringPackage(String qualifiedPackageName, Function<CompilationUnit, String> pkgNameExtractor) {
String qp2 = File.separatorChar == '/' ? qualifiedPackageName : qualifiedPackageName.replace('/', File.separatorChar);
- return Stream.of(directoryList(qp2)).anyMatch(entry -> {
+ String[] directoryList = directoryList(qp2);
+ if(directoryList == null)
+ return false;
+ return Stream.of(directoryList).anyMatch(entry -> {
String entryLC = entry.toLowerCase();
boolean hasDeclaration = false;
String fullPath = this.path + qp2 + "/" + entry; //$NON-NLS-1$

Back to the top