changeset 19349:3e030cff43b1

Small improvements to exceptions thrown when deriving a module descriptor fails
author alanb
date Sun, 19 Mar 2017 11:48:14 +0000
parents b77bacbfb8bf
children c9294b00cc92
files src/java.base/share/classes/jdk/internal/module/ModulePath.java
diffstat 1 files changed, 12 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/src/java.base/share/classes/jdk/internal/module/ModulePath.java	Sat Mar 18 14:01:28 2017 -0700
+++ b/src/java.base/share/classes/jdk/internal/module/ModulePath.java	Sun Mar 19 11:48:14 2017 +0000
@@ -513,7 +513,7 @@
                         String pn = packageName(cn);
                         if (!packages.contains(pn)) {
                             String msg = "Provider class " + cn + " not in module";
-                            throw new IOException(msg);
+                            throw new FindException(msg);
                         }
                         providerClasses.add(cn);
                     }
@@ -533,7 +533,7 @@
                 String pn = packageName(mainClass);
                 if (!packages.contains(pn)) {
                     String msg = "Main-Class " + mainClass + " not in module";
-                    throw new IOException(msg);
+                    throw new FindException(msg);
                 }
                 builder.mainClass(mainClass);
             }
@@ -610,10 +610,9 @@
                 try {
                     ModuleDescriptor md = deriveModuleDescriptor(jf);
                     attrs = new ModuleInfo.Attributes(md, null, null, null);
-                } catch (IllegalArgumentException e) {
-                    throw new FindException(
-                        "Unable to derive module descriptor for: "
-                        + jf.getName(), e);
+                } catch (RuntimeException e) {
+                    throw new FindException("Unable to derive module descriptor for "
+                                            + jf.getName(), e);
                 }
 
             } else {
@@ -672,7 +671,7 @@
     /**
      * Maps the name of an entry in a JAR or ZIP file to a package name.
      *
-     * @throws IllegalArgumentException if the name is a class file in
+     * @throws FindException if the name is a class file in
      *         the top-level directory of the JAR/ZIP file (and it's
      *         not module-info.class)
      */
@@ -681,9 +680,8 @@
         int index = name.lastIndexOf("/");
         if (index == -1) {
             if (name.endsWith(".class") && !name.equals(MODULE_INFO)) {
-                throw new IllegalArgumentException(name
-                        + " found in top-level directory"
-                        + " (unnamed package not allowed in module)");
+                throw new FindException(name + " found in top-level directory"
+                                        + " (unnamed package not allowed in module)");
             }
             return Optional.empty();
         }
@@ -701,8 +699,8 @@
      * Maps the relative path of an entry in an exploded module to a package
      * name.
      *
-     * @throws IllegalArgumentException if the name is a class file in
-     *          the top-level directory (and it's not module-info.class)
+     * @throws FindException if the name is a class file in
+     *         the top-level directory (and it's not module-info.class)
      */
     private Optional<String> toPackageName(Path file) {
         assert file.getRoot() == null;
@@ -711,9 +709,8 @@
         if (parent == null) {
             String name = file.toString();
             if (name.endsWith(".class") && !name.equals(MODULE_INFO)) {
-                throw new IllegalArgumentException(name
-                        + " found in top-level directory"
-                        + " (unnamed package not allowed in module)");
+                throw new FindException(name + " found in top-level directory"
+                                        + " (unnamed package not allowed in module)");
             }
             return Optional.empty();
         }