This rule flags usage of org.springframework.http.HttpMethod where the code assumes it is an enum.
In Spring Framework 6, org.springframework.http.HttpMethod has been refactored from an enum to a standard class. While commonly used constants such as HttpMethod.GET and HttpMethod.POST are still available, any code relying on enum-specific features will no longer compile or will fail at runtime.
Developers must migrate their code to class-compatible alternatives, such as replacing EnumSet<HttpMethod> with Set<HttpMethod> and switch statements with if-else blocks.
The following example shows invalid usage that will be flagged:
import org.springframework.http.HttpMethod;
import java.util.EnumSet;
public class InvalidHttpMethodUsage {
private EnumSet<HttpMethod> methods = EnumSet.of(HttpMethod.GET, HttpMethod.POST);
public void handle(HttpMethod method) {
switch (method) {
case GET:
System.out.println("GET");
break;
}
}
}
The following example shows valid migrated usage:
import org.springframework.http.HttpMethod;
import java.util.Set;
public class ValidHttpMethodUsage {
private Set<HttpMethod> methods = Set.of(HttpMethod.GET, HttpMethod.POST);
public void handle(HttpMethod method) {
if (HttpMethod.GET.equals(method)) {
System.out.println("GET");
}
}
}
For more information, see the following resources: