diff options
author | Omair Majid <[email protected]> | 2011-04-20 15:34:10 -0400 |
---|---|---|
committer | Omair Majid <[email protected]> | 2011-04-20 15:34:10 -0400 |
commit | 8a498edd2c86f034de4229037fb1aa2b79269de6 (patch) | |
tree | 24fad89636ff8768ac773580c5252bd9b5547a1b /netx/net/sourceforge | |
parent | 47fd4d77cb0c29ac1143d1bb1f09822acdb2c282 (diff) |
PR687: BasicService.getCodeBase() returns null for IcedTea6 1.9.7 + OSGI
The patch modifies how we try to find the JNLPClassLoader (from which we find
the ApplicationInstance). We first search the Context ClassLoader (and it's
parents) and then we search the ClassLoader for the classes on the stack (and
their parents). The Launcher always sets the Context ClassLoader of the
applications/applets it launches.
Diffstat (limited to 'netx/net/sourceforge')
-rw-r--r-- | netx/net/sourceforge/jnlp/runtime/JNLPSecurityManager.java | 56 |
1 files changed, 40 insertions, 16 deletions
diff --git a/netx/net/sourceforge/jnlp/runtime/JNLPSecurityManager.java b/netx/net/sourceforge/jnlp/runtime/JNLPSecurityManager.java index b45dd8b..a6a4ea7 100644 --- a/netx/net/sourceforge/jnlp/runtime/JNLPSecurityManager.java +++ b/netx/net/sourceforge/jnlp/runtime/JNLPSecurityManager.java @@ -165,7 +165,7 @@ class JNLPSecurityManager extends AWTSecurityManager { * determined. */ protected ApplicationInstance getApplication() { - return getApplication(getClassContext(), 0); + return getApplication(Thread.currentThread(), getClassContext(), 0); } /** @@ -190,28 +190,52 @@ class JNLPSecurityManager extends AWTSecurityManager { /** * Return the current Application, or null. */ - protected ApplicationInstance getApplication(Class stack[], int maxDepth) { + protected ApplicationInstance getApplication(Thread thread, Class<?> stack[], int maxDepth) { + ClassLoader cl; + JNLPClassLoader jnlpCl; + + cl = thread.getContextClassLoader(); + while (cl != null) { + jnlpCl = getJnlpClassLoader(cl); + if (jnlpCl != null && jnlpCl.getApplication() != null) { + return jnlpCl.getApplication(); + } + cl = cl.getParent(); + } + if (maxDepth <= 0) maxDepth = stack.length; // this needs to be tightened up for (int i = 0; i < stack.length && i < maxDepth; i++) { - ClassLoader cl = stack[i].getClassLoader(); - - // Since we want to deal with JNLPClassLoader, extract it if this - // is a codebase loader - if (cl instanceof JNLPClassLoader.CodeBaseClassLoader) - cl = ((JNLPClassLoader.CodeBaseClassLoader) cl).getParentJNLPClassLoader(); - - if (cl instanceof JNLPClassLoader) { - - JNLPClassLoader loader = (JNLPClassLoader) cl; - - if (loader != null && loader.getApplication() != null) { - return loader.getApplication(); + cl = stack[i].getClassLoader(); + while (cl != null) { + jnlpCl = getJnlpClassLoader(cl); + if (jnlpCl != null && jnlpCl.getApplication() != null) { + return jnlpCl.getApplication(); } + cl = cl.getParent(); } } + return null; + } + + /** + * Returns the JNLPClassLoader associated with the given ClassLoader, or + * null. + * @param cl a ClassLoader + * @return JNLPClassLoader or null + */ + private JNLPClassLoader getJnlpClassLoader(ClassLoader cl) { + // Since we want to deal with JNLPClassLoader, extract it if this + // is a codebase loader + if (cl instanceof JNLPClassLoader.CodeBaseClassLoader) + cl = ((JNLPClassLoader.CodeBaseClassLoader) cl).getParentJNLPClassLoader(); + + if (cl instanceof JNLPClassLoader) { + JNLPClassLoader loader = (JNLPClassLoader) cl; + return loader; + } return null; } @@ -444,7 +468,7 @@ class JNLPSecurityManager extends AWTSecurityManager { } // but when they really call, stop only the app instead of the JVM - ApplicationInstance app = getApplication(stack, 0); + ApplicationInstance app = getApplication(Thread.currentThread(), stack, 0); if (app == null) { throw new SecurityException(R("RExitNoApp")); } |