Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GraalVM integration with Micronaut broken in 7.8.2 because some Oracle changes #3175

Closed
ilopmar opened this issue May 17, 2021 · 2 comments
Closed

Comments

@ilopmar
Copy link

ilopmar commented May 17, 2021

Which version and edition of Flyway are you using?

Flyway Community Edition 7.8.2

If this is not the latest version, can you reproduce the issue with the latest one as well? (Many bugs are fixed in newer releases and upgrading will often resolve the issue)

Yes, same error happens with 7.9.0

Which client are you using? (Command-line, Java API, Maven plugin, Gradle plugin)

Java API

Which database are you using? (Type & version)

H2, but it happens with others as well.

Which operating system are you using?

Linux Mint 20.1

What did you do? (Please include the content causing the issue, any relevant configuration settings, the SQL statement(s) that failed (if any), and the command you ran)

I've tried to upgrade Micronaut Flyway integration from 7.7.3 to latest version but I've discovered that our GraalVM integration breaks with Flyway 7.8.2. It works with previous versions.

I've been trying Flyway snapshots locally with different commits, and the commit that breaks the integration is ece001f. With commits before it, everything works although some changes you did related to Oracle before that commit produces the following warning when creating the native image:

[flyway-h2:101121]    classlist:   2,144.65 ms,  1.94 GB
[flyway-h2:101121]        (cap):     411.67 ms,  1.94 GB

/////////////////////// THIS IS THE WARNING ///////////////////////
WARNING: Could not resolve oracle.jdbc.OracleConnection for reflection configuration. Reason: java.lang.ClassNotFoundException: oracle.jdbc.OracleConnection.
///////////////////////////////////////////////////////////////////
[flyway-h2:101121]        setup:   1,919.29 ms,  1.94 GB
15:34:43.971 [ForkJoinPool-4-worker-9] DEBUG i.m.flyway.graalvm.FlywayFeature - Adding application migrations in path 'file:/home/ivan/workspaces/micronaut-graal-tests/micronaut-flyway-graal/build/libs/micronaut-flyway-graal-0.1-all.jar!/databasemigrations' using protocol 'jar'
15:34:43.985 [ForkJoinPool-4-worker-9] TRACE i.m.flyway.graalvm.FlywayFeature - Discovered path: databasemigrations/V1__init.sql
15:34:43.985 [ForkJoinPool-4-worker-9] TRACE i.m.flyway.graalvm.FlywayFeature - Discovered path: databasemigrations/R__add-view.sql
15:34:43.985 [ForkJoinPool-4-worker-9] TRACE i.m.flyway.graalvm.FlywayFeature - Discovered path: databasemigrations/V2__testdata.sql
15:34:43.985 [ForkJoinPool-4-worker-9] DEBUG i.m.flyway.graalvm.FlywayFeature - Adding application migrations in path 'file:/home/ivan/workspaces/micronaut-graal-tests/micronaut-flyway-graal/build/libs/micronaut-flyway-graal-0.1-all.jar!/other' using protocol 'jar'
15:34:43.995 [ForkJoinPool-4-worker-9] TRACE i.m.flyway.graalvm.FlywayFeature - Discovered path: other/V3__testdata2.sql
[flyway-h2:101121]     (clinit):   1,198.16 ms,  4.94 GB
[flyway-h2:101121]   (typeflow):  23,951.49 ms,  4.94 GB
[flyway-h2:101121]    (objects):  38,659.24 ms,  4.94 GB
[flyway-h2:101121]   (features):   2,833.99 ms,  4.94 GB
[flyway-h2:101121]     analysis:  71,106.50 ms,  4.94 GB
[flyway-h2:101121]     universe:   2,465.55 ms,  4.94 GB
[flyway-h2:101121]      (parse):   5,457.02 ms,  4.90 GB
[flyway-h2:101121]     (inline):   5,771.14 ms,  5.57 GB
[flyway-h2:101121]    (compile):  49,305.22 ms,  7.62 GB
[flyway-h2:101121]      compile:  63,793.55 ms,  7.62 GB
[flyway-h2:101121]        image:   6,164.85 ms,  7.65 GB
[flyway-h2:101121]        write:     851.01 ms,  7.65 GB
# Printing build artifacts to: flyway-h2.build_artifacts.txt
[flyway-h2:101121]      [total]: 148,734.09 ms,  7.65 GB

Even with that warning it works.

After the changes introduced in ece001f I see more warnings like the one showed before that make the native image fails during startup:

[flyway-h2:101957]    classlist:   2,505.21 ms,  2.21 GB
[flyway-h2:101957]        (cap):     411.13 ms,  2.21 GB
WARNING: Could not resolve oracle.jdbc.OracleConnection for reflection configuration. Reason: java.lang.ClassNotFoundException: oracle.jdbc.OracleConnection.
[flyway-h2:101957]        setup:   2,002.81 ms,  2.21 GB
15:38:00.870 [ForkJoinPool-4-worker-9] DEBUG i.m.flyway.graalvm.FlywayFeature - Adding application migrations in path 'file:/home/ivan/workspaces/micronaut-graal-tests/micronaut-flyway-graal/build/libs/micronaut-flyway-graal-0.1-all.jar!/databasemigrations' using protocol 'jar'
15:38:00.887 [ForkJoinPool-4-worker-9] TRACE i.m.flyway.graalvm.FlywayFeature - Discovered path: databasemigrations/V1__init.sql
15:38:00.888 [ForkJoinPool-4-worker-9] TRACE i.m.flyway.graalvm.FlywayFeature - Discovered path: databasemigrations/R__add-view.sql
15:38:00.888 [ForkJoinPool-4-worker-9] TRACE i.m.flyway.graalvm.FlywayFeature - Discovered path: databasemigrations/V2__testdata.sql
15:38:00.888 [ForkJoinPool-4-worker-9] DEBUG i.m.flyway.graalvm.FlywayFeature - Adding application migrations in path 'file:/home/ivan/workspaces/micronaut-graal-tests/micronaut-flyway-graal/build/libs/micronaut-flyway-graal-0.1-all.jar!/other' using protocol 'jar'
15:38:00.900 [ForkJoinPool-4-worker-9] TRACE i.m.flyway.graalvm.FlywayFeature - Discovered path: other/V3__testdata2.sql
WARNING: Could not register reflection metadata for org.flywaydb.core.internal.database.oracle.OracleDatabaseType. Reason: java.lang.NoClassDefFoundError: oracle/jdbc/OracleConnection.
WARNING: Could not register reflection metadata for org.flywaydb.core.internal.database.oracle.OracleDatabaseType. Reason: java.lang.NoClassDefFoundError: oracle/jdbc/OracleConnection.
WARNING: Could not register reflection metadata for org.flywaydb.core.internal.database.oracle.OracleDatabaseType. Reason: java.lang.NoClassDefFoundError: oracle/jdbc/OracleConnection.
WARNING: Could not register reflection metadata for org.flywaydb.core.internal.database.oracle.OracleDatabaseType. Reason: java.lang.NoClassDefFoundError: oracle/jdbc/OracleConnection.
WARNING: Could not register reflection metadata for org.flywaydb.core.internal.database.oracle.OracleDatabaseType. Reason: java.lang.NoClassDefFoundError: oracle/jdbc/OracleConnection.
WARNING: Could not register reflection metadata for org.flywaydb.core.internal.database.oracle.OracleDatabaseType. Reason: java.lang.NoClassDefFoundError: oracle/jdbc/OracleConnection.
WARNING: Could not register reflection metadata for org.flywaydb.core.internal.database.oracle.OracleDatabaseType. Reason: java.lang.NoClassDefFoundError: oracle/jdbc/OracleConnection.
WARNING: Could not register reflection metadata for org.flywaydb.core.internal.database.oracle.OracleDatabaseType. Reason: java.lang.NoClassDefFoundError: oracle/jdbc/OracleConnection.
[flyway-h2:101957]     (clinit):   1,203.60 ms,  4.90 GB
[flyway-h2:101957]   (typeflow):  24,893.73 ms,  4.90 GB
[flyway-h2:101957]    (objects):  39,676.26 ms,  4.90 GB
[flyway-h2:101957]   (features):   3,137.52 ms,  4.90 GB
[flyway-h2:101957]     analysis:  73,205.58 ms,  4.90 GB
[flyway-h2:101957]     universe:   2,601.53 ms,  4.96 GB
[flyway-h2:101957]      (parse):   5,406.28 ms,  4.80 GB
[flyway-h2:101957]     (inline):   9,398.99 ms,  7.29 GB
[flyway-h2:101957]    (compile):  42,152.49 ms,  7.65 GB
[flyway-h2:101957]      compile:  60,272.17 ms,  7.65 GB
[flyway-h2:101957]        image:   6,434.64 ms,  7.59 GB
[flyway-h2:101957]        write:     870.08 ms,  7.59 GB
# Printing build artifacts to: flyway-h2.build_artifacts.txt
[flyway-h2:101957]      [total]: 148,121.61 ms,  7.59 GB

