When I try to create a native image of a trivial app that connects to postgres I get somewhat cryptic errors "Parameter _X_ of _method_ has declared type _classImpl_ which is incompatible with types in state:".
error: unsupported features in 48 methods
Detailed message:
Error: Parameter 0 of org.postgresql.core.SetupQueryRunner.run(QueryExecutor, String, boolean) has declared type org.postgresql.core.QueryExecutor which is incompatible with types in state: 1TypeMObject<[0x0000096E00008CDF:!S:QueryExecutorImpl]>
Call path from entry point to org.postgresql.core.SetupQueryRunner.run(QueryExecutor, String, boolean):
at org.postgresql.core.SetupQueryRunner.run(SetupQueryRunner.java:43)
at org.postgresql.core.v3.ConnectionFactoryImpl.isMaster(ConnectionFactoryImpl.java:745)
at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:256)
at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:49)
at org.postgresql.jdbc.PgConnection.<init>(PgConnection.java:195)
at org.postgresql.Driver.makeConnection(Driver.java:454)
at org.postgresql.Driver.connect(Driver.java:256)
at java.sql.DriverManager.getConnection(DriverManager.java:664)
at java.sql.DriverManager.getConnection(DriverManager.java:270)
at lumgraal.App.main(App.java:18)
at com.oracle.svm.core.JavaMainWrapper.run(JavaMainWrapper.java:163)
at com.oracle.svm.core.code.CEntryPointCallStubs.com_002eoracle_002esvm_002ecore_002eJavaMainWrapper_002erun_0028int_002corg_002egraalvm_002enativeimage_002ec_002etype_002eCCharPointerPointer_0029(generated:0)
...
What is the problem and what is a suggested workaround?
The repo to reproduce the issue: https://github.com/katox/graal-pg-client
@katox the repo to reproduce is missing pom.xml.
@cstancu I copied wrong .gitignore into the repo. pom.xml re-added, sorry.
@katox the issue is a side effect of the problems we currently have with building native images from apps with an incomplete class path, i.e., the code references a library that is missing from the classpath. The underlying exception that is the cause of the issue you see is: java.lang.ClassNotFoundException: waffle.windows.auth.IWindowsCredentialsHandle. This exception is not correctly captured by --report-unsupported-elements-at-runtime currently. We are working on a solution for incomplete classpaths, in the meantime you can try adding the missing dependency to the classpath, if your code doesn't actually need it, as a workaround.
@cstancu thank you. How can I log the underlying exception? I added waffle-jna and its dependencies but I ended up in the same situation with the same error message. Something else is probably missing as well.
There is only one place that needs IWindowsCredentialsHandle and that is SSPIClient. The SSPIClient is instanciated in a single place (dynamically via Class.forName), in org.postgresql.core.v3.ConnectionFactoryImpl/createSSPI(...).
I'm sure that the code is not needed because I run it on Linux and the code depends on win32-only JNA library. I tried to @Substitute the createSSPI method (see `stub.InternalConnectionFactoryImpl) in order to prune all code in this path but it doesn't seem to work that way.
I updated the repo with a new image creation script and extended logging in the App.
Update: unlike rc7 it seems to generate a working image when using the current git master native-image (using the suggested workaround). Nice!
@katox thanks for your work on this which helped me get started. I have found one problem which is if I make a static native image then the binary will segault when trying to establish the Postgres connection - org.postgresql.core.v3.ConnectionFactoryImpl.tryConnect().
If I leave off the static flag then it works.
Test repo here: https://github.com/emrul/testjdbc
@emrul yes, the static linking still doesn't work.
It's a separate issue, I opened #1054, closing this one.