1

We have a strange issue with two Java processes A and B that load same jar file (not 2 separate copies of the same file, same actual file).

The .jar file was replaced with a newer copy (renamed to .jar_BACK, then a new file copied in its pace), and one of the Java processes (A) restarted. The other Java process (B) keeps running.

Process A works without any problem.

Process B gets a NoClassDefFoundError exception when it tries to use one of the classes in the .jar we updated. The class that is "not found" was already loaded before.

Investigation by jar -x shows that the "missing" class is actually present in both old and new version of the jar, in same location within the jar file and the class itself is unchanged.

Restarting process B fixes the problem.

What would be causing such a behavior?

My current guess is: either standard Java classloader or some custom classloader invalidates classes from a jar when .jar file is renamed. But I can't find any documentation on this, and my previous understanding was that classloader does not do any such monitoring for missing .jar files.

I am pretty sure we're not using any custom class loaders, either.

Java version: 1.8.0_144-b01

OS version: Red Hat Enterprise Linux Server release 6.9 (Santiago)

  • Attempt to reproduce the behavior with plain single-class jars did not succeed –  Nov 01 '17 at 20:08

1 Answers1

0

I believe your issue stems from the fact that you changed the name of the jar and tried to overwrite it with a different file of the same name. The JVM doesn't like that. This question probably has the details you want.

ScarySpider
  • 139
  • 5
  • Thank you. I saw that question. Could you point me at the relevant details? The closest thing I see so far is a comment by H2ONaCl : "On Ubuntu and Oracle's JDK I experienced an NoClassDefined exception and I believe the most likely explanation was an overwrite of the JAR while the previous version was running.". That is a sign that another user experienced the same problem, but not necessarily an explanation of why the problem occurs –  Nov 01 '17 at 20:57
  • In any case, I will try testing what you're saying with simple jars and let you know. –  Nov 01 '17 at 21:03
  • Did not pan out. After `mv` and `cp` the simple example kept running. –  Nov 01 '17 at 21:07