Overview
Several of the ResultMatcher methods used in MockMvc declare unused type parameters (e.g., <T>). This is obviously the result of copying an existing method that actually needs the type parameter for proper casting.
For example, the following in RequestResultMatchers:
/**
* Assert a request attribute value.
*/
public <T> ResultMatcher attribute(String name, Object expectedValue) {
return result ->
assertEquals("Request attribute '" + name + "'", expectedValue, result.getRequest().getAttribute(name));
}
... should actually be declared without <T> since T is not used in the implementation or in the return type:
/**
* Assert a request attribute value.
*/
public ResultMatcher attribute(String name, Object expectedValue) {
return result ->
assertEquals("Request attribute '" + name + "'", expectedValue, result.getRequest().getAttribute(name));
}
Side Effects
Once we remove the unused type parameter declarations, users will see the following side effects if they had previously declared a type argument when invoking such methods.
- Java: an
Unused type arguments for the non generic method ... warning will be generated by the compiler, but the code will continue to work unchanged.
- Kotlin: a
Type inference failed: Not enough information to infer parameter T in fun ... compiler error will be raised, causing the code to no longer compile (see KT-5464). Removal of the type argument declaration will allow the code to work correctly again.
Overview
Several of the
ResultMatchermethods used inMockMvcdeclare unused type parameters (e.g.,<T>). This is obviously the result of copying an existing method that actually needs the type parameter for proper casting.For example, the following in
RequestResultMatchers:... should actually be declared without
<T>sinceTis not used in the implementation or in the return type:Side Effects
Once we remove the unused type parameter declarations, users will see the following side effects if they had previously declared a type argument when invoking such methods.
Unused type arguments for the non generic method ...warning will be generated by the compiler, but the code will continue to work unchanged.Type inference failed: Not enough information to infer parameter T in fun ...compiler error will be raised, causing the code to no longer compile (see KT-5464). Removal of the type argument declaration will allow the code to work correctly again.