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

ClassCastException in AndroidScanner #1474

Closed
benoitdevos opened this issue Nov 22, 2016 · 2 comments
Closed

ClassCastException in AndroidScanner #1474

benoitdevos opened this issue Nov 22, 2016 · 2 comments

Comments

@benoitdevos
Copy link
Contributor

Flyway sometimes crashes on Android 4.2 - 4.4, because a wrong ClassLoader is injected in AndroidScanner.
java.lang.ClassCastException: android.app.LoadedApk$WarningContextClassLoader cannot be cast to dalvik.system.PathClassLoader
It is not clear why Android sometimes decides to use this WarningContextClassLoader, but it's a valid ClassLoader and should then be supported by Flyway.

What version of Flyway are you using?

4.0.2

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

Java API

What database are you using (type & version)?

SQLiteDatabase
(android.database.sqlite.SQLiteDatabase, api level 24 )

What operating system are you using?

Android 4.2 (JellyBean), Android 4.4 (KitKat)

What did you do?

(Please include the content causing the issue, any relevant configuration settings, and the command you ran)

        DroidDataSource dataSource = new DroidDataSource(context.getPackageName() + "/databases", dbName);
        ContextHolder.setContext(context);
        flyway = new Flyway();
        flyway.setDataSource(dataSource);
        flyway.setBaselineVersionAsString("1.0");
        flyway.setBaselineOnMigrate(true);
        flyway.setBaselineDescription("Initial baseline");
        flyway.info();

where context is the Application Context of my Android App.

What did you expect to see?
What did you see instead?

An exception is thrown :

java.lang.ClassCastException: android.app.LoadedApk$WarningContextClassLoader cannot be cast to dalvik.system.PathClassLoader
    org.flywaydb.core.internal.util.scanner.classpath.android.AndroidScanner.<init> (AndroidScanner.java:46)
    org.flywaydb.core.internal.util.scanner.Scanner.<init> (Scanner.java:38)
    org.flywaydb.core.Flyway.execute (Flyway.java:1353)
    org.flywaydb.core.Flyway.info (Flyway.java:1040)
@benoitdevos
Copy link
Contributor Author

A pull request has been submitted.

axelfontaine pushed a commit that referenced this issue Jan 25, 2017
Fixed ClassCastException in AndroidScanner #1474
axelfontaine pushed a commit to flyway/flywaydb.org that referenced this issue Jan 25, 2017
@axelfontaine axelfontaine added this to the Flyway 4.1 milestone Jan 25, 2017
@axelfontaine
Copy link
Contributor

PR merged. Thanks!

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

No branches or pull requests

2 participants