When I am scanning code with sonar lint the following code shows the bug as "Method has 8 parameters, which is greater than 7 authorized"
@PutMapping("/something")
public List<SomeList> updateSomeThing(@PathVariable final SomeCode code,
@PathVariable final SomeId id,
@PathVariable final String testId,
@PathVariable final String itemId,
@RequestBody final List<Test> someList,
@RequestHeader("test") final String testHeader,
final HttpServletRequest request,
final SomeHeaders someHeaders)
Note: This is a controller method we can not skip any parameters
FYI: Eclipse showing a quick fix as squid:S00107
Anybody have any idea how to resolve this bug?
Parameters are specified after the method name, inside the parentheses. You can add as many parameters as you want, just separate them with a comma.
"Constructor has 8 parameters, which is greater than the 7 authorized" for . NET Core framework class constructors · Issue #3459 · SonarSource/sonar-dotnet · GitHub.
You can add many different types of parameters but java gives a limit, the limit says you can add 255 parameters or less.
Example of parameterized constructor In this example, we have created the constructor of Student class that have two parameters. We can have any number of parameters in the constructor.
There are two things to consider here.
UPD: the advice below is based on the old question version. It might be not applicable to the new question context any more.
Say in your particular example, I would expect, that you can have an aggregate class Order
:
public class Order {
private CountryCode countryCode;
private String orderId;
private User user;
private String orderId;
private String item;
private List<Person> persons;
private ShippingAddress address;
private PaymentMethod payment;
private Product product;
// ...
}
Which is much logical to manage instead of dealing with many parameters. Then your issues will be solved automatically:
@GetMapping
public void updateSomething(Order order) { ... }
In general this is a good rule. You should refactor to a Parameter Object or a Builder. However, I tend to ignore this rule when it concerns the creation of a domain model object (like an @Entity) or an immutable object where values are only passed in via the constructor.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With