Skip to content

Commit 6d8a1da

Browse files
lukaszlenartclaude
andcommitted
WW-5759 chore(core): address Sonar findings on the accessor resolution change
Make the non-null target contract of ultimateClass explicit, drop throws clauses the new tests do not need and record the values the probe setters receive. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 34ad24e commit 6d8a1da

2 files changed

Lines changed: 10 additions & 8 deletions

File tree

‎core/src/main/java/org/apache/struts2/interceptor/parameter/StrutsParameterAuthorizer.java‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import java.lang.reflect.Modifier;
4040
import java.util.Arrays;
4141
import java.util.List;
42+
import java.util.Objects;
4243
import java.util.Optional;
4344

4445
import static java.lang.String.format;
@@ -371,6 +372,7 @@ protected StrutsParameter getParameterAnnotation(AnnotatedElement element) {
371372
}
372373

373374
protected Class<?> ultimateClass(Object target) {
375+
Objects.requireNonNull(target, "target");
374376
if (proxyService.isProxy(target)) {
375377
return proxyService.ultimateTargetClass(target);
376378
}

‎core/src/test/java/org/apache/struts2/interceptor/parameter/ParametersInterceptorTest.java‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ public void testModelDrivenAnnotatedNestedPropertyOnActionIsAllowlisted() throws
324324
* OGNL resolves {@code uRange} to the JavaBeans setter {@code setuRange} before {@code setURange}, so that is the
325325
* method which has to carry the annotation. The model property alongside proves the parameters were applied.
326326
*/
327-
public void testModelDrivenJavaBeansStyleSetterOnActionRequiresAnnotation() throws Exception {
327+
public void testModelDrivenJavaBeansStyleSetterOnActionRequiresAnnotation() {
328328
loadButSet(Map.of(StrutsConstants.STRUTS_PARAMETERS_REQUIRE_ANNOTATIONS, "true"));
329329
ParametersInterceptor pi = createParametersInterceptor();
330330

@@ -349,7 +349,7 @@ public void testModelDrivenJavaBeansStyleSetterOnActionRequiresAnnotation() thro
349349
* A nested parameter goes through the getter OGNL resolves, {@code getURL} for {@code uRL}, which
350350
* introspection names property {@code URL}.
351351
*/
352-
public void testModelDrivenUppercaseGetterOnActionRequiresAnnotation() throws Exception {
352+
public void testModelDrivenUppercaseGetterOnActionRequiresAnnotation() {
353353
loadButSet(Map.of(StrutsConstants.STRUTS_PARAMETERS_REQUIRE_ANNOTATIONS, "true"));
354354
ParametersInterceptor pi = createParametersInterceptor();
355355

@@ -372,7 +372,7 @@ public void testModelDrivenUppercaseGetterOnActionRequiresAnnotation() throws Ex
372372
/**
373373
* The annotation counts only on the setter OGNL actually invokes for the parameter name as written.
374374
*/
375-
public void testAnnotationOnlyCountsOnTheSetterOgnlInvokes() throws Exception {
375+
public void testAnnotationOnlyCountsOnTheSetterOgnlInvokes() {
376376
loadButSet(Map.of(StrutsConstants.STRUTS_PARAMETERS_REQUIRE_ANNOTATIONS, "true"));
377377
ParametersInterceptor pi = createParametersInterceptor();
378378

@@ -395,7 +395,7 @@ public void testAnnotationOnlyCountsOnTheSetterOgnlInvokes() throws Exception {
395395
* Names differing from an accessor's property only in case resolve to no accessor on either object, so they
396396
* take the "declared on neither" route - which is safe only as long as OGNL does not bind them either.
397397
*/
398-
public void testModelDrivenCaseVariantsBindNothingOnAction() throws Exception {
398+
public void testModelDrivenCaseVariantsBindNothingOnAction() {
399399
loadButSet(Map.of(StrutsConstants.STRUTS_PARAMETERS_REQUIRE_ANNOTATIONS, "true"));
400400
ParametersInterceptor pi = createParametersInterceptor();
401401

@@ -1238,16 +1238,16 @@ public static class JavaBeansNamedAction {
12381238
public String getxCoord() { return xCoord; }
12391239

12401240
// NO @StrutsParameter - OGNL prefers it to the annotated setURange for "uRange"
1241-
public void setuRange(String uRange) { invoked.add("setuRange"); }
1241+
public void setuRange(String uRange) { invoked.add("setuRange=" + uRange); }
12421242

12431243
@StrutsParameter
1244-
public void setURange(String uRange) { invoked.add("setURange"); }
1244+
public void setURange(String uRange) { invoked.add("setURange=" + uRange); }
12451245

12461246
@StrutsParameter
1247-
public void setvRange(String vRange) { invoked.add("setvRange"); }
1247+
public void setvRange(String vRange) { invoked.add("setvRange=" + vRange); }
12481248

12491249
// NO @StrutsParameter - the only setter OGNL considers for "VRange"
1250-
public void setVRange(String vRange) { invoked.add("setVRange"); }
1250+
public void setVRange(String vRange) { invoked.add("setVRange=" + vRange); }
12511251

12521252
public List<String> getInvoked() { return invoked; }
12531253
}

0 commit comments

Comments
 (0)