kohlschutter / junixsocket

Unix Domain Sockets in Java 7 and newer (AF_UNIX), AF_TIPC, AF_VSOCK, and more
Apache License 2.0
438 stars 114 forks source link

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

Closed kohlschuetter closed 4 months ago

kohlschuetter commented 6 months ago

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 java.base@17.0.10/java.lang.Class.forName(DynamicHub.java:1322) ~[identity-service:na]
        at java.base@17.0.10/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 commented 6 months ago

@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.

czp3009 commented 6 months ago

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

kohlschuetter commented 6 months ago

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

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

czp3009 commented 6 months ago

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!

kohlschuetter commented 4 months ago

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