45
45
import org .springframework .javapoet .CodeBlock ;
46
46
import org .springframework .javapoet .CodeBlock .Builder ;
47
47
import org .springframework .javapoet .TypeName ;
48
+ import org .springframework .util .Assert ;
48
49
import org .springframework .util .ClassUtils ;
49
50
import org .springframework .util .ObjectUtils ;
50
51
import org .springframework .util .StringUtils ;
@@ -140,6 +141,8 @@ public QueryBlockBuilder queryRewriter(@Nullable Class<?> queryRewriter) {
140
141
*/
141
142
public CodeBlock build () {
142
143
144
+ Assert .notNull (queries , "Queries must not be null" );
145
+
143
146
boolean isProjecting = context .getReturnedType ().isProjecting ();
144
147
Class <?> actualReturnType = isProjecting ? context .getActualReturnType ().toClass ()
145
148
: context .getRepositoryInformation ().getDomainType ();
@@ -153,7 +156,6 @@ public CodeBlock build() {
153
156
builder .add ("\n " );
154
157
155
158
String queryStringVariableName = null ;
156
-
157
159
String queryRewriterName = null ;
158
160
159
161
if (queries .result () instanceof StringAotQuery && queryRewriter != QueryRewriter .IdentityQueryRewriter .class ) {
@@ -162,7 +164,7 @@ public CodeBlock build() {
162
164
builder .addStatement ("$T $L = new $T()" , queryRewriter , queryRewriterName , queryRewriter );
163
165
}
164
166
165
- if (queries != null && queries .result () instanceof StringAotQuery sq ) {
167
+ if (queries .result () instanceof StringAotQuery sq ) {
166
168
167
169
queryStringVariableName = "%sString" .formatted (queryVariableName );
168
170
builder .add (buildQueryString (sq , queryStringVariableName ));
@@ -183,7 +185,8 @@ public CodeBlock build() {
183
185
}
184
186
185
187
if ((StringUtils .hasText (sortParameterName ) || StringUtils .hasText (dynamicReturnType ))
186
- && queries .result () instanceof StringAotQuery ) {
188
+ && queries != null && queries .result () instanceof StringAotQuery
189
+ && StringUtils .hasText (queryStringVariableName )) {
187
190
builder .add (applyRewrite (sortParameterName , dynamicReturnType , queryStringVariableName , actualReturnType ));
188
191
}
189
192
@@ -605,7 +608,7 @@ public CodeBlock build() {
605
608
}
606
609
} else if (aotQuery != null && aotQuery .isExists ()) {
607
610
builder .addStatement ("return !$L.getResultList().isEmpty()" , queryVariableName );
608
- } else {
611
+ } else if ( aotQuery != null ) {
609
612
610
613
if (context .getReturnedType ().isProjecting ()) {
611
614
0 commit comments