junixsocket icon indicating copy to clipboard operation
junixsocket copied to clipboard

[GraalVM] java.lang.ClassNotFoundException: org.newsclub.net.mysql.AFUNIXDatabaseSocketFactoryCJ

Open kohlschuetter opened this issue 2 years ago • 4 comments

As per @czp3009 in https://github.com/kohlschutter/junixsocket/issues/152

Caused by: java.lang.ClassNotFoundException: org.newsclub.net.mysql.AFUNIXDatabaseSocketFactoryCJ
        at org.graalvm.nativeimage.builder/com.oracle.svm.core.hub.ClassForNameSupport.forName(ClassForNameSupport.java:123) ~[na:na]
        at org.graalvm.nativeimage.builder/com.oracle.svm.core.hub.ClassForNameSupport.forName(ClassForNameSupport.java:87) ~[na:na]
        at [email protected]/java.lang.Class.forName(DynamicHub.java:1322) ~[identity-service:na]
        at [email protected]/java.lang.Class.forName(DynamicHub.java:1311) ~[identity-service:na]
        at com.mysql.cj.util.Util.getInstance(Util.java:187) ~[na:na]
        ... 142 common frames omitted

kohlschuetter avatar Apr 19 '24 13:04 kohlschuetter

@czp3009 Thanks for bringing this up!

I have fixed the cause and improved the tooling to prevent mysql-specific bugs with GraalVM. Please verify with the latest junixsocket-2.10.0-SNAPSHOT version.

kohlschuetter avatar Apr 19 '24 13:04 kohlschuetter

If I'm not mistaken, the latest code should be on the master branch. But after looking at the source code, I'm confused

reflect-config.json in junixsocket-mysql only add reflection hints for class in mysql package, not include AFUNIXDatabaseSocketFactoryCJ in junixsocket. In many cases, user use junixsockets via a JDBC url(it's string), in which case graalvm needs to dynamically reflect to a specific SocketFactory implementation class such as AFUNIXDatabaseSocketFactoryCJ. So I think it's important to at least include a reflection hint for this class

Another point of confusion is that, AFUNIXDatabaseSocketFactoryTest only test legacy SocketFactory, not CJ style SocketFactory. AFUNIXDatabaseSocketFactory and AFUNIXDatabaseSocketFactoryCJ are two different classes, and both may be used by user via JDBC url

A typical JDBC Url Usage: "jdbc:mysql://localhost/db?socketFactory=org.newsclub.net.mysql.AFUNIXDatabaseSocketFactoryCJ&junixsocket.file=/tmp/mysql.sock"

In summary, i think should add reflective hints for AFUNIXDatabaseSocketFactory and AFUNIXDatabaseSocketFactoryCJ to cover JDBC url usage

czp3009 avatar Apr 19 '24 18:04 czp3009

Ah, good point, you're right, @czp3009

I've updated the config file. Please re-test. Thanks!

kohlschuetter avatar Apr 19 '24 18:04 kohlschuetter

i read the new https://github.com/kohlschutter/junixsocket/blob/main/junixsocket-mysql/src/main/resources/META-INF/native-image/com.kohlschutter.junixsocket/junixsocket-mysql/reflect-config.json, it looks very well, thanks your work!

czp3009 avatar Apr 20 '24 12:04 czp3009

junixsocket 2.10.0 has been released. Please verify and re-open if necessary. Thanks again for reporting , @czp3009 !

kohlschuetter avatar Jul 09 '24 11:07 kohlschuetter