diff --git a/core/src/main/java/org/jboss/logmanager/JDKSpecific.java b/core/src/main/java/org/jboss/logmanager/JDKSpecific.java index 0f5b9ec2..b9bc2e3e 100644 --- a/core/src/main/java/org/jboss/logmanager/JDKSpecific.java +++ b/core/src/main/java/org/jboss/logmanager/JDKSpecific.java @@ -25,6 +25,8 @@ import java.util.LinkedHashSet; import java.util.List; import java.util.Set; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import org.jboss.modules.Module; import org.jboss.modules.Version; @@ -37,6 +39,7 @@ private JDKSpecific() {} private static final Gateway GATEWAY; private static final boolean JBOSS_MODULES; + private static final boolean MODULAR_JVM; static { GATEWAY = AccessController.doPrivileged(new PrivilegedAction() { @@ -50,6 +53,23 @@ public Gateway run() { jbossModules = true; } catch (Throwable ignored) {} JBOSS_MODULES = jbossModules; + + // Get the current Java version and determine, by JVM version level, if this is a modular JDK + final String value = AccessController.doPrivileged(new PrivilegedAction() { + @Override + public String run() { + return System.getProperty("java.specification.version"); + } + }); + // Shouldn't happen, but we'll assume we're not a modular environment + boolean modularJvm = false; + if (value != null) { + final Matcher matcher = Pattern.compile("^(?:1\\.)?(\\d+)$").matcher(value); + if (matcher.find()) { + modularJvm = Integer.parseInt(matcher.group(1)) >= 9; + } + } + MODULAR_JVM = modularJvm; } static final class Gateway extends SecurityManager { @@ -58,6 +78,17 @@ protected Class[] getClassContext() { } } + /** + * Determines whether or not this is a modular JVM. The version of the {@code java.specification.version} is checked + * to determine if the version is greater than or equal to 9. This is required to disable specific features/hacks + * for older JVM's when the log manager is loaded on the boot class path which doesn't support multi-release JAR's. + * + * @return {@code true} if determined to be a modular JVM, otherwise {@code false} + */ + static boolean isModularJvm() { + return MODULAR_JVM; + } + static Class findCallingClass(Set rejectClassLoaders) { for (Class caller : GATEWAY.getClassContext()) { final ClassLoader classLoader = caller.getClassLoader(); diff --git a/core/src/main/java/org/jboss/logmanager/LogLevelInitTask.java b/core/src/main/java/org/jboss/logmanager/LogLevelInitTask.java index f0d43422..b14ac980 100644 --- a/core/src/main/java/org/jboss/logmanager/LogLevelInitTask.java +++ b/core/src/main/java/org/jboss/logmanager/LogLevelInitTask.java @@ -39,6 +39,11 @@ class LogLevelInitTask implements PrivilegedAction { @SuppressWarnings({ "unchecked" }) public Void run() { + // If this is a modular JVM ignore the level hack. The check here is required when the log manager is added to + // the boot class path. The boot class path does not support multi-release JAR's. + if (JDKSpecific.isModularJvm()) { + return null; + } /* This mysterious-looking hack is designed to trick JDK logging into not leaking classloaders and so forth when adding levels, by simply shutting down the craptastic level name "registry" that it keeps. */ diff --git a/core/src/main/java9/org/jboss/logmanager/JDKSpecific.java b/core/src/main/java9/org/jboss/logmanager/JDKSpecific.java index f3ce6f36..5ce980d5 100644 --- a/core/src/main/java9/org/jboss/logmanager/JDKSpecific.java +++ b/core/src/main/java9/org/jboss/logmanager/JDKSpecific.java @@ -55,6 +55,15 @@ private JDKSpecific() {} JBOSS_MODULES = jbossModules; } + /** + * Always returns {@code true}. + * + * @return {@code true} + */ + static boolean isModularJvm() { + return true; + } + static Class findCallingClass(Set rejectClassLoaders) { final SecurityManager sm = System.getSecurityManager(); if (sm != null) {