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

Closed
gbehrmann opened this issue Nov 7, 2018 · 1 comment
Closed

NullPointerException with PostgreSQL CREATE RULE statements #2202

gbehrmann opened this issue Nov 7, 2018 · 1 comment

Comments

@gbehrmann
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?
java.lang.NullPointerException
	at org.flywaydb.core.internal.sqlscript.AbstractSqlStatement.stripDelimiter(AbstractSqlStatement.java:94)
	at org.flywaydb.core.internal.sqlscript.AbstractSqlStatement.getSql(AbstractSqlStatement.java:72)
	at org.flywaydb.core.internal.sqlscript.SqlScript.addStatement(SqlScript.java:169)
	at org.flywaydb.core.internal.sqlscript.SqlScript.extractStatements(SqlScript.java:145)
	at org.flywaydb.core.internal.sqlscript.SqlScript.<init>(SqlScript.java:86)
	at org.flywaydb.core.internal.resolver.sql.SqlMigrationResolver.addMigrations(SqlMigrationResolver.java:140)
	at org.flywaydb.core.internal.resolver.sql.SqlMigrationResolver.resolveMigrations(SqlMigrationResolver.java:100)
	at org.flywaydb.core.internal.resolver.sql.SqlMigrationResolver.resolveMigrations(SqlMigrationResolver.java:47)
	at org.flywaydb.core.internal.resolver.CompositeMigrationResolver.collectMigrations(CompositeMigrationResolver.java:136)
	at org.flywaydb.core.internal.resolver.CompositeMigrationResolver.doFindAvailableMigrations(CompositeMigrationResolver.java:118)
	at org.flywaydb.core.internal.resolver.CompositeMigrationResolver.resolveMigrations(CompositeMigrationResolver.java:104)
	at org.flywaydb.core.internal.resolver.CompositeMigrationResolver.resolveMigrations(CompositeMigrationResolver.java:46)
	at org.flywaydb.core.internal.info.MigrationInfoServiceImpl.refresh(MigrationInfoServiceImpl.java:133)
	at org.flywaydb.core.internal.command.DbValidate$2.call(DbValidate.java:138)
	at org.flywaydb.core.internal.command.DbValidate$2.call(DbValidate.java:126)
	at org.flywaydb.core.internal.jdbc.TransactionTemplate.execute(TransactionTemplate.java:74)
	at org.flywaydb.core.internal.command.DbValidate.validate(DbValidate.java:126)
	at org.flywaydb.core.Flyway.doValidate(Flyway.java:1461)
	at org.flywaydb.core.Flyway.access$100(Flyway.java:82)
	at org.flywaydb.core.Flyway$1.execute(Flyway.java:1349)
	at org.flywaydb.core.Flyway$1.execute(Flyway.java:1341)
	at org.flywaydb.core.Flyway.execute(Flyway.java:1696)
	at org.flywaydb.core.Flyway.migrate(Flyway.java:1341)
	at org.flywaydb.commandline.Main.executeOperation(Main.java:161)
	at org.flywaydb.commandline.Main.main(Main.java:108)

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
  SELECT 1;

CREATE TABLE test (x int);

CREATE RULE users_update AS ON UPDATE TO users DO INSTEAD (UPDATE test
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/flywaydb.org that referenced this issue Nov 7, 2018
@axelfontaine
Copy link
Contributor

@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
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants