@@ -79,6 +79,10 @@ public static Statement parse(String sql) throws JSQLParserException {
79
79
public static Statement parse (String sql , Consumer <CCJSqlParser > consumer )
80
80
throws JSQLParserException {
81
81
82
+ if (sql == null || sql .isEmpty ()) {
83
+ return null ;
84
+ }
85
+
82
86
ExecutorService executorService = Executors .newSingleThreadExecutor ();
83
87
Statement statement = null ;
84
88
try {
@@ -92,8 +96,11 @@ public static Statement parse(String sql, Consumer<CCJSqlParser> consumer)
92
96
public static Statement parse (String sql , ExecutorService executorService ,
93
97
Consumer <CCJSqlParser > consumer )
94
98
throws JSQLParserException {
95
- Statement statement = null ;
99
+ if (sql == null || sql .isEmpty ()) {
100
+ return null ;
101
+ }
96
102
103
+ Statement statement = null ;
97
104
// first, try to parse fast and simple
98
105
CCJSqlParser parser = newParser (sql );
99
106
if (consumer != null ) {
@@ -122,6 +129,10 @@ public static Statement parse(String sql, ExecutorService executorService,
122
129
}
123
130
124
131
public static CCJSqlParser newParser (String sql ) {
132
+ if (sql == null || sql .isEmpty ()) {
133
+ return null ;
134
+ }
135
+
125
136
return new CCJSqlParser (new StringProvider (sql ));
126
137
}
127
138
@@ -134,6 +145,10 @@ public static CCJSqlParser newParser(InputStream is, String encoding) throws IOE
134
145
}
135
146
136
147
public static Node parseAST (String sql ) throws JSQLParserException {
148
+ if (sql == null || sql .isEmpty ()) {
149
+ return null ;
150
+ }
151
+
137
152
CCJSqlParser parser = newParser (sql );
138
153
try {
139
154
parser .Statement ();
@@ -162,20 +177,31 @@ public static Statement parse(InputStream is, String encoding) throws JSQLParser
162
177
}
163
178
164
179
public static Expression parseExpression (String expression ) throws JSQLParserException {
180
+ if (expression == null || expression .isEmpty ()) {
181
+ return null ;
182
+ }
183
+
165
184
return parseExpression (expression , true );
166
185
}
167
186
168
187
public static Expression parseExpression (String expression , boolean allowPartialParse )
169
188
throws JSQLParserException {
189
+ if (expression == null || expression .isEmpty ()) {
190
+ return null ;
191
+ }
192
+
170
193
return parseExpression (expression , allowPartialParse , p -> {
171
194
});
172
195
}
173
196
174
197
@ SuppressWarnings ("PMD.CyclomaticComplexity" )
175
198
public static Expression parseExpression (String expressionStr , boolean allowPartialParse ,
176
199
Consumer <CCJSqlParser > consumer ) throws JSQLParserException {
177
- Expression expression = null ;
200
+ if (expressionStr == null || expressionStr .isEmpty ()) {
201
+ return null ;
202
+ }
178
203
204
+ Expression expression = null ;
179
205
// first, try to parse fast and simple
180
206
try {
181
207
CCJSqlParser parser = newParser (expressionStr ).withAllowComplexParsing (false );
@@ -225,6 +251,9 @@ public static Expression parseExpression(String expressionStr, boolean allowPart
225
251
* @see #parseCondExpression(String, boolean)
226
252
*/
227
253
public static Expression parseCondExpression (String condExpr ) throws JSQLParserException {
254
+ if (condExpr == null || condExpr .isEmpty ()) {
255
+ return null ;
256
+ }
228
257
return parseCondExpression (condExpr , true );
229
258
}
230
259
@@ -238,15 +267,21 @@ public static Expression parseCondExpression(String condExpr) throws JSQLParserE
238
267
*/
239
268
public static Expression parseCondExpression (String condExpr , boolean allowPartialParse )
240
269
throws JSQLParserException {
270
+ if (condExpr == null || condExpr .isEmpty ()) {
271
+ return null ;
272
+ }
241
273
return parseCondExpression (condExpr , allowPartialParse , p -> {
242
274
});
243
275
}
244
276
245
277
@ SuppressWarnings ("PMD.CyclomaticComplexity" )
246
278
public static Expression parseCondExpression (String conditionalExpressionStr ,
247
279
boolean allowPartialParse , Consumer <CCJSqlParser > consumer ) throws JSQLParserException {
248
- Expression expression = null ;
280
+ if (conditionalExpressionStr == null || conditionalExpressionStr .isEmpty ()) {
281
+ return null ;
282
+ }
249
283
284
+ Expression expression = null ;
250
285
// first, try to parse fast and simple
251
286
try {
252
287
CCJSqlParser parser =
@@ -323,11 +358,19 @@ public Statement call() throws ParseException {
323
358
* @return the statements parsed
324
359
*/
325
360
public static Statements parseStatements (String sqls ) throws JSQLParserException {
361
+ if (sqls == null || sqls .isEmpty ()) {
362
+ return null ;
363
+ }
364
+
326
365
return parseStatements (sqls , null );
327
366
}
328
367
329
368
public static Statements parseStatements (String sqls , Consumer <CCJSqlParser > consumer )
330
369
throws JSQLParserException {
370
+ if (sqls == null || sqls .isEmpty ()) {
371
+ return null ;
372
+ }
373
+
331
374
ExecutorService executorService = Executors .newSingleThreadExecutor ();
332
375
final Statements statements = parseStatements (sqls , executorService , consumer );
333
376
executorService .shutdown ();
@@ -343,8 +386,11 @@ public static Statements parseStatements(String sqls, Consumer<CCJSqlParser> con
343
386
public static Statements parseStatements (String sqls , ExecutorService executorService ,
344
387
Consumer <CCJSqlParser > consumer )
345
388
throws JSQLParserException {
346
- Statements statements = null ;
389
+ if (sqls == null || sqls .isEmpty ()) {
390
+ return null ;
391
+ }
347
392
393
+ Statements statements = null ;
348
394
CCJSqlParser parser = newParser (sqls );
349
395
if (consumer != null ) {
350
396
consumer .accept (parser );
0 commit comments