Skip to content

Add SpEL support for float literals [SPR-9486] #14121

@spring-projects-issues

Description

@spring-projects-issues

Satyapal Reddy opened SPR-9486 and commented

I have two functions:

public class FunctionsClass {
  public int abs(int value) { return Math.abs(value); }
  public float abs(float value) { return Math.abs(value); } }
}

and when I execute the test with following code:

FunctionsClass testObject = new FunctionsClass();
StandardEvaluationContext context = new StandardEvaluationContext();
org.springframework.expression.Expression expression = parser.parseExpression("abs(-10.2f)");
Number result = expression.getValue(context, testObject, Number.class);

it fails with:

Caused by: org.springframework.expression.spel.SpelEvaluationException: EL1033E:(pos 0): Method call of 'abs' is ambiguous, supported type conversions allow multiple variants to match

This is due to -10.2f being treated as double, and then they are eligible for type conversions to int and float and hence the ambiguity


Affects: 3.1.1

Attachments:

Issue Links:

Metadata

Metadata

Assignees

No one assigned

    Labels

    in: coreIssues in core modules (aop, beans, core, context, expression)type: enhancementA general enhancement

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions