changeset 7703:8472a122f8e7

Merge
author erikj
date Fri, 09 Jan 2015 08:58:12 +0100
parents 1a5fc2a632a1 132f807deae0
children 28f0f6985eeb
files src/share/vm/classfile/classFileParser.cpp
diffstat 2 files changed, 49 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/vm/classfile/classFileParser.cpp	Thu Jan 08 17:19:25 2015 +0100
+++ b/src/share/vm/classfile/classFileParser.cpp	Fri Jan 09 08:58:12 2015 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2015, 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
@@ -5125,9 +5125,13 @@
   for (char* p = name; p != name + length; ) {
     ch = *p;
     if (ch < 128) {
-      p++;
-      if (ch == '.' && type != LegalModule) {
-        return false;
+      if (ch == '.') {
+        // permit '.' in module names unless it's the first char, or
+        // preceding char is also a '.', or last char is a '.'.
+        if ((type != LegalModule) || (p == name) || (*(p-1) == '.') ||
+          (p == name + length - 1)) {
+          return false;
+        }
       }
       if (ch == ';' || ch == '[' ) {
         return false;   // do not permit '.', ';', or '['
@@ -5138,6 +5142,7 @@
       if (type == LegalMethod && (ch == '<' || ch == '>')) {
         return false;   // do not permit '<' or '>' in method names
       }
+      p++;
     } else {
       char* tmp_p = UTF8::next(p, &ch);
       p = tmp_p;
--- a/test/runtime/modules/JVMDefineModule.java	Thu Jan 08 17:19:25 2015 +0100
+++ b/test/runtime/modules/JVMDefineModule.java	Fri Jan 09 08:58:12 2015 +0100
@@ -48,7 +48,7 @@
         // Invalid classloader argument, expect an IAE
         try {
             wb.DefineModule("mymodule1", new Object(), new String[] { "mypackage1" });
-            throw new RuntimeException("Failed to get the expected IAE");
+            throw new RuntimeException("Failed to get expected IAE for bad loader");
         } catch(IllegalArgumentException e) {
             // Expected
         }
@@ -60,7 +60,7 @@
         // NULL module name, expect an NPE
         try {
             wb.DefineModule(null, cl, new String[] { "mypackage2" });
-            throw new RuntimeException("Failed to get the expected NPE");
+            throw new RuntimeException("Failed to get expected NPE for NULL module");
         } catch(NullPointerException e) {
             // Expected
         }
@@ -68,7 +68,7 @@
         // module name is java.base, expect an IAE
         try {
             wb.DefineModule("java.base", cl, new String[] { "mypackage3" });
-            throw new RuntimeException("Failed to get the expected IAE");
+            throw new RuntimeException("Failed to get expected IAE for java.base");
         } catch(IllegalArgumentException e) {
             // Expected
         }
@@ -76,7 +76,7 @@
         // Duplicates in package list, expect an IAE
         try {
             wb.DefineModule("java.base", cl, new String[] { "mypackage4", "mypackage5", "mypackage4" });
-            throw new RuntimeException("Failed to get the expected IAE");
+            throw new RuntimeException("Failed to get IAE for duplicate packages");
         } catch(IllegalArgumentException e) {
             // Expected
         }
@@ -84,7 +84,7 @@
         // Empty entry in package list, expect an IAE
         try {
             wb.DefineModule("java.base", cl, new String[] { "mypackageX", "", "mypackageY" });
-            throw new RuntimeException("Failed to get the expected IAE");
+            throw new RuntimeException("Failed to get IAE for empty package");
         } catch(IllegalArgumentException e) {
             // Expected
         }
@@ -94,7 +94,7 @@
         assertNotNull(m, "Module should not be null");
         try {
             wb.DefineModule("module.name", cl, new String[] { "mypackage7" });
-            throw new RuntimeException("Failed to get the expected IAE");
+            throw new RuntimeException("Failed to get IAE for duplicate module");
         } catch(IllegalArgumentException e) {
             // Expected
         }
@@ -102,7 +102,7 @@
         // Package is already defined for class loader, expect an IAE
         try {
             wb.DefineModule("dupl.pkg.module", cl, new String[] { "mypackage6" });
-            throw new RuntimeException("Failed to get the expected IAE");
+            throw new RuntimeException("Failed to get IAE for existing package");
         } catch(IllegalArgumentException e) {
             // Expected
         }
@@ -110,7 +110,7 @@
         // Empty module name, expect an IAE
         try {
             wb.DefineModule("", cl, new String[] { "mypackage8" });
-            throw new RuntimeException("Failed to get the expected IAE");
+            throw new RuntimeException("Failed to get expected IAE for empty module name");
         } catch(IllegalArgumentException e) {
             // Expected
         }
@@ -118,11 +118,39 @@
         // Bad module name, expect an IAE
         try {
             wb.DefineModule("bad;name", cl, new String[] { "mypackage9" });
-            throw new RuntimeException("Failed to get the expected IAE");
+            throw new RuntimeException("Failed to get expected IAE for bad;name");
         } catch(IllegalArgumentException e) {
             // Expected
         }
 
+        // Bad module name, expect an IAE
+        try {
+            wb.DefineModule(".leadingdot", cl, new String[] { "mypackage9a" });
+            throw new RuntimeException("Failed to get expected IAE for .leadingdot");
+        } catch(IllegalArgumentException e) {
+            // Expected
+        }
+
+        // Bad module name, expect an IAE
+        try {
+            wb.DefineModule("trailingdot.", cl, new String[] { "mypackage9b" });
+            throw new RuntimeException("Failed to get expected IAE for trailingdot.");
+        } catch(IllegalArgumentException e) {
+            // Expected
+        }
+
+        // Bad module name, expect an IAE
+        try {
+            wb.DefineModule("consecutive..dots", cl, new String[] { "mypackage9c" });
+            throw new RuntimeException("Failed to get expected IAE for consecutive..dots");
+        } catch(IllegalArgumentException e) {
+            // Expected
+        }
+
+        // module name with multiple dots, should be okay
+        m = wb.DefineModule("more.than.one.dat", cl, new String[] { "mypackage9d" });
+        assertNotNull(m, "Module should not be null");
+
         // Zero length package list, should be okay
         m = wb.DefineModule("zero.packages", cl, new String[] { });
         assertNotNull(m, "Module should not be null");
@@ -130,7 +158,7 @@
         // Invalid package name, expect an IAE
         try {
             wb.DefineModule("module5", cl, new String[] { "your.package" });
-            throw new RuntimeException("Failed to get the expected IAE");
+            throw new RuntimeException("Failed to get expected IAE for your.package");
         } catch(IllegalArgumentException e) {
             // Expected
         }
@@ -138,7 +166,7 @@
         // Invalid package name, expect an IAE
         try {
             wb.DefineModule("module6", cl, new String[] { ";your/package" });
-            throw new RuntimeException("Failed to get the expected IAE");
+            throw new RuntimeException("Failed to get expected IAE for ;your.package");
         } catch(IllegalArgumentException e) {
             // Expected
         }
@@ -146,7 +174,7 @@
         // Invalid package name, expect an IAE
         try {
             wb.DefineModule("module7", cl, new String[] { "7[743" });
-            throw new RuntimeException("Failed to get the expected IAE");
+            throw new RuntimeException("Failed to get expected IAE for package 7[743");
         } catch(IllegalArgumentException e) {
             // Expected
         }