Getting java.lang.ClassCastException exceptions in log file
Asked by Eric Zago:

I have a newly installed Confluence server installation, running with a MySQL 8.0.23 database on Ubuntu 20.04.1. I started with Confluence 7.10.2, and then upgraded it to 7.11.1. The error message below happened both before the upgrade and after.

The atlassian-confluence.log gets full of repeated entries similar to the following:

---------------------------

2021-03-01 13:12:32,383 ERROR \[Caesium-1-3\] \[migration.agent.queue.QueueBroker\] error An error occurred when getting the next batch for consumer type: USERS_MIGRATION. Message: java.l\>com.atlassian.util.concurrent.LazyReference$InitializationException: java.lang.ClassCastException: class java.time.LocalDateTime cannot be cast to class java.lang.String (java.time.Lo\> at com.atlassian.util.concurrent.LazyReference.getInterruptibly(LazyReference.java:149)  
at com.atlassian.util.concurrent.LazyReference.get(LazyReference.java:112)  
at com.atlassian.migration.agent.store.jpa.impl.DefaultSessionFactorySupplier.get(DefaultSessionFactorySupplier.java:65)...

---------------------------

Instead of "USERS_MIGRATION" - it repeats a similar error with "CONFLUENCE_EXPORT" - "DATA_UPLOAD" - "ATTACHMENT_UPLOAD" - "CONFLUENCE_IMPORT" - in sequence, cycling through those errors. They seem to get recorded every 10 seconds or so in the log.

I've searched here in the forums, but can't find this mentioned similarly.

Is this a real actual error, or just a warning? Is there a resolution to clean this up so that the log file is more useful?

If additional information would be useful to help diagnose, please let me know.

Thanks, - Eric


Answers:
author: line hammer
body: The exaception thrown to indicate that your code has attempted to cast an object to a subclass of which it is not an instance. This means that ClassCastException occurs when you try to cast an instance of an Object to a type that it is not. [Type Casting](http://net-informations.com/java/basics/casting.htm) only works when the casted object follows an is a relationship to the type you are trying to cast to.

It is good practice to guard any explicit casts with an instanceof check first:

if (myApple instanceof Fruit) {  
Fruit myFruit = (Fruit)myApple;  
}

When will be ClassCastException is thrown:

* When you try to cast an object of Parent class to its Child class type, this exception will be thrown.
* When you try to cast an object of one class into another class type that has not extended the other class or they don't have any relationship between them.


author: Charlie Misonne
body: Hi Eric,

I stumbled upon this post whil dealing with the same issue and want to share my solution.

This is a change in the 8.0.23 mysql driver: <https://bugs.mysql.com/bug.php?id=102435>. So it's not a bug but a change.

I'd suggest to use driver 8.0.22 which works for me.

comments: author: John Ainhirn-Williams
body: Thanks Charlie, works for me too


author: Charlie Misonne
body: Update:

The right driver can be downloaded from <https://dev.mysql.com/downloads/>. You should select **Connector/J** . J stands for Java wich is the technology Confluence runs on.  
Then click archives and choose 8.0.22. For Operating System I always use *platform indepentent* and wonload the zip or tar.gz file. The jar file is in the zip file.  
Direct URL: <https://downloads.mysql.com/archives/get/p/3/file/mysql-connector-java-8.0.22.zip>

[@Eric Zago](/t5/user/viewprofilepage/user-id/4234614) I noticed you asked this in one of the other questions but I tried to keep the solution clear on this post.


author: Eric Zago
body: Thanks I think I've tried this before, but Confluence would not run.

My Ubuntu 20.04.2 server is currently running with mysql 8.0.26

When one swaps the mysql-connector-java-8.0.22.jar file into /opt/atlassian/confluence/confluence/WEB-INF/lib/ - do you also have to down grade the version of mysql that is installed? Or should it work to have mysql 8.0.26 running with the 8.02.22.jar file?

Thanks - I have some system downtime scheduled soon and am happy to try again, just want to have a good plan in mind.

-Eric


author: ??????? ????
body: Thanks Stan

It resolved problem


author: Stan
body: alright, I was able to resolve this issue by downgrading mysql database driver from **mysql-connector-java-8.0.23** to **mysql-connector-java-5.1.42**

comments: author: Eric Zago
body: I am circling around back to this issue - I'm don't seem to fully understand the solution. When installing, I downloaded the mysql-connector-java_8.0.23-1ubuntu20.10_all.deb file from downloads.mysql.com, installed it with dpkg, and then copied the mysql-connector-java-8.0.23.jar file from /usr/share/java/ to /opt/atlassian/confluence/confluence/WEB-INF/lib/ - and it works (well, except for the errors in the log mentioned above.

Today I downloaded mysql-connector-java-5.1.42.tar.gz - since there does not seem to be a .deb file available from downloads.mysql.com for 5.1.42. I copied the mysql-connector-java-5.1.42-bin.jar into the /usr/share/java/ and /opt/atlassian/confluence/confluence/WEB-INF/lib/ directories, rebooted for good measure, and now when the atlassian-confluence.log file shows:

*2021-05-11 09:11:09,474 ERROR \[Catalina-utility-2\] \[confluence.impl.setup.DefaultBootstrapDatabaseAccessor\] getBootstrapData Unable to open database connection during bootstrap.
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure*

Which suggests to me that what I've downloaded isn't the right thing, since it is not able to make a database connection. I was able to put back the mysql-connector-java-8.0.23.jar file into the above two directories, and I'm able to restart Confluence and it runs (but once again, with those same errors as above.

Can someone help point out what I'm missing?

Thanks, -Eric


author: Stan
body: experiencing the same issue right now, [@Eric Zago](/t5/user/viewprofilepage/user-id/4234614) did you figure out?


Tags: confluence-server

server