CCJSqlParserUtil.parseStatements(sql, consumer) returns null instead of throwing JSQLParserException when complex parsing is switched off and the input does not parse. A caller that relies on the declared exception dereferences the result and fails with a NullPointerException of its own; a guard that treats "no exception" as "parsed" is misled.
Version: com.manticore-projects.jsqlformatter:jsqlparser:5.4.351-SNAPSHOT (build 5.4.351-20260910.100601-1), master at b2115ac8.
Reproduce
// default configuration: the documented exception
CCJSqlParserUtil.parseStatements("PRAGMA foo");
// -> JSQLParserException: Encountered: <S_IDENTIFIER> / "PRAGMA", at line 1, column 1 ...
// complex parsing off: null, no exception
Statements s = CCJSqlParserUtil.parseStatements("PRAGMA foo", p -> p.withAllowComplexParsing(false));
// s == null
// same for a broken script and for an empty statement between separators
CCJSqlParserUtil.parseStatements("SELECT * FROM foo; PRAGMA x", p -> p.withAllowComplexParsing(false)); // null
CCJSqlParserUtil.parseStatements("SELECT * FROM foo;;", p -> p.withAllowComplexParsing(false)); // null
// the single-statement entry point throws as expected with the same option
CCJSqlParserUtil.parse("PRAGMA foo", p -> p.withAllowComplexParsing(false));
// -> JSQLParserException
Also observed: parseStatements("/* nothing */") (default configuration) returns an empty Statements while parse("/* nothing */") throws JSQLParserException; the two entry points disagree on comment-only input.
Where
CCJSqlParserUtil.parseStatements(String, ExecutorService, Consumer) (CCJSqlParserUtil.java:471-501): the simple-parse attempt fails, the complex re-parse is skipped because allowComplexParsing is false, and the method falls through returning the unassigned result instead of rethrowing the first ParseException.
Suggestion
Rethrow the first parse failure as JSQLParserException when the complex re-parse is disabled (the way parse(String, ExecutorService, Consumer) does), and align the two entry points on comment-only input, either both empty or both throwing.
CCJSqlParserUtil.parseStatements(sql, consumer)returnsnullinstead of throwingJSQLParserExceptionwhen complex parsing is switched off and the input does not parse. A caller that relies on the declared exception dereferences the result and fails with aNullPointerExceptionof its own; a guard that treats "no exception" as "parsed" is misled.Version:
com.manticore-projects.jsqlformatter:jsqlparser:5.4.351-SNAPSHOT(build 5.4.351-20260910.100601-1),masteratb2115ac8.Reproduce
Also observed:
parseStatements("/* nothing */")(default configuration) returns an emptyStatementswhileparse("/* nothing */")throwsJSQLParserException; the two entry points disagree on comment-only input.Where
CCJSqlParserUtil.parseStatements(String, ExecutorService, Consumer)(CCJSqlParserUtil.java:471-501): the simple-parse attempt fails, the complex re-parse is skipped becauseallowComplexParsingis false, and the method falls through returning the unassigned result instead of rethrowing the firstParseException.Suggestion
Rethrow the first parse failure as
JSQLParserExceptionwhen the complex re-parse is disabled (the wayparse(String, ExecutorService, Consumer)does), and align the two entry points on comment-only input, either both empty or both throwing.