Skip to content

Fix NPE when parsing modifying HQL #3650

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
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
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa-parent</artifactId>
<version>3.2.12-SNAPSHOT</version>
<version>3.2.x-GH-3649-SNAPSHOT</version>
<packaging>pom</packaging>

<name>Spring Data JPA Parent</name>
Expand Down
4 changes: 2 additions & 2 deletions spring-data-envers/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@

<groupId>org.springframework.data</groupId>
<artifactId>spring-data-envers</artifactId>
<version>3.2.12-SNAPSHOT</version>
<version>3.2.x-GH-3649-SNAPSHOT</version>

<parent>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa-parent</artifactId>
<version>3.2.12-SNAPSHOT</version>
<version>3.2.x-GH-3649-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion spring-data-jpa-distribution/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<parent>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa-parent</artifactId>
<version>3.2.12-SNAPSHOT</version>
<version>3.2.x-GH-3649-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
4 changes: 2 additions & 2 deletions spring-data-jpa/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa</artifactId>
<version>3.2.12-SNAPSHOT</version>
<version>3.2.x-GH-3649-SNAPSHOT</version>

<name>Spring Data JPA</name>
<description>Spring Data module for JPA repositories.</description>
Expand All @@ -15,7 +15,7 @@
<parent>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa-parent</artifactId>
<version>3.2.12-SNAPSHOT</version>
<version>3.2.x-GH-3649-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ 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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should add another guard in case the parent is empty to eliminate this bug class for future revisions.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah - sounds good - let me do that

} else {
return isSubquery(ctx.getParent());
}
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
Loading