Visitar URL original
[Fix] #2443 - NPE In TableNamesFinder with AnalyticExpression by davyboyhayes · Pull Request #2444 · JSQLParser/JSqlParser · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
[Fix] #2443 - NPE In TableNamesFinder with AnalyticExpression
If you attempt to tree walk an AnalyticExpression in TableNamesFinder with an SQL that has a window function without a range and without an offset, such as `SELECT c, SUM(COUNT(*)) OVER (ORDER BY c ASC ROWS UNBOUNDED PRECEDING) FROM tbl GROUP BY c`, an NPE is thrown. This adds defensive checks around the range and offset expressions being null.
  • Loading branch information
David Hayes
David Hayes committed Jul 24, 2026
commit e5d0051f5e7064cd192dba50630c6e77750fce9d
19 changes: 11 additions & 8 deletions src/main/java/net/sf/jsqlparser/util/TablesNamesFinder.java
Original file line number Diff line number Diff line change
Expand Up @@ -766,17 +766,20 @@ public <S> Void visit(AnalyticExpression analytic, S context) {
}

if (analytic.getWindowElement() != null) {
if (analytic.getWindowElement().getRange().getStart().getExpression() != null) {
analytic.getWindowElement().getRange().getStart().getExpression().accept(this,
context);
}
if (analytic.getWindowElement().getRange().getEnd().getExpression() != null) {
analytic.getWindowElement().getRange().getEnd().getExpression().accept(this,
context);
if (analytic.getWindowElement().getRange() != null) {
if (analytic.getWindowElement().getRange().getStart().getExpression() != null) {
analytic.getWindowElement().getRange().getStart().getExpression().accept(this,
context);
}
if (analytic.getWindowElement().getRange().getEnd().getExpression() != null) {
analytic.getWindowElement().getRange().getEnd().getExpression().accept(this,
context);
}
}
if (analytic.getWindowElement().getOffset() != null) {
if (analytic.getWindowElement().getOffset() != null && analytic.getWindowElement().getOffset().getExpression() != null) {
analytic.getWindowElement().getOffset().getExpression().accept(this, context);
}

}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -771,4 +771,12 @@ void testJsonTable() throws JSQLParserException {

}

@Test
void testWindowExpressionWithNoRangeAndNoOffsetDoesNotThrowException() {
String sqlStr = "SELECT c, SUM(COUNT(*)) OVER (ORDER BY c ASC ROWS UNBOUNDED PRECEDING) FROM tbl GROUP BY c";

assertThatCode(() -> TablesNamesFinder.findTables(sqlStr))
.doesNotThrowAnyException();
}

}
Loading