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 with PostgreSQL CREATE RULE statements #2202

gbehrmann opened this issue Nov 7, 2018 · 1 comment

NullPointerException with PostgreSQL CREATE RULE statements #2202

gbehrmann opened this issue Nov 7, 2018 · 1 comment


Copy link

@gbehrmann gbehrmann commented Nov 7, 2018

Which version and edition of Flyway are you using?

Flyway Community Edition 5.2.1 by Boxfuse

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

Command-line and Java API.

Which database are you using (type & version)?

PostgreSQL 10.4

Which operating system are you using?

Mac OS, Linux.

What did you do?

The following migration

CREATE TABLE users (updated int);
CREATE RULE users_update AS ON UPDATE TO users DO INSTEAD (UPDATE users SET updated = 1);

executed with flyway -X -url=jdbc:postgresql://localhost:5432/test -user=postgres -password= -locations=filesystem:. migrate.

What did you expect to see?

A successful migration as the RULE syntax is valid and accepted by PostgreSQL.

What did you see instead?
	at org.flywaydb.core.internal.sqlscript.AbstractSqlStatement.stripDelimiter(
	at org.flywaydb.core.internal.sqlscript.AbstractSqlStatement.getSql(
	at org.flywaydb.core.internal.sqlscript.SqlScript.addStatement(
	at org.flywaydb.core.internal.sqlscript.SqlScript.extractStatements(
	at org.flywaydb.core.internal.sqlscript.SqlScript.<init>(
	at org.flywaydb.core.internal.resolver.sql.SqlMigrationResolver.addMigrations(
	at org.flywaydb.core.internal.resolver.sql.SqlMigrationResolver.resolveMigrations(
	at org.flywaydb.core.internal.resolver.sql.SqlMigrationResolver.resolveMigrations(
	at org.flywaydb.core.internal.resolver.CompositeMigrationResolver.collectMigrations(
	at org.flywaydb.core.internal.resolver.CompositeMigrationResolver.doFindAvailableMigrations(
	at org.flywaydb.core.internal.resolver.CompositeMigrationResolver.resolveMigrations(
	at org.flywaydb.core.internal.resolver.CompositeMigrationResolver.resolveMigrations(
	at org.flywaydb.core.internal.command.DbValidate$
	at org.flywaydb.core.internal.command.DbValidate$
	at org.flywaydb.core.internal.jdbc.TransactionTemplate.execute(
	at org.flywaydb.core.internal.command.DbValidate.validate(
	at org.flywaydb.core.Flyway.doValidate(
	at org.flywaydb.core.Flyway.access$100(
	at org.flywaydb.core.Flyway$1.execute(
	at org.flywaydb.core.Flyway$1.execute(
	at org.flywaydb.core.Flyway.execute(
	at org.flywaydb.core.Flyway.migrate(
	at org.flywaydb.commandline.Main.executeOperation(
	at org.flywaydb.commandline.Main.main(

The exception disappears if a terminating semicolon is included inside the rule. This appears to be a regression since version 5.0.7.

On a related note, the following migration causes a null pointer exception at the same place:

CREATE VIEW users (username) AS

CREATE TABLE test (x int);

SET x = 1 WHERE 'sdfjhsafkjldhfksadf ksdajgf klsdafg klsadfg ksadfg dksahfgdsaklfg klsadfg ksadlhf gasdkhf sadf ' = ' sdlfkhsdafsadjkfhlksadjfghklsdajf ksdjafdsfdsfdsfsdadsafsadfdsfa';
  UPDATE test
  SET x = 2 WHERE x = (SELECT 2 WHERE 'dflkhdsfsdhflkjsadhf kjsdahfkjlsadf kljadshf kjasdhf kjadhsf kjasdhf kjsda fkjadsg fkjasdgf ksadgf ksadjgf' = 'ælsadklhfældsafhldsfh'
AND 'sflkhsdflhasdfælhadsfksf kljsdag fklsadfgklj sadfgkljsad gkldsgfkldsgf ksdhgfklsadhfgskadlfgsadkhfgsdajkhfgdsajkhfgdsa hsadghf' = 'sd' AND 'sdfkjsdafkj sadjkf hkljasdhf kjsadhf kjasd kjsdhf kjasdh sdf ' = 'sdfjhasdflkjhasdfkjasdhfkjhasdfkjhsdafkjhsadfkjsahdkjsadfsdfdsf');
  UPDATE test
  SET x = 3 WHERE 'dfsdofhsdlfhasdofh asdklf hdsklfh dsakljfh dsfkjhsd kjlfhdskjfh dskjf hasdkljfh asdkljf hdskjf aksdjf sdf ' = 'lkjsdhflkjasdhf kljasdf kjasdgf kljasdg fkasdfg kjasdf sadf ';

This despite there being a final semicolon. This case appears to be related to the literal length of the statement.

@axelfontaine axelfontaine added this to the Flyway 5.2.2 milestone Nov 7, 2018
axelfontaine added a commit that referenced this issue Nov 7, 2018
axelfontaine added a commit to flyway/ that referenced this issue Nov 7, 2018
Copy link

@axelfontaine axelfontaine commented Nov 7, 2018

Thank you very much for the report, the analysis and the great repro cases. Fixed.

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

Successfully merging a pull request may close this issue.

None yet
2 participants