Skip to content
Snippets Groups Projects
Commit 41f04a1c authored by Tomasz Grabiec's avatar Tomasz Grabiec Committed by Pekka Enberg
Browse files

java: fix NPE when context is called from a thread attached via JNI


In such case current context was not initialized. The fix is to default to master context.

Reported-by: default avatarAmnon Heiman <amnon@cloudius-systems.com>
Signed-off-by: default avatarTomasz Grabiec <tgrabiec@cloudius-systems.com>
Signed-off-by: default avatarPekka Enberg <penberg@cloudius-systems.com>
parent 89b9b3e8
No related branches found
No related tags found
No related merge requests found
...@@ -33,6 +33,8 @@ public class ContextIsolator { ...@@ -33,6 +33,8 @@ public class ContextIsolator {
verifyLogManagerIsInstalled(); verifyLogManagerIsInstalled();
} }
private final Context masterContext;
private static void verifyLogManagerIsInstalled() { private static void verifyLogManagerIsInstalled() {
LogManager manager = LogManager.getLogManager(); LogManager manager = LogManager.getLogManager();
if (!(manager instanceof IsolatingLogManager)) { if (!(manager instanceof IsolatingLogManager)) {
...@@ -41,7 +43,13 @@ public class ContextIsolator { ...@@ -41,7 +43,13 @@ public class ContextIsolator {
} }
} }
private final InheritableThreadLocal<Context> currentContext = new InheritableThreadLocal<>(); private final InheritableThreadLocal<Context> currentContext = new InheritableThreadLocal<Context>() {
@Override
protected Context initialValue() {
return masterContext;
}
};
private final ClassLoader parentClassLoaderForIsolates; private final ClassLoader parentClassLoaderForIsolates;
public static ContextIsolator getInstance() { public static ContextIsolator getInstance() {
...@@ -50,8 +58,7 @@ public class ContextIsolator { ...@@ -50,8 +58,7 @@ public class ContextIsolator {
public ContextIsolator() { public ContextIsolator() {
ClassLoader originalSystemClassLoader = getOsvClassLoader().getParent(); ClassLoader originalSystemClassLoader = getOsvClassLoader().getParent();
masterContext = new Context(originalSystemClassLoader, System.getProperties());
currentContext.set(new Context(originalSystemClassLoader, System.getProperties()));
parentClassLoaderForIsolates = new TeeClassLoader( parentClassLoaderForIsolates = new TeeClassLoader(
new FilteringClassLoader(originalSystemClassLoader, "io.osv.")); new FilteringClassLoader(originalSystemClassLoader, "io.osv."));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment