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

NullPointerException in quoteReplacement #725

Closed
llidija opened this issue Apr 14, 2014 · 4 comments
Closed

NullPointerException in quoteReplacement #725

llidija opened this issue Apr 14, 2014 · 4 comments
Labels
Milestone

Comments

@llidija
Copy link

@llidija llidija commented Apr 14, 2014

Hi,

We were using flyway-maven-plugin 2.2 and we just upgraded to 2.3. We're doing the database migration with mvn flyway:migrate.

Until some point in time the migrations worked perfectly. But we started to get some errors and we can't get it to migrate with mvn flyway:migration anymore.

Prior the upgrade (using version 2.2) we got the same error as described here: #575.
There's no error with our SQL files. If I copy & paste the SQL file contents into the mysql client, the statements are successfully executed.

After the upgrade (now using version 2.3) we indeed get an error. Find the stacktrace below.

As I understand there's some error replacing the placeholders.

This is our pom definition for flyway plugin:

        <plugin>
            <groupId>com.googlecode.flyway</groupId>
            <artifactId>flyway-maven-plugin</artifactId>
            <version>2.3</version>
            <configuration>
                <!-- defined in company pom -->
                <driver>com.mysql.jdbc.Driver</driver>
                <url>${database.url}</url>
                <serverId>${database.serverId}</serverId>
                <locations>
                    <location>${migration.location}</location>
                </locations>
                <placeholders>
                    <database>${database.name}</database>
                    <useLocal>${database.local}</useLocal>
                </placeholders>
                <placeholderPrefix>$[</placeholderPrefix>
                <placeholderSuffix>]</placeholderSuffix>
            </configuration>
            <dependencies>
                <dependency>
                    <groupId>mysql</groupId>
                    <artifactId>mysql-connector-java</artifactId>
                    <version>5.1.18</version>
                </dependency>
            </dependencies>
        </plugin>

Any help would be appreciated.

Kind regards,
Lidija

Java stacktrace:

[INFO] Current version of schema najdi_news_dev: 019
[INFO] Migrating schema najdi_news_dev to version 020
[DEBUG] Rolling back transaction...
[DEBUG] Transaction rolled back
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.017s
[INFO] Finished at: Mon Apr 14 13:28:13 CEST 2014
[INFO] Final Memory: 15M/981M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal com.googlecode.flyway:flyway-maven-plugin:2.3:migrate (default-cli) on project najdi-persistence: java.lang.NullPointerException -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal com.googlecode.flyway:flyway-maven-plugin:2.3:migrate (default-cli) on project najdi-persistence: java.lang.NullPointerException
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:217)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)
at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:320)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156)
at org.apache.maven.cli.MavenCli.execute(MavenCli.java:537)
at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:141)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409)
at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352)
Caused by: org.apache.maven.plugin.MojoExecutionException: java.lang.NullPointerException
at com.googlecode.flyway.maven.AbstractFlywayMojo.execute(AbstractFlywayMojo.java:536)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:101)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209)
... 19 more
Caused by: java.lang.NullPointerException
at java.util.regex.Matcher.quoteReplacement(Matcher.java:598)
at com.googlecode.flyway.core.util.StringUtils.replaceAll(StringUtils.java:132)
at com.googlecode.flyway.core.util.PlaceholderReplacer.replacePlaceholders(PlaceholderReplacer.java:75)
at com.googlecode.flyway.core.resolver.sql.SqlMigrationExecutor.execute(SqlMigrationExecutor.java:70)
at com.googlecode.flyway.core.command.DbMigrate$2.doInTransaction(DbMigrate.java:243)
at com.googlecode.flyway.core.command.DbMigrate$2.doInTransaction(DbMigrate.java:241)
at com.googlecode.flyway.core.util.jdbc.TransactionTemplate.execute(TransactionTemplate.java:72)
at com.googlecode.flyway.core.command.DbMigrate.applyMigration(DbMigrate.java:241)
at com.googlecode.flyway.core.command.DbMigrate.access$700(DbMigrate.java:44)
at com.googlecode.flyway.core.command.DbMigrate$1.doInTransaction(DbMigrate.java:186)
at com.googlecode.flyway.core.command.DbMigrate$1.doInTransaction(DbMigrate.java:135)
at com.googlecode.flyway.core.util.jdbc.TransactionTemplate.execute(TransactionTemplate.java:72)
at com.googlecode.flyway.core.command.DbMigrate.migrate(DbMigrate.java:135)
at com.googlecode.flyway.core.Flyway$1.execute(Flyway.java:872)
at com.googlecode.flyway.core.Flyway$1.execute(Flyway.java:819)
at com.googlecode.flyway.core.Flyway.execute(Flyway.java:1200)
at com.googlecode.flyway.core.Flyway.migrate(Flyway.java:819)
at com.googlecode.flyway.maven.MigrateMojo.doExecute(MigrateMojo.java:38)
at com.googlecode.flyway.maven.AbstractFlywayMojo.execute(AbstractFlywayMojo.java:534)
... 21 more
[ERROR]
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

@axelfontaine
Copy link
Contributor

@axelfontaine axelfontaine commented Apr 14, 2014

Thanks for the report. Could you post the 020 migration causing trouble? It's hard to pin point the exact cause without it.

@llidija
Copy link
Author

@llidija llidija commented Apr 15, 2014

Sure, this is the contents of the file V020__data_feed_source_locations.sql (I just replaced the real domain name with "someUrl"):

INSERT INTO source VALUES (138, 'Source DN', 'Source DN', now(), NULL);
INSERT INTO source_location (id, url, active, type, source_id, m_created, m_modified) VALUES
(386, 'http://someUrl.si/feed/?cat=32,7,10,9,64&amp;feed=rss2&amp;tag__not_in=77', 1, 'news', 138, now(), NULL);

If I copy and paste these SQL statements into console mysql client, it works perfectly:

mysql> INSERT INTO source VALUES (138, 'Source DN', 'Source DN', now(), NULL);
Query OK, 1 row affected (0.21 sec)

mysql> INSERT INTO source_location (id, url, active, type, source_id, m_created, m_modified) VALUES
-> (386, 'http://someUrl.si/feed/?cat=32,7,10,9,64&amp;feed=rss2&amp;tag__not_in=77', 1, 'news', 138, now(), NULL);
Query OK, 1 row affected (0.08 sec)

After the mvn flyway:migrate is executed, there's no need to do mvn flyway:repair since no record is written into schema_version table.

Kind regards,
Lidija

@axelfontaine axelfontaine added this to the Flyway 3.0 milestone Apr 15, 2014
@axelfontaine
Copy link
Contributor

@axelfontaine axelfontaine commented Apr 16, 2014

Fixed it. One of your placeholders must have had no value. This caused Maven this pass null instead of blank, causing the NPE.

@llidija
Copy link
Author

@llidija llidija commented Apr 16, 2014

You're right: if useLocal tag is empty, I get NPE. If it's not empty, the migration works.

Thank you for the quick fix :)

Kind regards,
Lidija

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

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.