From ef0329ec086fb5e9a373140acb0d40bd8ddf2d1c Mon Sep 17 00:00:00 2001 From: Jay Arthanareeswaran Date: Sun, 18 Aug 2019 22:29:27 +0530 Subject: Bug 550178 - NPE when an invalid package is exported or opened Change-Id: Ia3014a954d02789deafa5ccf2219bb18e642a5d6 Signed-off-by: Jay Arthanareeswaran --- .../regression/ModuleCompilationTests.java | 34 ++++++++++++++++++++++ .../compiler/batch/ClasspathDirectory.java | 5 +++- 2 files changed, 38 insertions(+), 1 deletion(-) 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 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 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$ -- cgit v1.2.3