changeset 300:3545cea5c845

PR618: Can't install OpenDJ, JavaWebStart fails with Input stream is null error. 2011-09-29 Omair Majid <omajid@redhat.com> * NEWS: Update. * netx/net/sourceforge/jnlp/runtime/JNLPClassLoader.java (getResource): Rename to ... (findResource): New method. (findResources): If resource can not be found, search in lazy resources. (findResourcesBySearching): New method.
author Omair Majid <omajid@redhat.com>
date Thu, 29 Sep 2011 11:35:01 -0400
parents fb883fdc9331
children 2a7aa789f554
files ChangeLog NEWS netx/net/sourceforge/jnlp/runtime/JNLPClassLoader.java
diffstat 3 files changed, 56 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Wed Sep 28 18:17:13 2011 -0400
+++ b/ChangeLog	Thu Sep 29 11:35:01 2011 -0400
@@ -1,4 +1,15 @@
-2011-09-28 Omair Majid <omajid@redhat.com>
+2011-09-29  Omair Majid  <omajid@redhat.com>
+
+	PR618: Can't install OpenDJ, JavaWebStart fails with Input stream is null
+	error.
+	* NEWS: Update.
+	* netx/net/sourceforge/jnlp/runtime/JNLPClassLoader.java
+	(getResource): Rename to ...
+	(findResource): New method.
+	(findResources): If resource can not be found, search in lazy resources.
+	(findResourcesBySearching): New method.
+
+2011-09-28  Omair Majid  <omajid@redhat.com>
 
 	* netx/net/sourceforge/jnlp/AppletDesc.java (getMainClass): Clarify the
 	return value in javadoc.
--- a/NEWS	Wed Sep 28 18:17:13 2011 -0400
+++ b/NEWS	Thu Sep 29 11:35:01 2011 -0400
@@ -13,6 +13,7 @@
 	- RH718164, CVE-2011-2513: Home directory path disclosure to untrusted applications
 	- RH718170, CVE-2011-2514: Java Web Start security warning dialog manipulation
 * NetX
+  - PR618: Can't install OpenDJ, JavaWebStart fails with Input stream is null error
   - PR765: JNLP file with all resource jars marked as 'lazy' fails to validate signature and stops the launch of application
   - PR788: Elluminate Live! is not working
 * Plugin
--- a/netx/net/sourceforge/jnlp/runtime/JNLPClassLoader.java	Wed Sep 28 18:17:13 2011 -0400
+++ b/netx/net/sourceforge/jnlp/runtime/JNLPClassLoader.java	Thu Sep 29 11:35:01 2011 -0400
@@ -1484,31 +1484,64 @@
     /**
      * Finds the resource in this, the parent, or the extension
      * class loaders.
+     *
+     * @return a <code>URL</code> for the resource, or <code>null</code>
+     * if the resource could not be found.
      */
-    public URL getResource(String name) {
-        URL result = super.getResource(name);
+    @Override
+    public URL findResource(String name) {
+        URL result = null;
 
-        for (int i = 1; i < loaders.length; i++)
-            if (result == null)
-                result = loaders[i].getResource(name);
+        try {
+            Enumeration<URL> e = findResources(name);
+            if (e.hasMoreElements()) {
+                result = e.nextElement();
+            }
+        } catch (IOException e) {
+            if (JNLPRuntime.isDebug()) {
+                e.printStackTrace();
+            }
+        }
         
         // If result is still null, look in the codebase loader
         if (result == null && codeBaseLoader != null)
-            result = codeBaseLoader.getResource(name);
+            result = codeBaseLoader.findResource(name);
 
         return result;
     }
 
     /**
-     * Finds the resource in this, the parent, or the extension
-     * class loaders.
+     * Find the resources in this, the parent, or the extension
+     * class loaders. Load lazy resources if not found in current resources.
      */
     @Override
     public Enumeration<URL> findResources(String name) throws IOException {
-        Vector<URL> resources = new Vector<URL>();
+        Enumeration<URL> resources = findResourcesBySearching(name);
+
+        try {
+            // if not found, load all lazy resources; repeat search
+            while (!resources.hasMoreElements() && addNextResource() != null) {
+                resources = findResourcesBySearching(name);
+            }
+        } catch (LaunchException le) {
+            le.printStackTrace();
+        }
+
+        return resources;
+    }
+
+    /**
+     * Find the resources in this, the parent, or the extension
+     * class loaders.
+     */
+    private Enumeration<URL> findResourcesBySearching(String name) throws IOException {
+        List<URL> resources = new ArrayList<URL>();
         Enumeration<URL> e;
 
         for (int i = 0; i < loaders.length; i++) {
+            // TODO check if this will blow up or not
+            // if loaders[1].getResource() is called, wont it call getResource() on
+            // the original caller? infinite recursion?
 
             if (loaders[i] == this)
                 e = super.findResources(name);
@@ -1527,7 +1560,7 @@
                 resources.add(e.nextElement());
         }
 
-        return resources.elements();
+        return Collections.enumeration(resources);
     }
 
     /**