Bug #109508 GraalVM Image with connector j fails to run
Submitted: 2 Jan 2023 6:20 Modified: 3 Feb 2023 14:22
Reporter: Bharati Trivedi Email Updates:
Status: No Feedback Impact on me:
Category:Connector / J Severity:S3 (Non-critical)
Version: OS:Oracle Linux
Assigned to: Filipe Silva CPU Architecture:x86

[2 Jan 2023 6:20] Bharati Trivedi
I am trying to build a GraalVM image with mysql-connector.
The image builds but it fails at runtime with the following error:

java.sql.SQLNonTransientConnectionException: Cannot connect to MySQL server on localhost:3,306.

Make sure that there is a MySQL server running on the machine/port you are trying to connect to and that the machine this software is running on is able to connect to this host/port (i.e. not firewalled). Also make sure that the server has not been started with the --skip-networking flag.

	at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:110)
	at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97)
	at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:89)
	at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:63)
	at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:73)
	at com.mysql.cj.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:462)
	at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:241)
	at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:198)
	at java.sql@11.0.17/java.sql.DriverManager.getConnection(DriverManager.java:677)
	at java.sql@11.0.17/java.sql.DriverManager.getConnection(DriverManager.java:228)
	at com.oracle.mysql.test.LoadDriver.main(LoadDriver.java:21)
Caused by: java.lang.ClassCastException: com.mysql.cj.exceptions.CJException cannot be cast to com.mysql.cj.exceptions.UnableToConnectException
	at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:825)
	at com.mysql.cj.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:448)

How to repeat:
Create a jdbc connection to mysql using connector/j
Create a GraalVM image for this connection.
Run this GraalVM image.
[2 Jan 2023 18:22] Filipe Silva
Hi Bharati,

Thank you for your interest in MySQL Connector/J.

You are running Connector/J from source code locally compiled, aren't you?

If so, please try using the binaries from the officially distributed bundles.
[3 Jan 2023 9:48] MySQL Verification Team
I'm not sure whether this is relevant here but looking at the error message "Cannot connect to MySQL server on localhost:3,306".  Maybe worth checking "port" details? Shouldn't be "3306" and not "3,306"? Thank you.

[3 Jan 2023 14:22] MySQL Verification Team

Please let us know if your problem has been resolved by our recommendations .......
[3 Jan 2023 16:03] Filipe Silva
The "bad" stack trace shown here is related to Bug#91968. It's not possible to tell this a duplicate bug, though, since we don't see the real reason why the connection is not established.

It is known that GraalVM Native Image doesn't support all Java features, namely reflection, which is the source of all these problems. However, it seems it is possible to configure the application and GraalVM in such a way that most of the reflection features end up being supported.

I would recommend configuring the application/GraalVM following the documentation/suggestions mentioned in the Bug#91968 to see if that helps. This will, most likely, require searching the source code to find all places reflection is used - https://github.com/mysql/mysql-connector-j.

Regardless, it's up to you to decide whether you should trust on a solution using GraalVM Native Image knowing about its limitations and how they affect Connector/J. Chances are that there may be others not known yet.

We shall keep this report in "Need Feedback" status. Please share your findings if you decide to continue.

[4 Feb 2023 1:00] Bugs System
No feedback was provided for this bug for over a month, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".