Skip to content

Commit

Permalink
Merge pull request #218 from jamezp/LOGMGR-218
Browse files Browse the repository at this point in the history
[LOGMGR-218] An MR JAR is not supported for the boot class path. Chec…
  • Loading branch information
jamezp authored Dec 7, 2018
2 parents 871bd38 + 70e733b commit 41831ff
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 0 deletions.
31 changes: 31 additions & 0 deletions core/src/main/java/org/jboss/logmanager/JDKSpecific.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<Gateway>() {
Expand All @@ -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<String>() {
@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 {
Expand All @@ -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<ClassLoader> rejectClassLoaders) {
for (Class<?> caller : GATEWAY.getClassContext()) {
final ClassLoader classLoader = caller.getClassLoader();
Expand Down
5 changes: 5 additions & 0 deletions core/src/main/java/org/jboss/logmanager/LogLevelInitTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ class LogLevelInitTask implements PrivilegedAction<Void> {

@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.
*/
Expand Down
9 changes: 9 additions & 0 deletions core/src/main/java9/org/jboss/logmanager/JDKSpecific.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<ClassLoader> rejectClassLoaders) {
final SecurityManager sm = System.getSecurityManager();
if (sm != null) {
Expand Down

0 comments on commit 41831ff

Please sign in to comment.