0

We have one URLUtils class which is coming from one internal maven dependency jar (Jar A), and this URLUtils class is also coming from another third-party maven dependency jar (Jar B). These both classes have same package name in these two jars.

Now there is another 3rd part dependency which has Jar B as dependency, and it is using URLUtils class from it. Even though the class and package names of URLUtils class in Jar A and Jar B is same but method signature is different.

Initially we don't know we have to URLUtils classes coming from two different jars and deployed it and it worked fine but after 12 days it started picking URLUtils class from Jar A and failing with ClassCastException.

We found the issue and removed the Jar A dependency from the project. But I am curious to know why JVM initially choosed URLUtils class from Jar B and suddenly switched to Jar A URLUtils class.

JVM: Corretto JDK 8

Charan2628
  • 41
  • 6
  • Based on reading the duplicates, the class found "first" on the class-path is the one used. But in general, it seems to completely depend on the `ClassLoader` implementation being used. Some frameworks (e.g., Java EE/Jakarta EE containers) can do some pretty, let's say "unorthodox", stuff with class loading. – Slaw Feb 22 '23 at 06:38

0 Answers0