Skip to content

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

Closed

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:

Activity

  1. spring-projects-issues commented on Jun 28, 2012

    @spring-projects-issues
    CollaboratorAuthor

    Satyapal Reddy commented

    I have a potential fix for this and wondering if I should go github route to submit my fix. We are releasing our product in next two months and wondering if we could this fix.

    Thanks

  2. spring-projects-issues commented on Jun 29, 2012

    @spring-projects-issues
    CollaboratorAuthor

    Chris Beams commented

    Hi Satya,

    Please do go ahead with a pull request per the contributor guidelines, and I'll follow up from there. Thanks!

  3. spring-projects-issues commented on Aug 6, 2012

    @spring-projects-issues
    CollaboratorAuthor

    Satyapal Reddy commented

    I made a pull request : #114

  4. spring-projects-issues commented on Aug 6, 2012

    @spring-projects-issues
    CollaboratorAuthor

    Chris Beams commented

    @Andy (added as watcher), you might want to take a look at this pull request and comment: #114

  5. spring-projects-issues commented on Aug 10, 2012

    @spring-projects-issues
    CollaboratorAuthor

    Satyapal Reddy commented

    Thanks for the comments on the pull request Andy.

    We currently use 3.1.1 of spring framework. Is there any possibility of backporting this fix to 3.1.x?

  6. spring-projects-issues commented on Aug 16, 2012

    @spring-projects-issues
    CollaboratorAuthor

    Satyapal Reddy commented

    Hi Chris,

    Any chance this can make into 3.1.3 ?

    Satya

  7. spring-projects-issues commented on Oct 18, 2012

    @spring-projects-issues
    CollaboratorAuthor

    Chris Beams commented

    Hi Satya, yes, I've just scheduled this for 3.1.3.

  8. spring-projects-issues commented on Oct 24, 2012

    @spring-projects-issues
    CollaboratorAuthor

    Chris Beams commented

    3.2 RC1 (master):

    commit be8f23d75658a8b728912b644c138407d4914f8b
    Author: Satyapal Reddy <[email protected]>
    Commit: Chris Beams <[email protected]>
    
        Add SpEL support for float literals
        
        This change ensures that SpEL expressions involving floats are
        supported natively as opposed to the previous behavior which required
        conversion to double, leading to potential downstream conversion
        ambiguities.
        
        Issue: SPR-9486
    

    3.1.3 (3.1.x):

    commit a94677e7b6d6c6f506a7ac06d9958cb780d42fbb
    Author: Satyapal Reddy <[email protected]>
    Commit: Chris Beams <[email protected]>
    
        Add SpEL support for float literals
        
        This change ensures that SpEL expressions involving floats are
        supported natively as opposed to the previous behavior which required
        conversion to double, leading to potential downstream conversion
        ambiguities.
        
        Issue: SPR-9486
        Backport-Commit: be8f23d75658a8b728912b644c138407d4914f8b
    

    Update: several related commits followed those shown above in order to catch a couple failing tests. git log --grep SPR-9486 on master or 3.1.x to see everything.

  9. added
    type: enhancement
    in: core
    on Jan 11, 2019
  10. added this to the 3.1.3 milestone on Jan 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    in: coretype: enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions