changeset 43771:25ddac537bb5

8174104: Compiler does not allow non-existent module path entry Reviewed-by: jlahoda
author jjg
date Fri, 10 Feb 2017 15:42:17 -0800
parents a321bed02000
children 4e5350b7be75
files langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/file/Locations.java langtools/test/tools/javac/diags/examples/IllegalArgumentForOption/IllegalArgumentForOption.java langtools/test/tools/javac/modules/ModulePathTest.java
diffstat 3 files changed, 30 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/file/Locations.java	Fri Feb 10 13:49:42 2017 -0800
+++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/file/Locations.java	Fri Feb 10 15:42:17 2017 -0800
@@ -985,6 +985,11 @@
         }
 
         private void checkValidModulePathEntry(Path p) {
+            if (!Files.exists(p)) {
+                // warning may be generated later
+                return;
+            }
+
             if (Files.isDirectory(p)) {
                 // either an exploded module or a directory of modules
                 return;
--- a/langtools/test/tools/javac/diags/examples/IllegalArgumentForOption/IllegalArgumentForOption.java	Fri Feb 10 13:49:42 2017 -0800
+++ b/langtools/test/tools/javac/diags/examples/IllegalArgumentForOption/IllegalArgumentForOption.java	Fri Feb 10 15:42:17 2017 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -22,7 +22,7 @@
  */
 
 // key: compiler.err.illegal.argument.for.option
-// options: --module-path doesNotExist
+// options: --module-source-path=abc*def
 // run: simple
 
 class X {}
--- a/langtools/test/tools/javac/modules/ModulePathTest.java	Fri Feb 10 13:49:42 2017 -0800
+++ b/langtools/test/tools/javac/modules/ModulePathTest.java	Fri Feb 10 15:42:17 2017 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -23,6 +23,7 @@
 
 /*
  * @test
+ * @bug 8142968 8174104
  * @summary tests for --module-path
  * @library /tools/lib
  * @modules
@@ -57,7 +58,7 @@
     }
 
     @Test
-    public void testNotExistsOnPath(Path base) throws Exception {
+    public void testNotExistsOnPath_noWarn(Path base) throws Exception {
         Path src = base.resolve("src");
         tb.writeJavaFiles(src, "class C { }");
 
@@ -65,11 +66,29 @@
                 .options("-XDrawDiagnostics",
                         "--module-path", "doesNotExist")
                 .files(findJavaFiles(src))
-                .run(Task.Expect.FAIL)
+                .run(Task.Expect.SUCCESS)
                 .writeAll()
                 .getOutput(Task.OutputKind.DIRECT);
 
-        if (!log.contains("- compiler.err.illegal.argument.for.option: --module-path, doesNotExist"))
+        if (!log.isEmpty())
+            throw new Exception("unexpected output");
+    }
+
+    @Test
+    public void testNotExistsOnPath_warn(Path base) throws Exception {
+        Path src = base.resolve("src");
+        tb.writeJavaFiles(src, "class C { }");
+
+        String log = new JavacTask(tb, Task.Mode.CMDLINE)
+                .options("-XDrawDiagnostics",
+                        "-Xlint:path",
+                        "--module-path", "doesNotExist")
+                .files(findJavaFiles(src))
+                .run(Task.Expect.SUCCESS)
+                .writeAll()
+                .getOutput(Task.OutputKind.DIRECT);
+
+        if (!log.contains("- compiler.warn.path.element.not.found: doesNotExist"))
             throw new Exception("expected output not found");
     }