Skip to content

Remove unused type parameter declarations in MockMvc #23858

@sbrannen

Description

@sbrannen

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.

Metadata

Metadata

Assignees

Labels

in: testIssues in the test moduletype: bugA general bug

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions