8137113: [TEST_BUG] Two java.beans tests need to be updated to work with JDK 9 modularized filesystem
authoryan
Tue, 10 Nov 2015 13:46:45 +0300
changeset 33865 d5d2d1a08a71
parent 33864 009bfc0f3666
child 33866 e4b2a5f4dea0
child 34393 171a07c89136
8137113: [TEST_BUG] Two java.beans tests need to be updated to work with JDK 9 modularized filesystem Reviewed-by: serb, alexsch Contributed-by: Rocky Sloan <rocky.sloan@oracle.com>
jdk/test/java/beans/XMLDecoder/8028054/Task.java
jdk/test/java/beans/XMLDecoder/8028054/TestConstructorFinder.java
jdk/test/java/beans/XMLDecoder/8028054/TestMethodFinder.java
--- a/jdk/test/java/beans/XMLDecoder/8028054/Task.java	Mon Nov 09 09:05:20 2015 -0800
+++ b/jdk/test/java/beans/XMLDecoder/8028054/Task.java	Tue Nov 10 13:46:45 2015 +0300
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 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
@@ -22,12 +22,17 @@
  */
 
 import java.util.ArrayList;
-import java.util.Enumeration;
 import java.util.List;
-import java.util.jar.JarEntry;
-import java.util.jar.JarFile;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
+import java.util.stream.Collectors;
+import java.net.*;
+import java.io.*;
+import java.nio.file.FileSystem;
+import java.nio.file.FileSystems;
+import java.nio.file.FileSystemNotFoundException;
+import java.nio.file.ProviderNotFoundException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.function.Predicate;
 
 abstract class Task<T> implements Runnable {
     private transient boolean working = true;
@@ -74,26 +79,74 @@
     }
 
     static List<Class<?>> getClasses(int count) throws Exception {
-        String resource = ClassLoader.getSystemClassLoader().getResource("java/lang/Object.class").toString();
+        List<Class<?>> classes = new ArrayList<>();
+        FileSystem fs = null;
+
+        try {
+            fs = FileSystems.getFileSystem(URI.create("jrt:/"));
+        } catch (ProviderNotFoundException | FileSystemNotFoundException e) {
+            throw new RuntimeException("FAIL - JRT Filesystem not found");
+        }
+
+        List<String> fileNames;
+        Path modules = fs.getPath("/modules");
 
-        Pattern pattern = Pattern.compile("jar:file:(.*)!.*");
-        Matcher matcher = pattern.matcher(resource);
-        matcher.matches();
-        resource = matcher.group(1);
+        Predicate<String> startsWithJavaBase          = path -> path.toString().startsWith("java.base/java");
+        Predicate<String> startsWithJavaDesktop       = path -> path.toString().startsWith("java.desktop/java");
+        Predicate<String> startsWithJavaDataTransfer  = path -> path.toString().startsWith("java.datatransfer/java");
+        Predicate<String> startsWithJavaRMI           = path -> path.toString().startsWith("java.rmi/java");
+        Predicate<String> startsWithJavaSmartCardIO   = path -> path.toString().startsWith("java.smartcardio/java");
+        Predicate<String> startsWithJavaManagement    = path -> path.toString().startsWith("java.management/java");
+        Predicate<String> startsWithJavaXML           = path -> path.toString().startsWith("java.xml/java");
+        Predicate<String> startsWithJavaXMLBind       = path -> path.toString().startsWith("java.xml.bind/java");
+        Predicate<String> startsWithJavaScripting     = path -> path.toString().startsWith("java.scripting/java");
+        Predicate<String> startsWithJavaNaming        = path -> path.toString().startsWith("java.naming/java");
+        Predicate<String> startsWithJavaSQL           = path -> path.toString().startsWith("java.sql/java");
+        Predicate<String> startsWithJavaActivation    = path -> path.toString().startsWith("java.activation/java");
+        Predicate<String> startsWithJavaCompiler      = path -> path.toString().startsWith("java.compiler/java");
+        Predicate<String> startsWithJavaAnnotations   = path -> path.toString().startsWith("java.annotations/java");
+        Predicate<String> startsWithJavaTransaction   = path -> path.toString().startsWith("java.transaction/java");
+        Predicate<String> startsWithJavaLogging       = path -> path.toString().startsWith("java.logging/java");
+        Predicate<String> startsWithJavaCorba         = path -> path.toString().startsWith("java.corba/java");
+        Predicate<String> startsWithJavaPrefs         = path -> path.toString().startsWith("java.prefs/java");
 
-        List<Class<?>> classes = new ArrayList<>();
-        try (JarFile jarFile = new JarFile(resource)) {
-            Enumeration<JarEntry> entries = jarFile.entries();
-            while (entries.hasMoreElements()) {
-                String name = entries.nextElement().getName();
-                if (name.startsWith("java") && name.endsWith(".class")) {
-                    classes.add(Class.forName(name.substring(0, name.indexOf(".")).replace('/', '.')));
-                    if (count == classes.size()) {
-                        break;
-                    }
-                }
+        fileNames = Files.walk(modules)
+                .map(Path::toString)
+                .filter(path -> path.toString().contains("java"))
+                .map(s -> s.substring(9))  // remove /modules/ from beginning
+                .filter(startsWithJavaBase
+                    .or(startsWithJavaDesktop)
+                    .or(startsWithJavaDataTransfer)
+                    .or(startsWithJavaRMI)
+                    .or(startsWithJavaSmartCardIO)
+                    .or(startsWithJavaManagement)
+                    .or(startsWithJavaXML)
+                    .or(startsWithJavaXMLBind)
+                    .or(startsWithJavaScripting)
+                    .or(startsWithJavaNaming)
+                    .or(startsWithJavaSQL)
+                    .or(startsWithJavaActivation)
+                    .or(startsWithJavaCompiler)
+                    .or(startsWithJavaAnnotations)
+                    .or(startsWithJavaTransaction)
+                    .or(startsWithJavaLogging)
+                    .or(startsWithJavaCorba)
+                    .or(startsWithJavaPrefs))
+                .map(s -> s.replace('/', '.'))
+                .filter(path -> path.toString().endsWith(".class"))
+                .map(s -> s.substring(0, s.length() - 6))  // drop .class
+                .map(s -> s.substring(s.indexOf(".")))
+                .filter(path -> path.toString().contains("java"))
+                .map(s -> s.substring(s.indexOf("java")))
+                .collect(Collectors.toList());
+
+        for (String name : fileNames) {
+            classes.add(Class.forName(name));
+            if (count == classes.size()) {
+                break;
             }
         }
+
         return classes;
     }
 }
--- a/jdk/test/java/beans/XMLDecoder/8028054/TestConstructorFinder.java	Mon Nov 09 09:05:20 2015 -0800
+++ b/jdk/test/java/beans/XMLDecoder/8028054/TestConstructorFinder.java	Tue Nov 10 13:46:45 2015 +0300
@@ -73,8 +73,7 @@
             }
             Task.print(working + " out of " + alive + " threads are working");
             if ((working == 0) && (++alarm == 10)) {
-                Task.print("DEADLOCK DETECTED");
-                System.exit(100);
+                throw new RuntimeException("FAIL - DEADLOCK DETECTED");
             }
             Thread.sleep(1000);
         }
--- a/jdk/test/java/beans/XMLDecoder/8028054/TestMethodFinder.java	Mon Nov 09 09:05:20 2015 -0800
+++ b/jdk/test/java/beans/XMLDecoder/8028054/TestMethodFinder.java	Tue Nov 10 13:46:45 2015 +0300
@@ -73,8 +73,7 @@
             }
             Task.print(working + " out of " + alive + " threads are working");
             if ((working == 0) && (++alarm == 10)) {
-                Task.print("DEADLOCK DETECTED");
-                System.exit(100);
+                throw new RuntimeException("FAIL - DEADLOCK DETECTED");
             }
             Thread.sleep(1000);
         }