[Solved] JNLPClassLoader finds the same resource twice when using jnlp extension

The public knowledge pool and discussion forum of the OWS community. Do not post confidential information here!
msc
Posts: 13
Joined: 09 Dec 2021, 07:18

[Solved] JNLPClassLoader finds the same resource twice when using jnlp extension

Post by msc »

Our application uses a jnlp file ("first.jnlp") which references another jnlp file ("second.jnlp") as an extension:

first.jnlp

Code: Select all

...<resources>
        <extension href="second.jnlp" name="myExtension"/>...
The second.jnlp references a jar file which contains an xml resource:

Code: Select all

...<resources>
        <jar href="jar_containing_xml_resource.jar" version="1.0.0"/>...
So it looks something like this:
first.jnlp --> second.jnlp (extension) --> jar --> xml resource

When calling the method getResources() of the ClassLoader with the path to the xml file as an argument, the method findResources() of the net.sourceforge.jnlp.runtime.classloader.JNLPClassLoader gets called with the same argument. This method returns an Enumeration<URL> with two occurences: the first one is empty and the second one is a Collection which contains the same resource twice. So the JNLPClassLoader seems to be finding the same resource twice, although it only exists once in one jar, which is referenced by only one jnlp. This in turn leads to the resource being processed twice in the application, which causes all sorts of problems.

The reason behind this behavoiur seems to be the fact that the resource is in a jar which is in an extension jnlp.
The JNLPClassLoader probably finds the resource once when processing the first.jnlp (seemingly also including all its extensions) ant then once more when processing the second.jnlp. So the jar seems to be on the classpath twice and not only once as expected.

I tried using only one jnlp file without extensions and referencing all the jars in this jnlp. Everything worked perfectly, this time the resource was only found and processed once, as expected.

Janak Mulani
Posts: 746
Joined: 24 Mar 2020, 13:37

Re: JNLPClassLoader finds the same resource twice when using jnlp extension

Post by Janak Mulani »

Thanks for reporting this. I will try to reproduce this. Just some clarification:

1. First Jnlp has:
a. jar with an app that is loading the xml resource
b. Extension pointing to Second Jnlp
2. Second Jnlp has:
a jar that contains xml resource used by the the app in the jar file specified in the First Jnlp

Does the above describe your situation accurately?

msc
Posts: 13
Joined: 09 Dec 2021, 07:18

Re: JNLPClassLoader finds the same resource twice when using jnlp extension

Post by msc »

Yes, exactly.

Janak Mulani
Posts: 746
Joined: 24 Mar 2020, 13:37

Re: JNLPClassLoader finds the same resource twice when using jnlp extension

Post by Janak Mulani »

Ok. I will try to reproduce and fix it.

msc
Posts: 13
Joined: 09 Dec 2021, 07:18

Re: JNLPClassLoader finds the same resource twice when using jnlp extension

Post by msc »

Maybe you can use this application (see attachment).
There is a main.jar with a Main.class which reads all resources named "items.txt" and displays their content. This main.jar is referenced in the jnlp_main.jnlp.
Then there are two resource jars: res1.jar and res2.jar, each containing an items.txt file. These two jars are referenced in the jnlp_extension.jnlp, which is an extension of jnlp_main.jnlp.
When I download and start the application with OpenWebStart, each items.txt file is found and processed twice.
Attachments
MyApp.zip
(55.19 KiB) Downloaded 230 times

Janak Mulani
Posts: 746
Joined: 24 Mar 2020, 13:37

Re: JNLPClassLoader finds the same resource twice when using jnlp extension

Post by Janak Mulani »

Thanks for the sample. I will try and come back to you.

Janak Mulani
Posts: 746
Joined: 24 Mar 2020, 13:37

Re: JNLPClassLoader finds the same resource twice when using jnlp extension

Post by Janak Mulani »

I can reproduce the issue. When the resource jars are directly present in jnlp, the resource is found only once. However, when the resources jars are in the extension jnlp, the resource is found twice. I will investigate and fix it. Thanks for pointing reporting this bug.

msc
Posts: 13
Joined: 09 Dec 2021, 07:18

Re: JNLPClassLoader finds the same resource twice when using jnlp extension

Post by msc »

In the meantime, we implemented a work around which should take care of the issue until the JNLPClassLoader gets corrected.
Basically, we use a wrapper which filters out all duplicates contained in the Enumeration<URL> returned by findResources(String name).


Post Reply