Skip to content

Commit

Permalink
fixes #1009
Browse files Browse the repository at this point in the history
  • Loading branch information
wumpz committed Jul 11, 2020
1 parent c03733b commit 71d6523
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 5 deletions.
5 changes: 4 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>3.11.1</version>
<version>3.16.1</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down Expand Up @@ -246,6 +246,9 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M4</version>
<configuration>
<trimStackTrace>false</trimStackTrace>
</configuration>
</plugin>
</plugins>
</build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,10 @@ public void visit(InExpression expr) {
}
if (expr.getRightExpression() != null) {
expr.getRightExpression().accept(this);
} else {
} else if (expr.getRightItemsList() != null) {
expr.getRightItemsList().accept(this);
} else {
expr.getMultiExpressionList().accept(this);
}
}

Expand Down
8 changes: 7 additions & 1 deletion src/main/java/net/sf/jsqlparser/util/TablesNamesFinder.java
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,13 @@ public void visit(InExpression inExpression) {
} else if (inExpression.getLeftItemsList() != null) {
inExpression.getLeftItemsList().accept(this);
}
inExpression.getRightItemsList().accept(this);
if (inExpression.getRightExpression() != null) {
inExpression.getRightExpression().accept(this);
} else if (inExpression.getRightItemsList() != null) {
inExpression.getRightItemsList().accept(this);
} else {
inExpression.getMultiExpressionList().accept(this);
}
}

@Override
Expand Down
15 changes: 13 additions & 2 deletions src/test/java/net/sf/jsqlparser/util/TablesNamesFinderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,12 @@
import java.io.StringReader;
import java.util.Iterator;
import java.util.List;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.Assert.*;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;


public class TablesNamesFinderTest {

Expand Down Expand Up @@ -615,4 +618,12 @@ public void testAlterSequence_throwsException() throws JSQLParserException {
assertThatThrownBy(() -> tablesNamesFinder.getTableList(stmt)).isInstanceOf(UnsupportedOperationException.class)
.hasMessage("Finding tables from AlterSequence is not supported");
}

@Test
public void testNPEIssue1009() throws JSQLParserException {
Statement stmt = CCJSqlParserUtil.parse(" SELECT * FROM (SELECT * FROM biz_fund_info WHERE tenant_code = ? AND ((ta_code, manager_code) IN ((?, ?)) OR department_type IN (?)))");
TablesNamesFinder tablesNamesFinder = new TablesNamesFinder();

assertThat(tablesNamesFinder.getTableList(stmt)).containsExactly("biz_fund_info");
}
}

0 comments on commit 71d6523

Please sign in to comment.