6

My webapplication throws the following ClassCastException:

java.lang.ClassCastException: org.postgresql.jdbc4.Jdbc4ResultSetMetaData
cannot be cast to org.postgresql.jdbc4.Jdbc4ResultSetMetaData

Obviously the classes are the same, so this is a strange error to get.

I found out by using -verbose:class that the class Jdbc4ResultSetMetaData gets loaded from two jar files, one in my Jetty lib/ext/ directory and from a /WEB-INF/lib directory in my webapplication. These jar files are exactly the same version (md5sum identical)

This leads me to believe that it is indeed exactly the same class, but the ClassCastException might be caused by two different classloaders loading the same class.

Is it possible to log/trace the name or id of the classloader which loads the classes with a jvm parameter?

Cloud
  • 458
  • 1
  • 13
  • 34
  • 1
    http://stackoverflow.com/questions/826319/classcastexception-when-casting-to-the-same-class – Suresh Atta Jan 11 '17 at 09:19
  • you can get the class loader name thru `object.getClass().getClassLoader()` – M Sach Jan 11 '17 at 09:30
  • With this suggested code changes I can not log the classloader for both loaded classes at startup. (only for the specific class that I try to cast) That is why I asked specifically for a vm argument or logging configuration, so that the classloader for each class is logged. – Cloud Jan 11 '17 at 09:35
  • 1
    @sᴜʀᴇsʜ ᴀᴛᴛᴀ: I think this is not a duplicate because of the reasons mentioned in the (edit) comments. – Cloud Jan 11 '17 at 09:52
  • I don't think this as a dupe either - the linked question does not seem to provide help with finding out which classloaders loaded the classes. – Hulk Jan 11 '17 at 10:43

0 Answers0