Skip to content

Avoid final-field mutation in security tests - #19521

Open
gregjotau wants to merge 1 commit into
spring-projects:mainfrom
gregjotau:fix/final-security-context-repository
Open

Avoid final-field mutation in security tests#19521
gregjotau wants to merge 1 commit into
spring-projects:mainfrom
gregjotau:fix/final-security-context-repository

Conversation

@gregjotau

Copy link
Copy Markdown

Closes gh-19520

WebTestUtils currently replaces SecurityContextHolderFilter.securityContextRepository reflectively even though it is final. Current JDKs warn about this operation and state it will be blocked in a future release.

This adds a null-checked repository setter and uses it from test support. Reflective reads remain unchanged, so the new setter is the only additional production API.

Verification (JDK 25):

./gradlew :spring-security-web:test \
  --tests org.springframework.security.web.context.SecurityContextHolderFilterTests \
  :spring-security-test:test \
  --tests org.springframework.security.test.web.support.WebTestUtilsTests
./gradlew format

Closes spring-projectsgh-19520

Signed-off-by: gregjotau <gregjotau@gmail.com>
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Aug 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status: waiting-for-triage An issue we've not yet triaged

Projects

None yet

Development

Successfully merging this pull request may close these issues.

WebTestUtils mutates a final SecurityContextHolderFilter field

2 participants