diff --git a/java-checks-test-sources/src/main/java/checks/spring/ModelAttributeNamingConventionForSpELCheck.java b/java-checks-test-sources/src/main/java/checks/spring/ModelAttributeNamingConventionForSpELCheck.java index 2bb58f116fb..ba30387da05 100644 --- a/java-checks-test-sources/src/main/java/checks/spring/ModelAttributeNamingConventionForSpELCheck.java +++ b/java-checks-test-sources/src/main/java/checks/spring/ModelAttributeNamingConventionForSpELCheck.java @@ -3,6 +3,7 @@ import java.io.File; import java.util.HashMap; import java.util.Map; +import org.springframework.ui.Model; class ModelAttributeNamingConventionForSpELCheck { @@ -42,6 +43,13 @@ public void foo(org.springframework.ui.Model model) { model.addAttribute("$d", 8); // Compliant model.addAllAttributes(new HashMap<>()); // Compliant - test coverage + model.addAllAttributes(Map.of()); + + + } + + public void modelAttribute(Model model, String name, Object value) { // Compliant + model.addAttribute(name, value); } private Map getMap() { diff --git a/java-checks/src/main/java/org/sonar/java/checks/spring/ModelAttributeNamingConventionForSpELCheck.java b/java-checks/src/main/java/org/sonar/java/checks/spring/ModelAttributeNamingConventionForSpELCheck.java index 174103dae3f..a34068ed6e4 100644 --- a/java-checks/src/main/java/org/sonar/java/checks/spring/ModelAttributeNamingConventionForSpELCheck.java +++ b/java-checks/src/main/java/org/sonar/java/checks/spring/ModelAttributeNamingConventionForSpELCheck.java @@ -91,7 +91,7 @@ private void checkStringLiteralAndReport(ExpressionTree tree, ExpressionTree rep private void checkIdentifier(IdentifierTree identifierTree) { VariableTreeImpl declaration = (VariableTreeImpl) identifierTree.symbol().declaration(); - if (declaration != null) { + if (declaration != null && declaration.initializer()!=null) { checkExpression(declaration.initializer(), identifierTree); } }