Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SpEL: 'select last' operator for maps has inconsistent behavior [SPR-7323] #11981

Closed
spring-projects-issues opened this issue Jun 26, 2010 · 2 comments
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: bug A general bug
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

Sam Brannen opened SPR-7323 and commented

The inconsistent behavior is due to improper tracking of the lastKey for maps in Selection.getValueInternal(ExpressionState).

The following can be used to reproduce the bug:

class MapTestBean {

	private final Map<String, String> colors = new TreeMap<String, String>();

	MapTestBean() {
		colors.put("red", "rot");
		colors.put("brown", "braun");
		colors.put("blue", "blau");
		colors.put("yellow", "gelb");
		colors.put("beige", "beige");
	}

	public Map<String, String> getColors() {
		return colors;
	}
}
EvaluationContext context = new StandardEvaluationContext(new MapTestBean());
ExpressionParser parser = new SpelExpressionParser();

Expression exp = parser.parseExpression("colors.$[key.startsWith('b')]");
Map<String, String> colorsMap = (Map<String, String>) exp.getValue(context);

assertEquals(1, colorsMap.size());
assertEquals("brown", colorsMap.keySet().iterator().next());

The above test currently fails with:

org.junit.ComparisonFailure: expected:<[brown]> but was:<[yellow]>

Affects: 3.0.3

Referenced from: commits 8bd0633, db7531b

@spring-projects-issues
Copy link
Collaborator Author

Sam Brannen commented

Added code to reproduce bug.

@spring-projects-issues
Copy link
Collaborator Author

Sam Brannen commented

SpEL 'select last' operator now works consistently with maps.

@spring-projects-issues spring-projects-issues added type: bug A general bug in: core Issues in core modules (aop, beans, core, context, expression) labels Jan 11, 2019
@spring-projects-issues spring-projects-issues added this to the 3.0.4 milestone Jan 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: bug A general bug
Projects
None yet
Development

No branches or pull requests

2 participants