-
Notifications
You must be signed in to change notification settings - Fork 37.8k
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
Support BigDecimals with SpEL [SPR-9164] #13802
Comments
Chris Beams commented Added Andy Clement as watcher
Thanks! |
Oliver Becker commented I think the algorithm should be something along
|
Andy Clement commented This does need doing. I feel like widening byte/short/int to long value if not necessary might be overkill but I don't feel strongly enough that it shouldn't be done. Supporting BigDecimal/BigInteger in those referenced Op* classes should be added. Although not hard, care would need taking to do it in a way such that the code doesn't get too bloated with instanceof checks. Also needs test coverage, ideally for all cases/combinations. Don't think we have to take the further step of handling custom Number subtypes, that could be looked at when the scenario comes up. |
Chris Beams commented Andy, is this something you're willing to commit to for 3.2 M1 / M2? I'll assign to you if so. |
Stevo Slavić commented #13358 is somewhat related issue. |
Giovanni Dall'Oglio Risso commented Hi... I'm the reporter for the #13358 issue (related to this). We managed to solve this problem, adding BigDecimals; we also made a pull request: #80 You can take that pull request, or start by that code (we added quite test cases). PS: maybe you can consider to add also the BigIntegers support... |
Chris Beams commented I've asked Giovanni to touch up his pull request per the contributor guidelines. We can start with that support at least, which covers |
Satyapal Reddy commented I have two functions: public class FunctionsClass { and when I execute the test with following code:
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 |
Satyapal Reddy commented When I have two functions with different inputs int and float, eventhough I pass float, it is complaining about this being ambiguous |
Satyapal Reddy commented test case |
Giovanni Dall'Oglio Risso commented
I think that your problem (SpEL unable to find the correct method) should be described in a new issue. Regarding your problem, it seems that (at first glance) SPEL tries to find a function with the required signature, if not, try to find one that might fit (using converters), finds two candidates and does not know which one to apply. You might think to put in place a priority system depending on the type to convert. ...but pay attention, imagine you have this situation:
Then you go and evaluate
Which one of the two functions would you choose? So I think that it is necessary to open a new issue, and discuss it carefully in there. |
Satyapal Reddy commented
Thanks for the feedback. I will open a new bug. The possible fix that I tried locally (and that resolved my issue) involved introducing FloatLiteral.java and adding additional instanceof for Float. Satyapal |
Andy Clement commented I just reviewed the PR Giovanni again - made a couple of comments on it but in principal it is in reasonable shape. There seems to be some code duplication in the tests and the coding standards aren't quite right for the if blocks, but it works and all the existing expression tests are passing for me. Chris/Phil - would you expect the submitter to fix the code duplication and styling thing in the PR and resubmit or would you do that? |
Giovanni Dall'Oglio Risso commented This weekend I'm out, if you can wait, the first days of the next week I'll rebase and clean everything... Thanks |
Giovanni Dall'Oglio Risso commented Hello.
I rebased on master, hope is OK... |
Oliver Becker commented Big thanks to Giovanni and Andy for fixing this! |
Oliver Becker opened SPR-9164 and commented
When doing number arithmetic in SpEL the result type is apparently one of double, long or int.
This has the unwanted effect that for example float or BigDecimal values will be changed to int.
new java.math.BigDecimal("12.34")
evaluates to 12.34
-(new java.math.BigDecimal("12.34"))
evaluates to -12
see org.springframework.expression.spel.ast
OpPlus, OpMinus, OpMultiply, OpDivide
Affects: 3.1.1
Reference URL: #80
Attachments:
Issue Links:
1 votes, 7 watchers
The text was updated successfully, but these errors were encountered: