0

We updated OJDBC driver in our application from OJDBC6 to OJDBC7. And got strange ClassCastException. Inside logs shows that at: oracle.jdbc.driver.BlockSource$ThreadedCachingBlockSource$BlockReleaserListener.(BlockSource.java:348) we got: java.lang.ClassCastException: sun.management.MemoryImpl cannot be cast to javax.management.NotificationEmitter

And we have no idea why this exception is appeared, because according the http://www.docjar.com/docs/api/sun/management/MemoryImpl.html MemoryImpl implements NotificationEmitter.

If we change JVM from Hotspot to the IBM (both JDK7), we got the same: java.lang.ClassCastException: com.ibm.lang.management.MemoryMXBeanImpl incompatible with javax.management.NotificationEmitter

And again MemoryMXBeanImpl implements NotificationEmitter.

So if anybody have the workaround or any idea why does it happens I'll be very grateful!

serg
  • 1,003
  • 3
  • 16
  • 26
  • Does `javax/management/NotificationEmitter.class` appear in two different sealed jars or could there be two versions of it loaded in different class loaders? – Mike Samuel May 20 '14 at 13:25
  • from logs I get:[Loaded javax.management.NotificationEmitter from C:\Program Files\Java\jdk1.7.0_17\jre\lib\rt.jar] and [Loaded javax.management.NotificationEmitter from file:/C:/development/newSRC/lib/j2ee/jars/j2ee.jar] so it seems I have to instances of the same interface, if there any way to say JVM not to use one of them? – serg May 20 '14 at 14:04
  • 1
    I think ["Multiple Versions of the same ..."](http://stackoverflow.com/questions/6105124/java-classpath-classloading-multiple-versions-of-the-same-jar-project) describes your problem. ["Handling multiple versions of the same class"](http://java.dzone.com/articles/java-classloader-handling) explains some solutions. One solution not mentioned is to force a parent classloader to load the class first, so the two different classloaders will not load it, but instead use the parent's. – Mike Samuel May 20 '14 at 14:46
  • Thank you Mike, after we make some order in the jars that we used, (actually, now starting to use j2ee.jar version without the javax.management package), everything starting works fine!!! – serg May 21 '14 at 11:50
  • Good to hear. Happy classloading. – Mike Samuel May 21 '14 at 14:00

0 Answers0