Skip to content

Commit

Permalink
SONARJAVA-4645 Fix unchecked NPE on initializer on S6806 (4497)
Browse files Browse the repository at this point in the history
  • Loading branch information
erwan-serandour authored Oct 20, 2023
1 parent 92765dc commit 6dbbe3f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.io.File;
import java.util.HashMap;
import java.util.Map;
import org.springframework.ui.Model;

class ModelAttributeNamingConventionForSpELCheck {

Expand Down Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down

0 comments on commit 6dbbe3f

Please sign in to comment.