Why is this an issue?

Spring Expression Language (SpEL) is an expression language used in the Spring Framework for evaluating and manipulating objects, properties, and conditions within Spring-based applications.

org.springframework.ui.Model is an interface in the Spring Framework that represents a container for data that can be passed between a controller and a view in a Spring MVC web application, allowing for data sharing during the request-response cycle.

Attributes added to the org.springframework.ui.Model should follow the Java identifier naming convention, which means they must start with a letter a-z, A-Z, underscore _, or a dollar sign $ and may be followed by letters, digits, underscores, or dollar signs.

Failure to do so may result in SpEL parsing errors when using these attributes in template engines.

How to fix it

Follow the Java identifier naming convention.

Code examples

Noncompliant code example

model.addAttribute(" a", 100); // Noncompliant (starts with a space)
model.addAttribute("a-b", 7);  // Noncompliant (contains a hyphen)
model.addAttribute("1c", 42);  // Noncompliant (starts with a digit)

Compliant solution

model.addAttribute("a", 100);
model.addAttribute("b", 42);
model.addAttribute("_c", 7);
model.addAttribute("$d", 8);

Resources

Documentation