See all the previous WARNING: Could not register reflection metadata for org.flywaydb.core.internal.database.oracle.OracleDatabaseType. Reason: java.lang.NoClassDefFoundError: oracle/jdbc/OracleConnection.

I'm not really sure why that change makes all those warnings but it only happens with Oracle when it's not in the classpath.

Is there a way you can implement ece001f in another way that is "GraalVM native-image friendly" or check if Oracle is being used before trying to detect if Hikari is beings used?

What did you expect to see?

I expect to be able to create the native image without warnings about Oracle when not using Oracle (as in my example that I'm using H2) and run the native image without errors.

What did you see instead?

I see warnings during native image generation and the following error when starting the native-image

 __  __ _                                  _   
|  \/  (_) ___ _ __ ___  _ __   __ _ _   _| |_ 
| |\/| | |/ __| '__/ _ \| '_ \ / _` | | | | __|
| |  | | | (__| | | (_) | | | | (_| | |_| | |_ 
|_|  |_|_|\___|_|  \___/|_| |_|\__,_|\__,_|\__|
  Micronaut (v3.0.0-SNAPSHOT)

15:41:20.814 [main] INFO  com.zaxxer.hikari.HikariDataSource - HikariPool-1 - Starting...
15:41:20.819 [main] INFO  com.zaxxer.hikari.HikariDataSource - HikariPool-1 - Start completed.
15:41:20.821 [main] DEBUG o.f.c.i.s.classpath.ClassPathScanner - Scanning for classpath resources at 'classpath:db/callback' ...
15:41:20.821 [main] DEBUG o.f.c.i.s.classpath.ClassPathScanner - Determining location urls for classpath:db/callback using ClassLoader sun.misc.Launcher$AppClassLoader@18b4aac2 ...
15:41:20.821 [main] DEBUG o.f.c.i.s.classpath.ClassPathScanner - Unable to resolve location classpath:db/callback.
15:41:20.821 [main] INFO  i.m.flyway.AbstractFlywayMigration - Running migrations for database with qualifier [default]
15:41:20.821 [main] INFO  o.f.c.i.license.VersionPrinter - Flyway Community Edition 7.8.2 by Redgate
15:41:20.821 [main] ERROR io.micronaut.runtime.Micronaut - Error starting Micronaut server: Bean definition [javax.sql.DataSource] could not be loaded: org.flywaydb.core.internal.database.DatabaseType: Provider org.flywaydb.core.internal.database.oracle.OracleDatabaseType could not be instantiated
io.micronaut.context.exceptions.BeanInstantiationException: Bean definition [javax.sql.DataSource] could not be loaded: org.flywaydb.core.internal.database.DatabaseType: Provider org.flywaydb.core.internal.database.oracle.OracleDatabaseType could not be instantiated
	at io.micronaut.context.DefaultBeanContext.initializeContext(DefaultBeanContext.java:1859)
	at io.micronaut.context.DefaultApplicationContext.initializeContext(DefaultApplicationContext.java:234)
	at io.micronaut.context.DefaultBeanContext.readAllBeanDefinitionClasses(DefaultBeanContext.java:3355)
	at io.micronaut.context.DefaultBeanContext.start(DefaultBeanContext.java:236)
	at io.micronaut.context.DefaultApplicationContext.start(DefaultApplicationContext.java:180)
	at io.micronaut.runtime.Micronaut.start(Micronaut.java:71)
	at io.micronaut.runtime.Micronaut.run(Micronaut.java:311)
	at io.micronaut.runtime.Micronaut.run(Micronaut.java:297)
	at micronaut.example.Application.main(Application.java:8)
Caused by: java.util.ServiceConfigurationError: org.flywaydb.core.internal.database.DatabaseType: Provider org.flywaydb.core.internal.database.oracle.OracleDatabaseType could not be instantiated
	at java.util.ServiceLoader.fail(ServiceLoader.java:232)
	at java.util.ServiceLoader.access$100(ServiceLoader.java:185)
	at java.util.ServiceLoader$LazyIterator.nextService(ServiceLoader.java:384)
	at java.util.ServiceLoader$LazyIterator.next(ServiceLoader.java:404)
	at java.util.ServiceLoader$1.next(ServiceLoader.java:480)
	at org.flywaydb.core.internal.database.DatabaseTypeRegister.registerDatabaseTypes(DatabaseTypeRegister.java:58)
	at org.flywaydb.core.internal.database.DatabaseTypeRegister.getDatabaseTypeForConnection(DatabaseTypeRegister.java:130)
	at org.flywaydb.core.internal.jdbc.JdbcConnectionFactory.<init>(JdbcConnectionFactory.java:69)
	at org.flywaydb.core.Flyway.execute(Flyway.java:505)
	at org.flywaydb.core.Flyway.migrate(Flyway.java:165)
	at io.micronaut.flyway.AbstractFlywayMigration.runFlyway(AbstractFlywayMigration.java:100)
	at io.micronaut.flyway.AbstractFlywayMigration.forceRun(AbstractFlywayMigration.java:85)
	at io.micronaut.flyway.AbstractFlywayMigration.run(AbstractFlywayMigration.java:65)
	at io.micronaut.flyway.DataSourceMigrationRunner.lambda$null$0(DataSourceMigrationRunner.java:65)
	at java.util.Optional.ifPresent(Optional.java:159)
	at io.micronaut.flyway.DataSourceMigrationRunner.lambda$onCreated$1(DataSourceMigrationRunner.java:63)
	at java.util.Optional.ifPresent(Optional.java:159)
	at io.micronaut.flyway.DataSourceMigrationRunner.onCreated(DataSourceMigrationRunner.java:60)
	at io.micronaut.flyway.DataSourceMigrationRunner.onCreated(DataSourceMigrationRunner.java:37)
	at io.micronaut.context.DefaultBeanContext.doCreateBean(DefaultBeanContext.java:2312)
	at io.micronaut.context.DefaultBeanContext.createAndRegisterSingletonInternal(DefaultBeanContext.java:3200)
	at io.micronaut.context.DefaultBeanContext.createAndRegisterSingleton(DefaultBeanContext.java:3186)
	at io.micronaut.context.DefaultBeanContext.loadContextScopeBean(DefaultBeanContext.java:2574)
	at io.micronaut.context.DefaultBeanContext.initializeContext(DefaultBeanContext.java:1853)
	... 8 common frames omitted
Caused by: java.lang.InstantiationException: Type `org.flywaydb.core.internal.database.oracle.OracleDatabaseType` can not be instantiated reflectively as it does not have a no-parameter constructor or the no-parameter constructor has not been added explicitly to the native image.
	at java.lang.Class.newInstance(DynamicHub.java:909)
	at java.util.ServiceLoader$LazyIterator.nextService(ServiceLoader.java:380)
	... 29 common frames omitted
More information

I already opened #2927 asking about including GraalVM support directly in the library so frameworks and users don't need to worry about it. I'm still happy to help with it but as mentioned in that issue I don't know the internals of the library.

I'm able to provide a reproducer if you want to dig into it, but I'm not sure at this moment if it's really helpful or not, so please ask me about it if you need it.

@DoodleBobBuffPants
Copy link
Contributor

I believe this is related to #3163 so closing this as a duplicate, and we will look at merging that PR soon

@ilopmar
Copy link
Author

ilopmar commented May 17, 2021

Thanks @DoodleBobBuffPants. I've already commented in that PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants