From 8a498edd2c86f034de4229037fb1aa2b79269de6 Mon Sep 17 00:00:00 2001 From: Omair Majid Date: Wed, 20 Apr 2011 15:34:10 -0400 Subject: 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. --- .../jnlp/runtime/JNLPSecurityManager.java | 56 +++++++++++++++------- 1 file changed, 40 insertions(+), 16 deletions(-) (limited to 'netx/net/sourceforge') 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")); } -- cgit v1.2.3