changeset 13509:0beca53343bb

8184689: Test applications/ctw/Modules.java fails with AssertionError in sun.hotspot.tools.ctw.Utils.fileNameToClassName Reviewed-by: kvn
author iignatyev
date Mon, 14 Aug 2017 12:35:38 -0700
parents 1f5231d2d01c
children c25f83bd8189
files test/testlibrary/ctw/src/sun/hotspot/tools/ctw/ClassPathJimageEntry.java test/testlibrary/ctw/src/sun/hotspot/tools/ctw/Utils.java
diffstat 2 files changed, 9 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/test/testlibrary/ctw/src/sun/hotspot/tools/ctw/ClassPathJimageEntry.java	Mon Aug 14 14:32:17 2017 -0400
+++ b/test/testlibrary/ctw/src/sun/hotspot/tools/ctw/ClassPathJimageEntry.java	Mon Aug 14 12:35:38 2017 -0700
@@ -43,9 +43,16 @@
         return Arrays.stream(reader.getEntryNames())
                      .filter(name -> name.endsWith(".class"))
                      .filter(name -> !name.endsWith("module-info.class"))
+                     .map(ClassPathJimageEntry::toFileName)
                      .map(Utils::fileNameToClassName);
     }
 
+    private static String toFileName(String name) {
+        final char nameSeparator = '/';
+        assert name.charAt(0) == nameSeparator : name;
+        return name.substring(name.indexOf(nameSeparator, 1) + 1);
+    }
+
     @Override
     protected String description() {
         return "# jimage: " + root;
--- a/test/testlibrary/ctw/src/sun/hotspot/tools/ctw/Utils.java	Mon Aug 14 14:32:17 2017 -0400
+++ b/test/testlibrary/ctw/src/sun/hotspot/tools/ctw/Utils.java	Mon Aug 14 12:35:38 2017 -0700
@@ -203,18 +203,14 @@
      * Converts the filename to classname.
      *
      * @param filename filename to convert
-     * @return corresponding classname.
+     * @return corresponding classname
      * @throws AssertionError if filename isn't valid filename for class file -
      *                        {@link #isClassFile(String)}
      */
     public static String fileNameToClassName(String filename) {
         assert isClassFile(filename);
-        // workaround for the class naming in jimage : /<module>/<class_name>
         final char nameSeparator = '/';
-        int nameStart = filename.charAt(0) == nameSeparator
-                ? filename.indexOf(nameSeparator, 1) + 1
-                : 0;
-        return filename.substring(nameStart, filename.length() - CLASSFILE_EXT.length())
+        return filename.substring(0, filename.length() - CLASSFILE_EXT.length())
                        .replace(nameSeparator, '.');
     }