From cb3b7482fb3eebf34ff4522ffaf96a8fd0b09dbe Mon Sep 17 00:00:00 2001 From: Peter Bain Date: Wed, 16 Jan 2019 12:17:16 -0500 Subject: [PATCH] Fix vmcheck exclusions Expand the exclusion list for machines with no access to a display (https://github.com/eclipse/openj9/issues/4279). Update the filtering code. Add quotes to filenames containing dollar signs so the command line is compatible with the shell. [ci skip] Fixes https://github.com/eclipse/openj9/issues/4279 Signed-off-by: Peter Bain --- .../TestLoadingClassesFromJarfile.java | 67 ++++++++++++------- 1 file changed, 43 insertions(+), 24 deletions(-) diff --git a/test/functional/Java8andUp/src/org/openj9/test/vmcheck/TestLoadingClassesFromJarfile.java b/test/functional/Java8andUp/src/org/openj9/test/vmcheck/TestLoadingClassesFromJarfile.java index 8c8ab709dca..194336dc60d 100644 --- a/test/functional/Java8andUp/src/org/openj9/test/vmcheck/TestLoadingClassesFromJarfile.java +++ b/test/functional/Java8andUp/src/org/openj9/test/vmcheck/TestLoadingClassesFromJarfile.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2001, 2018 IBM Corp. and others + * Copyright (c) 2001, 2019 IBM Corp. and others * * This program and the accompanying materials are made available under * the terms of the Eclipse Public License 2.0 which accompanies this @@ -35,8 +35,10 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Enumeration; +import java.util.HashSet; import java.util.jar.JarEntry; import java.util.jar.JarFile; +import java.util.stream.Collectors; @Test(groups = { "level.extended" }) @@ -99,8 +101,12 @@ private void loadClassesFromJarfile(String jarfilePath) { while ((classNames.size() < MAX_CLASSES) && jarfileEntries.hasMoreElements()) { JarEntry entry = jarfileEntries.nextElement(); String jarEntryName = entry.getName(); - if (filterFileName(jarEntryName)) { + if (includeFile(jarEntryName)) { String testClassName = convertFileNameToClassName(jarEntryName); + /* Prevent spurious macro expansion by the shell */ + if (testClassName.contains("$")) { //$NON-NLS-1$ + testClassName = "'"+testClassName+"'"; //$NON-NLS-1$ //$NON-NLS-2$ + } classNames.add(testClassName); } } @@ -115,28 +121,41 @@ private void loadClassesFromJarfile(String jarfilePath) { } } - private boolean filterFileName(String jarEntryName) { - if (!jarEntryName.endsWith(".class")) { - return false; - } - - /* - * the AWT native libraries have known issues if loaded manually. - * See CMVC 188841 and 188910 - */ - if (jarEntryName.startsWith("sun/awt") - || jarEntryName.startsWith("sun/java2d") - - /* sun.reflect.misc.Trampoline need to be excluded as per CMVC 197245 */ - || jarEntryName.startsWith("sun/reflect/misc/Trampoline") - - /* Classes that compile stubs will throw errors if loaded: OpenJ9 Issue #732 */ - || jarEntryName.equals("java/util/PropertyPermission.class") - || jarEntryName.startsWith("java/lang/invoke")) - { - return false; - } - return true; + /** + * Certain packages cannot be loaded via Class.forName() + * as they may require certain machine setups or permissions, + * e.g. access to a display. + */ + @SuppressWarnings("nls") + private static final HashSet excludedPackages = + new HashSet(Arrays.asList(new String[] { + "com.apple.eawt", + "com.apple.laf", + "com.sun.beans.editors", + "com.sun.imageio.plugins", + "com.sun.java.swing", + "com.sun.naming.internal", + "com.sun.xml.internal", + "java.applet", + "java.awt", + "java.lang.invoke", + "java.util.PropertyPermission", + "javax.imageio.ImageIO", + "javax.swing", + "sun.applet", + "sun.awt", + "sun.font", + "sun.java2d", + "sun.lwawt", + "sun.print", + "sun.reflect.misc.Trampoline", + "sun.security.tools.policytool", + "sun.swing" + }).stream().map(s -> s.replace('.', '/')).collect(Collectors.toList())); + + private static boolean includeFile(String jarEntryName) { + return jarEntryName.endsWith(".class") //$NON-NLS-1$ + && !excludedPackages.stream().anyMatch(p -> jarEntryName.startsWith(p)); } private void createAndRunNewClassloadingTester(String jarfilePath, ArrayList classNames)