@@ -60,6 +60,13 @@ public static Statement parse(Reader statementReader) throws JSQLParserException
6060 return statement ;
6161 }
6262
63+ /**
64+ * Parses a single SQL statement.
65+ *
66+ * @param sql the SQL statement to parse
67+ * @return the parsed statement
68+ * @throws JSQLParserException if the input is null, empty, or cannot be parsed
69+ */
6370 public static Statement parse (String sql ) throws JSQLParserException {
6471 return parse (sql , null );
6572 }
@@ -73,17 +80,15 @@ public static Statement parse(String sql) throws JSQLParserException {
7380 * CCJSqlParserUtil.parse("select * from [mytable]", parser -> parser.withSquareBracketQuotation(true));
7481 * }
7582 *
76- * @param sql
77- * @param consumer
78- * @return
79- * @throws JSQLParserException
83+ * @param sql the SQL statement to parse
84+ * @param consumer parser configuration callback, or {@code null}
85+ * @return the parsed statement
86+ * @throws JSQLParserException if the input is null, empty, or cannot be parsed
8087 */
8188 public static Statement parse (String sql , Consumer <CCJSqlParser > consumer )
8289 throws JSQLParserException {
8390
84- if (sql == null || sql .isEmpty ()) {
85- return null ;
86- }
91+ requireStatementInput (sql );
8792
8893 ExecutorService executorService = Executors .newSingleThreadExecutor ();
8994 Statement statement ;
@@ -97,12 +102,19 @@ public static Statement parse(String sql, Consumer<CCJSqlParser> consumer)
97102 return statement ;
98103 }
99104
105+ /**
106+ * Parses a single SQL statement using the caller's executor, which is left open.
107+ *
108+ * @param sql the SQL statement to parse
109+ * @param executorService executor to use for parsing
110+ * @param consumer parser configuration callback, or {@code null}
111+ * @return the parsed statement
112+ * @throws JSQLParserException if the input is null, empty, or cannot be parsed
113+ */
100114 public static Statement parse (String sql , ExecutorService executorService ,
101115 Consumer <CCJSqlParser > consumer )
102116 throws JSQLParserException {
103- if (sql == null || sql .isEmpty ()) {
104- return null ;
105- }
117+ requireStatementInput (sql );
106118
107119 Statement statement ;
108120 // first, try to parse fast and simple
@@ -134,6 +146,12 @@ public static Statement parse(String sql, ExecutorService executorService,
134146 return statement ;
135147 }
136148
149+ private static void requireStatementInput (String sql ) throws JSQLParserException {
150+ if (sql == null || sql .isEmpty ()) {
151+ throw new JSQLParserException ("SQL statement must not be null or empty." );
152+ }
153+ }
154+
137155 public static CCJSqlParser newParser (String sql ) {
138156 if (sql == null || sql .isEmpty ()) {
139157 return null ;
@@ -412,20 +430,21 @@ public Statement call() throws ParseException {
412430 /**
413431 * Parse a statement list.
414432 *
415- * @return the statements parsed
433+ * @return the statements parsed, or a new empty list for null or empty input
416434 */
417435 public static Statements parseStatements (String sqls ) throws JSQLParserException {
418- if (sqls == null || sqls .isEmpty ()) {
419- return null ;
420- }
421-
422436 return parseStatements (sqls , null );
423437 }
424438
439+ /**
440+ * Parses a statement list with optional parser configuration.
441+ *
442+ * @return the statements parsed, or a new empty list for null or empty input
443+ */
425444 public static Statements parseStatements (String sqls , Consumer <CCJSqlParser > consumer )
426445 throws JSQLParserException {
427446 if (sqls == null || sqls .isEmpty ()) {
428- return null ;
447+ return new Statements () ;
429448 }
430449
431450 ExecutorService executorService = Executors .newSingleThreadExecutor ();
@@ -437,15 +456,15 @@ public static Statements parseStatements(String sqls, Consumer<CCJSqlParser> con
437456 }
438457
439458 /**
440- * Parse a statement list.
459+ * Parses a statement list using the caller's executor, which is left open .
441460 *
442- * @return the statements parsed
461+ * @return the statements parsed, or a new empty list for null or empty input
443462 */
444463 public static Statements parseStatements (String sqls , ExecutorService executorService ,
445464 Consumer <CCJSqlParser > consumer )
446465 throws JSQLParserException {
447466 if (sqls == null || sqls .isEmpty ()) {
448- return null ;
467+ return new Statements () ;
449468 }
450469
451470 CCJSqlParser parser = newParser (sqls );
0 commit comments