URLClassLoader getResourceAsStream reads from wrong/old Jar file and believed to cause corruption of the resource stream and/or sigsegv of JVM
This can cause correct code to generate incorrect results and/or sigsegv.
Symptoms:
A module of code is dynamically loaded into a JVM using a URLClassLoader, the module code and resources (property files) are in a jarfile on the URLClassLoader's path.
The dynamically loaded module reads resources (property files) through its classloader. It gets the expected resource streams.
The module is unloaded from the JVM, the classloader is garbage collected sucessfully.
The module's jar file is updated to a new version of the module and new version of the property files.
The module is re-loaded into the JVM with a new classloader, using the updated jar file in the same filesystem location.
The module is re-executed. The new code is executed, but classloader.getResourceAsStream() returns the contents of the property file from the OLD jar file which no longer exists on the filesystem.
... we believe that the jar file has been cached in the JVM and the old jarfile is being reused by mistake in getResourceAsStream
** ISOLATED CODE TO REPRODUCE BUG ***
Attached to this bugid is a standalone program demonstrating the problem in a simple use-case, it creates multiple jars with just 1 resource in and then shows, when renaming the jars, how the old version of the jar is being used at the wrong time.
** Old resources, but new code **
It would appear in our test cases that if we execute code from this URLClassLoader through reflection, the *new* code executes, but the *old* resource streams are found by this new code.
** Data Corruption and SIGSEGV **
We have seen, in more complex use-cases, corruption of the values of the properties being returned, and have seen a sigsegv from Java 6 beta 2 we believe is due to this problem, the stack being attached too.
Conclusion
This bug prevents clean upgrade of java modules loaded into containers, they execute in a corrupted context and produce unexpected behavior. For example, if the port number used to offer a service comes from a property file, an old (incorrect) port number would be used.
Reproduced on:
solaris/sparc
linux/i386
with Java 6, Java 5, Java 1.4, Java 1.3
We believe, by reading 6349735, that it would not be possible to replace the jarfile
on windows. We can replace it on solaris and linux.