Affects: 5.1.4

Bug Description

I am using ResourceDatabasePopulator to populate a MySQL database using SQL scripts. These scripts contain multi-line comments of the form:

/*--------------------------------------------
-- This is a multi-line comment block
--------------------------------------------*/

ScriptUtils.executeSqlScript then fails with the error:

Failed to parse SQL script from resource [Byte array resource [resource loaded from byte array]]: Missing block comment end delimiter: */

More Details

What appears to be happening is that ScriptUtils.readScript(LineNumberReader, String, String) trims all single-line comments from the input script before passing it to ScriptUtils.splitSqlScript(). The last line of the comment, containing the block-comment end-delimiter, also gets removed because it assumes that this is a single-line comment. The line does start with the single-line comment prefix '--' after all.

Subsequently the trimmed version of the script is passed to and processed by ScriptUtils.splitSqlScript(EncodedResource resource, String, String, String, String, String, List<String>) which finds a block-comment-open delimiter but doesn't find a corresponding block-comment-end delimiter. Which then causes the error listed above.

Effectively, it appears that code allows the block-comment end-delimiter to itself be commented-away by a single-line comment prefix. This is not the behavior we see in standard SQL which allows

I forked and fixed this in the following commits:

  • 5488b2004 - Failing test that demonstrates this issue.
  • a320f622bc - The fix I ended up using.

Comment From: jhoeller

A valid point indeed, are your fix looks good to me. Would you mind preparing a pull request, ideally based on the 5.1.x branch? I'd be happy to merge it right away then, right in time for the 5.1.5 release next week.

Comment From: mmustaquim

There you go: pull request created. Took me a while to figure out how to move the changes to 5.1.x. Hope this helps.

Comment From: jhoeller

Superseded by #22392

Comment From: sbrannen

Good catch and analysis, @mmustaquim!

And thanks for providing the fix as well.

Comment From: mmustaquim

I'm glad to be able to help. And now looking forward to moving to 5.1.5 next week :-)