Issue
The test org.springframework.boot.web.servlet.DelegatingFilterProxyRegistrationBeanTests.initShouldNotCauseEarlyInitialization is not idempotent since it pollutes the state registry. It may be good to clean this state pollution so that some other tests do not fail in the future due to the shared state polluted by this test.
This might fail future tests that share the same state similar to #38363 , making the test order dependent.
Detail
AssertionFailedError log when initShouldNotCauseEarlyInitialization was run twice in the same JVM:
org.junit.ComparisonFailure:
Expected :null
Actual :true
// Failed at this line:
assertThat(mockFilterInitialized.get()).isNull();
The root cause is that in each of the test runs, the ThreadLocal<Boolean> mockFilterInitialized is set, which is not removed when the test exits. Therefore, when the assertion is hit during the second test run, mockFilterInitialized is still set(not null), leading to the assertion error.
The suggested fix is to remove the mockFilterInitialized when each test exits.
assertThat(mockFilterInitialized.get()).isNull();
filter.doFilter(new MockHttpServletRequest(), new MockHttpServletResponse(), new MockFilterChain());
assertThat(mockFilterInitialized.get()).isTrue();
mockFilterInitialized.remove();
The proposed fix resolves the issue of state pollution proactively before it causes other tests to fail.
Comment From: harshith2000
Hi, I've created a tentative PR for this fix. Please let me know if I can open a real PR to spring-boot
Tentative PR: https://github.com/harshith2000/spring-boot/pull/1