changeset 19352:69bb5be60882

More improvements to exceptions
author alanb
date Mon, 20 Mar 2017 11:59:05 +0000
parents b657b9585c94
children 21ffffec02ce
files src/java.base/share/classes/jdk/internal/module/ModulePath.java test/java/lang/module/ModuleFinderTest.java
diffstat 2 files changed, 18 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/src/java.base/share/classes/jdk/internal/module/ModulePath.java	Sun Mar 19 12:14:58 2017 +0000
+++ b/src/java.base/share/classes/jdk/internal/module/ModulePath.java	Mon Mar 20 11:59:05 2017 +0000
@@ -513,7 +513,7 @@
                         String pn = packageName(cn);
                         if (!packages.contains(pn)) {
                             String msg = "Provider class " + cn + " not in module";
-                            throw new FindException(msg);
+                            throw new InvalidModuleDescriptorException(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 FindException(msg);
+                    throw new InvalidModuleDescriptorException(msg);
                 }
                 builder.mainClass(mainClass);
             }
@@ -671,17 +671,18 @@
     /**
      * Maps the name of an entry in a JAR or ZIP file to a package name.
      *
-     * @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)
+     * @throws InvalidModuleDescriptorException if the name is a class file in
+     *         the top-level directory of the JAR/ZIP file (and it's not
+     *         module-info.class)
      */
     private Optional<String> toPackageName(String name) {
         assert !name.endsWith("/");
         int index = name.lastIndexOf("/");
         if (index == -1) {
             if (name.endsWith(".class") && !name.equals(MODULE_INFO)) {
-                throw new FindException(name + " found in top-level directory"
-                                        + " (unnamed package not allowed in module)");
+                String msg = name + " found in top-level directory"
+                             + " (unnamed package not allowed in module)";
+                throw new InvalidModuleDescriptorException(msg);
             }
             return Optional.empty();
         }
@@ -699,7 +700,7 @@
      * Maps the relative path of an entry in an exploded module to a package
      * name.
      *
-     * @throws FindException if the name is a class file in
+     * @throws InvalidModuleDescriptorException 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) {
@@ -709,8 +710,9 @@
         if (parent == null) {
             String name = file.toString();
             if (name.endsWith(".class") && !name.equals(MODULE_INFO)) {
-                throw new FindException(name + " found in top-level directory"
-                                        + " (unnamed package not allowed in module)");
+                String msg = name + " found in top-level directory"
+                             + " (unnamed package not allowed in module)";
+                throw new InvalidModuleDescriptorException(msg);
             }
             return Optional.empty();
         }
--- a/test/java/lang/module/ModuleFinderTest.java	Sun Mar 19 12:14:58 2017 +0000
+++ b/test/java/lang/module/ModuleFinderTest.java	Mon Mar 20 11:59:05 2017 +0000
@@ -373,7 +373,7 @@
 
 
     /**
-     * Test ModuleModule with a JAR file containing a .class file in the top
+     * Test ModuleFinder with a JAR file containing a .class file in the top
      * level directory.
      */
     public void testOfOneJarFileWithTopLevelClass() throws Exception {
@@ -386,6 +386,7 @@
             assertTrue(false);
         } catch (FindException e) {
             assertTrue(e.getCause() instanceof InvalidModuleDescriptorException);
+            assertTrue(e.getCause().getMessage().contains("Mojo.class"));
         }
 
         finder = ModuleFinder.of(jar);
@@ -394,11 +395,12 @@
             assertTrue(false);
         } catch (FindException e) {
             assertTrue(e.getCause() instanceof InvalidModuleDescriptorException);
+            assertTrue(e.getCause().getMessage().contains("Mojo.class"));
         }
     }
 
     /**
-     * Test ModuleModule with a JAR file containing a .class file in the top
+     * Test ModuleFinder with a JAR file containing a .class file in the top
      * level directory.
      */
     public void testOfOneExplodedModuleWithTopLevelClass() throws Exception {
@@ -411,6 +413,7 @@
             assertTrue(false);
         } catch (FindException e) {
             assertTrue(e.getCause() instanceof InvalidModuleDescriptorException);
+            assertTrue(e.getCause().getMessage().contains("Mojo.class"));
         }
 
         finder = ModuleFinder.of(m_dir);
@@ -419,6 +422,7 @@
             assertTrue(false);
         } catch (FindException e) {
             assertTrue(e.getCause() instanceof InvalidModuleDescriptorException);
+            assertTrue(e.getCause().getMessage().contains("Mojo.class"));
         }
     }