Skip to content

Commit

Permalink
Fix NPE when parsing modifying HQL.
Browse files Browse the repository at this point in the history
Closes #3649
Original pull request: #3650
  • Loading branch information
christophstrobl authored and mp911de committed Oct 25, 2024
1 parent 3ad78ab commit 84e0e32
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,12 @@ private static boolean isSubquery(ParserRuleContext ctx) {
return false;
} else if (ctx instanceof HqlParser.InsertStatementContext) {
return false;
} else if (ctx instanceof HqlParser.DeleteStatementContext) {
return false;
} else if (ctx instanceof HqlParser.UpdateStatementContext) {
return false;
} else {
return isSubquery(ctx.getParent());
return ctx.getParent() != null ? isSubquery(ctx.getParent()) : false;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -995,16 +995,23 @@ void fromWithoutAPrimaryAliasShouldWork() {
.isEqualTo("FROM Story WHERE enabled = true order by created desc");
}

@Test // GH-2977
void isSubqueryThrowsException() {

String query = """
insert into MyEntity (id, col)
select max(id), col
from MyEntityStaging
group by col
""";

@ParameterizedTest
@ValueSource(strings = { """
insert into MyEntity (id, col)
select max(id), col
from MyEntityStaging
group by col
""", """
update MyEntity AS mes
set mes.col = 'test'
where mes.id = 1
""", """
delete MyEntity AS mes
where mes.col = 'test'
"""

}) // GH-2977, GH-3649
void isSubqueryThrowsException(String query) {
assertThat(createQueryFor(query, Sort.unsorted())).isEqualToIgnoringWhitespace(query);
}

Expand Down

0 comments on commit 84e0e32

Please sign in to comment.