Home > database >  ClassLoader NullPointerException with Flyway 8.5.13 and Tomcat 9.0.70 - works with Tomcat 9.0.69
ClassLoader NullPointerException with Flyway 8.5.13 and Tomcat 9.0.70 - works with Tomcat 9.0.69

Time:12-16

We have a Spring Boot (2.6.7) application with Flyway 8.5.13 (Postgresql driver 42.2.9), Java 11.0.17

Yesterday we updated our tomcat from version 9.0.69 to 9.0.70 and now the application fails to start. The relevant log looks like this:

 Caused by: java.lang.NullPointerException
                at org.flywaydb.core.internal.resource.classpath.ClassPathResource.read(ClassPathResource.java:108)
                at org.flywaydb.core.internal.resolver.ChecksumCalculator.calculateChecksumForResource(ChecksumCalculator.java:64)
                at org.flywaydb.core.internal.resolver.ChecksumCalculator.calculate(ChecksumCalculator.java:43)
                at org.flywaydb.core.internal.resolver.sql.SqlMigrationResolver.getChecksumForLoadableResource(SqlMigrationResolver.java:127)
                at org.flywaydb.core.internal.resolver.sql.SqlMigrationResolver.addMigrations(SqlMigrationResolver.java:169)
                at org.flywaydb.core.internal.resolver.sql.SqlMigrationResolver.resolveMigrations(SqlMigrationResolver.java:71)
                at org.flywaydb.core.internal.resolver.sql.SqlMigrationResolver.resolveMigrations(SqlMigrationResolver.java:50)

Curiously, the migration files are correctly recognized beforehand by org.flywaydb.core.internal.scanner.classpath.ClassPathScanner and org.flywaydb.core.internal.resource.ResourceNameValidator

The source code where the exception occurs (org.flywaydb.core.internal.resource.classpath.ClassPathResource.read(ClassPathResource.java:108)) looks like this:

InputStream inputStream = null;
        try {
            Enumeration<URL> urls = classLoader.getResources(fileNameWithAbsolutePath);
            while (urls.hasMoreElements()) {
                URL url = urls.nextElement();
                if (url.getPath() != null && url.getPath().contains(parentURL)) {
                    inputStream = url.openStream();
                    break;
                }
            }
        } catch (IOException e) {
            throw new FlywayException(e);
        }

        if (inputStream == null) {
            throw new FlywayException("Unable to obtain inputstream for resource: "   fileNameWithAbsolutePath);
        }

Any ideas what could be the reason?

I tried several 8.5 versions of Flyway but there is no difference!

CodePudding user response:

Probably you stumbled upon bug BZ 66388, which has been recently fixed:

Booting our application on 9.0.70 fails because we are trying to read a the content of a classpath resource (sql file) having name containing a space. The file name is: 'com/aqme/product/database/migration/sql/_443/V443_17_36495__some name.sql'

  • Related