Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

MethodSecurityExpressionHandler doesn't allow null to be returned when filtering

Open Beginner friendly
#19,781 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 3 days

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
65/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active

Research direction

Look at the MethodSecurityExpressionHandler interface in spring-security-core, specifically the filter method. Check the PostFilterAuthorizationMethodInterceptor.invoke method to see how it handles null returns. The fix likely involves adding a @Nullable annotation to the filter method's return type. The linked issue #19280 may provide context. Test by updating the sample project to verify compilation passes after the change.

Written by the indexing model from the issue text.

Description

status: waiting-for-triage type: bug

Describe the bug
I've implemented a custom MethodSecurityExpressionHandler in earlier Spring versions which does some filtering. In the past I've returned null when the incoming filterTarget was null as well. Unfortunately though with adding the new @Nullable annotations to Spring 7 (and me using Kotlin and upgrading to the latest Spring version), I can't do this any longer, as the return type misses a @Nullable annotation. So this is a regression in contrast to previous Spring versions.

I personally think it should be possible to return null from this and it was missed when introducing the annotations to the interface, because the actual calling code on PostFilterAuthorizationMethodInterceptor.invoke allows null to be returned from the filter.

Be aware that this whole problem is also somewhat connected to the issue at #19280
So one could either merge the solution mentioned over there or add the missing annotation mentioned here. Either one or the other would actually work for me.

Thanks for checking. 🙏

To Reproduce
Implement a custom MethodSecurityExpressionHandler and try to return null from the filter method.

Expected behavior
It should be allowed to return null from the filter method.

Sample
https://github.com/GFriedrich/spring-security-issue

  1. See that the code compiles with Spring Boot 3
  2. Update the Spring Boot plugin to 4.x (e.g. 4.1.1) inside the build.gradle.kts
  3. See that the compilation now fails
Dominant language
Java
Stars
9.6k
Forks
6.4k
Avg merge
1d 20h
Merged PRs (30d)
54

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from spring-projects/spring-security

All issues in spring-projects/spring-security

Similar issues

More Java issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.