Skip to content

Commit 1668528

Browse files
fix: avoid NPE on empty Window Element properties
- fixes #2183 Signed-off-by: Andreas Reichel <[email protected]>
1 parent c474c16 commit 1668528

File tree

3 files changed

+32
-6
lines changed

3 files changed

+32
-6
lines changed

build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ tasks.register('xmldoc', Javadoc) {
178178
)
179179

180180
source = sourceSets.main.allJava
181-
include("build/generated/javacc/net/sf/jsqlparser/parser/*.java" )
181+
include("**/javacc/net/sf/jsqlparser/parser/*.java" )
182182

183183
destinationDir = reporting.file("xmlDoclet")
184184
options.docletpath = configurations.xmlDoclet.files as List

src/main/java/net/sf/jsqlparser/util/TablesNamesFinder.java

+11-5
Original file line numberDiff line numberDiff line change
@@ -804,11 +804,17 @@ public <S> Void visit(AnalyticExpression analytic, S context) {
804804
}
805805

806806
if (analytic.getWindowElement() != null) {
807-
analytic.getWindowElement().getRange().getStart().getExpression().accept(this,
808-
context);
809-
analytic.getWindowElement().getRange().getEnd().getExpression().accept(this,
810-
context);
811-
analytic.getWindowElement().getOffset().getExpression().accept(this, context);
807+
if (analytic.getWindowElement().getRange().getStart().getExpression() != null) {
808+
analytic.getWindowElement().getRange().getStart().getExpression().accept(this,
809+
context);
810+
}
811+
if (analytic.getWindowElement().getRange().getEnd().getExpression() != null) {
812+
analytic.getWindowElement().getRange().getEnd().getExpression().accept(this,
813+
context);
814+
}
815+
if (analytic.getWindowElement().getOffset() != null) {
816+
analytic.getWindowElement().getOffset().getExpression().accept(this, context);
817+
}
812818
}
813819
return null;
814820
}

src/test/java/net/sf/jsqlparser/util/TablesNamesFinderTest.java

+20
Original file line numberDiff line numberDiff line change
@@ -661,5 +661,25 @@ void testInsertTableIssue() throws JSQLParserException {
661661
tables = TablesNamesFinder.findTables(sqlStr);
662662
assertThat(tables).containsExactlyInAnyOrder("the_cool_db.the_table");
663663
}
664+
665+
@Test
666+
void testIssue2183() throws JSQLParserException {
667+
String sqlStr = "SELECT\n" +
668+
"\tsubscriber_id,\n" +
669+
"\tsum(1) OVER (PARTITION BY subscriber_id\n" +
670+
"ORDER BY\n" +
671+
"\tstat_time ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW ) AS stop_id\n" +
672+
"FROM\n" +
673+
"\t(\n" +
674+
"\tSELECT\n" +
675+
"\t\tsubscriber_id,\n" +
676+
"\t\tstat_time\n" +
677+
"\tFROM\n" +
678+
"\t\tlocation_subscriber AS mid2 WINDOW w AS (PARTITION BY subscriber_id\n" +
679+
"\tORDER BY\n" +
680+
"\t\tstat_time ROWS BETWEEN 1 PRECEDING AND 1 PRECEDING ) )";
681+
Set<String> tables = TablesNamesFinder.findTables(sqlStr);
682+
assertThat(tables).containsExactlyInAnyOrder("location_subscriber");
683+
}
664684
}
665685

0 commit comments

Comments
 (0)