Skip to content

[SpEL] Problem with uppercase property names [SPR-9123] #13761

@spring-projects-issues

Description

@spring-projects-issues

Ralph Schaer opened SPR-9123 and commented

Looks like SpEL has a problem with property names where the second character is uppercase.

 
public class TestObject {
	private String iD;
}

According to the Java Bean Specification the get and set method have to be named like this. This is also the code Eclipse generates with the "Source->Generate Getters and Setters" function.

public String getiD() {
     return iD;
}
public void setiD(String iD) {
     this.iD = iD;
}

Now I try to access the property iD with SpEL

 
TestObject to = new TestObject();
to.setiD("a ID");
ExpressionParser expressionParser = new SpelExpressionParser();
Expression idExpression = expressionParser.parseExpression("iD");
String anId = idExpression.getValue(to, String.class);

This code throws an exception
org.springframework.expression.spel.SpelEvaluationException: EL1008E:(pos 0): Field or property 'iD' cannot be found on object of type 'TestObject'

The PropertyUtils class from the Apache commons-beanutils project works:

 
PropertyUtils.getProperty(to, "iD")

Affects: 3.1.1

Issue Links:

Referenced from: commits d91a419, 0ca11d2, 1f28bdf

1 votes, 3 watchers

Metadata

Metadata

Assignees

No one assigned

    Labels

    in: coreIssues in core modules (aop, beans, core, context, expression)type: bugA general bug

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions