Skip to content

Commit 4bdabed

Browse files
build: try to work around the Maven/JDK8 issue on GitHub
1 parent 9dafae8 commit 4bdabed

File tree

3 files changed

+44
-34
lines changed

3 files changed

+44
-34
lines changed

src/main/java/net/sf/jsqlparser/parser/CCJSqlParserUtil.java

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -296,17 +296,18 @@ public static Expression parseCondExpression(String conditionalExpressionStr,
296296
public static Statement parseStatement(CCJSqlParser parser, ExecutorService executorService)
297297
throws JSQLParserException {
298298
Statement statement = null;
299+
Future<Statement> future = executorService.submit(new Callable<Statement>() {
300+
@Override
301+
public Statement call() throws Exception {
302+
return parser.Statement();
303+
}
304+
});
299305
try {
300-
Future<Statement> future = executorService.submit(new Callable<Statement>() {
301-
@Override
302-
public Statement call() throws Exception {
303-
return parser.Statement();
304-
}
305-
});
306306
statement = future.get(parser.getConfiguration().getAsLong(Feature.timeOut),
307307
TimeUnit.MILLISECONDS);
308308
} catch (TimeoutException ex) {
309309
parser.interrupted = true;
310+
future.cancel(true);
310311
throw new JSQLParserException("Time out occurred.", ex);
311312
} catch (Exception ex) {
312313
throw new JSQLParserException(ex);
@@ -376,17 +377,18 @@ public static Statements parseStatements(String sqls, ExecutorService executorSe
376377
public static Statements parseStatements(CCJSqlParser parser, ExecutorService executorService)
377378
throws JSQLParserException {
378379
Statements statements = null;
380+
Future<Statements> future = executorService.submit(new Callable<Statements>() {
381+
@Override
382+
public Statements call() throws Exception {
383+
return parser.Statements();
384+
}
385+
});
379386
try {
380-
Future<Statements> future = executorService.submit(new Callable<Statements>() {
381-
@Override
382-
public Statements call() throws Exception {
383-
return parser.Statements();
384-
}
385-
});
386387
statements = future.get(parser.getConfiguration().getAsLong(Feature.timeOut),
387388
TimeUnit.MILLISECONDS);
388389
} catch (TimeoutException ex) {
389390
parser.interrupted = true;
391+
future.cancel(true);
390392
throw new JSQLParserException("Time out occurred.", ex);
391393
} catch (Exception ex) {
392394
throw new JSQLParserException(ex);

src/test/java/net/sf/jsqlparser/expression/JsonExpressionTest.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
/*-
2+
* #%L
3+
* JSQLParser library
4+
* %%
5+
* Copyright (C) 2004 - 2023 JSQLParser
6+
* %%
7+
* Dual licensed under GNU LGPL 2.1 or Apache License 2.0
8+
* #L%
9+
*/
110
package net.sf.jsqlparser.expression;
211

312
import net.sf.jsqlparser.JSQLParserException;

src/test/java/net/sf/jsqlparser/parser/CCJSqlParserUtilTest.java

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,9 @@
3636
import static org.junit.jupiter.api.Assertions.assertThrows;
3737
import static org.junit.jupiter.api.Assertions.assertTrue;
3838

39+
import net.sf.jsqlparser.statement.UnsupportedStatement;
40+
import net.sf.jsqlparser.statement.select.PlainSelect;
3941
import net.sf.jsqlparser.test.MemoryLeakVerifier;
40-
import org.junit.jupiter.api.Disabled;
4142
import org.junit.jupiter.api.Test;
4243
import org.junit.jupiter.api.function.Executable;
4344

@@ -217,12 +218,19 @@ public void accept(Statement statement) {
217218
}
218219

219220
@Test
220-
@Disabled
221221
public void testParseStatementsFail() throws Exception {
222-
// This will not fail, but always return the Unsupported Statements
223-
// Since we can't LOOKAHEAD in the Statements() production
224-
assertThrows(JSQLParserException.class,
225-
() -> CCJSqlParserUtil.parseStatements("select * from dual;WHATEVER!!"));
222+
String sqlStr = "select * from dual;WHATEVER!!";
223+
224+
// Won't fail but return Unsupported Statement instead
225+
assertDoesNotThrow(new Executable() {
226+
@Override
227+
public void execute() throws Throwable {
228+
final Statements statements = CCJSqlParserUtil.parseStatements(sqlStr);
229+
assertEquals(2, statements.size());
230+
assertTrue(statements.get(0) instanceof PlainSelect);
231+
assertTrue(statements.get(1) instanceof UnsupportedStatement);
232+
}
233+
});
226234
}
227235

228236
@Test
@@ -335,20 +343,16 @@ public void testCondExpressionIssue1482_2() throws JSQLParserException {
335343
assertEquals("test_table_enum.f1_enum IN ('TEST2'::test.\"test_enum\")", expr.toString());
336344
}
337345

338-
339-
340346
/**
341347
* The purpose of the test is to run into a timeout and to stop the parser when this happens. We
342348
* provide an INVALID statement for this purpose, which will fail the SIMPLE parse and then hang
343349
* with COMPLEX parsing until the timeout occurs.
344350
* <p>
345351
* We repeat that test multiple times and want to see no stale references to the Parser after
346352
* timeout.
347-
*
348-
* @throws JSQLParserException
349353
*/
350354
@Test
351-
public void testParserInterruptedByTimeout() throws InterruptedException {
355+
public void testParserInterruptedByTimeout() {
352356
MemoryLeakVerifier verifier = new MemoryLeakVerifier();
353357

354358
int parallelThreads = Runtime.getRuntime().availableProcessors() + 1;
@@ -371,17 +375,15 @@ public void run() {
371375
}
372376
});
373377
}
374-
378+
timeOutService.shutdownNow();
375379
executorService.shutdown();
376-
timeOutService.shutdown();
377380

378381
// we should not run in any timeout here (because we expect that the Parser has timed out by
379382
// itself)
380383
assertDoesNotThrow(new Executable() {
381384
@Override
382385
public void execute() throws Throwable {
383386
executorService.awaitTermination(10, TimeUnit.SECONDS);
384-
timeOutService.awaitTermination(10, TimeUnit.SECONDS);
385387
}
386388
});
387389

@@ -390,7 +392,7 @@ public void execute() throws Throwable {
390392
}
391393

392394
@Test
393-
public void testTimeOutIssue1582() throws InterruptedException {
395+
public void testTimeOutIssue1582() {
394396
// This statement is INVALID on purpose
395397
// There are crafted INTO keywords in order to make it fail but only after a long time (40
396398
// seconds plus)
@@ -443,7 +445,7 @@ public void execute() throws Throwable {
443445

444446
// Supposed to time out
445447
@Test
446-
void testComplexIssue1792() throws JSQLParserException, InterruptedException {
448+
void testComplexIssue1792() throws JSQLParserException {
447449
ExecutorService executorService = Executors.newCachedThreadPool();
448450
CCJSqlParserUtil.LOGGER.setLevel(Level.ALL);
449451

@@ -457,7 +459,7 @@ void testComplexIssue1792() throws JSQLParserException, InterruptedException {
457459
public void execute() throws Throwable {
458460
try {
459461
CCJSqlParserUtil.parse(INVALID_SQL, executorService, parser -> {
460-
parser.withTimeOut(6000);
462+
parser.withTimeOut(10000);
461463
parser.withAllowComplexParsing(false);
462464
});
463465
} catch (JSQLParserException ex) {
@@ -467,7 +469,6 @@ public void execute() throws Throwable {
467469
}
468470
});
469471

470-
471472
// Expect to time-out with COMPLEX Parsing allowed
472473
// CCJSqlParserUtil.LOGGER will report:
473474
// 1) Allowed Complex Parsing: true
@@ -478,7 +479,7 @@ public void execute() throws Throwable {
478479
public void execute() throws Throwable {
479480
try {
480481
CCJSqlParserUtil.parse(INVALID_SQL, executorService, parser -> {
481-
parser.withTimeOut(6000);
482+
parser.withTimeOut(1000);
482483
parser.withAllowComplexParsing(true);
483484
});
484485
} catch (JSQLParserException ex) {
@@ -487,9 +488,7 @@ public void execute() throws Throwable {
487488
}
488489
}
489490
});
490-
491-
executorService.shutdown();
492-
executorService.awaitTermination(1, TimeUnit.MINUTES);
491+
executorService.shutdownNow();
493492
CCJSqlParserUtil.LOGGER.setLevel(Level.OFF);
494493
}
495494
}

0 commit comments

Comments
 (0)