Why this matters
Using primitive types for optional REST parameters can lead to runtime errors when the parameter is absent. Use object types or `Optional<T>` instead.
Ensure that optional REST parameters use object types or `Optional<T>` instead of primitive types to avoid runtime errors.
Using primitive types for optional REST parameters can lead to runtime errors when the parameter is absent. Use object types or `Optional<T>` instead.
Side-by-side examples engineers can pattern-match during review.
@RequestMapping(value = {"/article", "/article/{id}"})
public Article getArticle(@PathVariable(required = false) int articleId) { // Noncompliant, null cannot be mapped to int
//...
}@RequestMapping(value = {"/article", "/article/{id}"})
public Article getArticle(@PathVariable(required = false) Integer articleId) { // Compliant
//...
}@RequestMapping(value = {"/article", "/article/{id}"})
public Article getArticle(@PathVariable(required = false) int articleId) { // Noncompliant, null cannot be mapped to int
//...
}@RequestMapping(value = {"/article", "/article/{id}"})
public Article getArticle(@PathVariable(required = false) Integer articleId) { // Compliant
//...
}From the same buckets as this rule.