Skip to content

Broken OAuth2AuthorizationRequestRedirectFilter constructor tests #18507

@rwinch

Description

@rwinch

There are some tests that pass in null (with no type) into OAuth2AuthorizationRequestRedirectFilter constructor expecting an IllegalArgumentException. The tests pass not because the constructor throws an IllegalArgumentException, but because there are multiple constructors and the proper constructor cannot be selected without type information.

An example is found at constructorWhenClientRegistrationRepositoryIsNullThenThrowIllegalArgumentException. If you look at the actual stacktrace, you can see it is reflection code and not the constructor throwing the IllegalArgumentException.

wrong number of arguments
java.lang.IllegalArgumentException: wrong number of arguments
	at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:77)
	at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
	at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:500)
	at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:481)
	at org.springframework.security.oauth2.client.web.OAuth2AuthorizationRequestRedirectFilterTests.constructorWhenClientRegistrationRepositoryIsNullThenThrowIllegalArgumentException(OAuth2AuthorizationRequestRedirectFilterTests.java:92)

We can remove the unnecessary reflection and include the type information to ensure the constructor is being checked properly

NOTE: This is important in order to be able to run with JDK 25 because the exception type changes

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions