The SPEL is "new java.math.BigDecimal(#source['unitPrice'])", the first time source['unitPrice'] is null. org.springframework.expression.spel.support.ReflectiveConstructorResolver#resolve find a random BigDecimal's Constructor that it's argument's length is 1. In my case, the constructor is java.math.BigDecimal#BigDecimal(char[]). Then, source['unitPrice'] is 3.68, new java.math.BigDecimal occur exception because the 3.68 is convert to type char[] - char[]{'3'} in org.springframework.expression.spel.support.ReflectiveConstructorExecutor#execute.

1.sort by parameter length get random result in same length constructor

    @Override
    public ConstructorExecutor resolve(EvaluationContext context, String typeName, List<TypeDescriptor> argumentTypes)
            throws AccessException {

        try {
            TypeConverter typeConverter = context.getTypeConverter();
            Class<?> type = context.getTypeLocator().findType(typeName);
            Constructor<?>[] ctors = type.getConstructors();

            Arrays.sort(ctors, new Comparator<Constructor<?>>() {
                @Override
                public int compare(Constructor<?> c1, Constructor<?> c2) {
                    int c1pl = c1.getParameterTypes().length;
                    int c2pl = c2.getParameterTypes().length;
                    return (c1pl < c2pl ? -1 : (c1pl > c2pl ? 1 : 0));
                }
            });
    ..........

2.convert argument error or loss of precision

    public TypedValue execute(EvaluationContext context, Object... arguments) throws AccessException {
        try {
            if (arguments != null) {
                ReflectionHelper.convertArguments(context.getTypeConverter(), arguments, this.ctor, this.varargsPosition);
            }
            if (this.ctor.isVarArgs()) {
                arguments = ReflectionHelper.setupArgumentsForVarargsInvocation(this.ctor.getParameterTypes(), arguments);
            }
            ReflectionUtils.makeAccessible(this.ctor);
            return new TypedValue(this.ctor.newInstance(arguments));
        }
        catch (Exception ex) {
            throw new AccessException("Problem invoking constructor: " + this.ctor, ex);
        }
    }

Comment From: rstoyanchev

I've edited your comment to improve the formatting. You might want to check out this Mastering Markdown guide for future reference. Also, it's less helpful to paste images than to link to the source code.

Comment From: hotmocha

I've edited your comment to improve the formatting. You might want to check out this Mastering Markdown guide for future reference. Also, it's less helpful to paste images than to link to the source code.

Thank you for your suggestion!! 🙂

Comment From: anishlukk123

is this still an issue, if not we can close the ticket. if it is still issue i would like to be assigned this ticket

Comment From: sbrannen

@anishlukk123, the team has not yet had time to investigate this.

If you would like to assist with this, we would be grateful if you could provide a minimal example that reproduces the claimed behavior -- preferably in the form of a JUnit Jupiter based test.

Once we have a means to reproduce the issue, we will then be able to decide what steps to take next (if any).

Comment From: snicoll

@hotmocha can you please share the sample that we've requested? We prefer a sample that demonstrates the issue rather than copy/pasting our own code as the analysis may not reveal a full context.

Comment From: spring-projects-issues

If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.

Comment From: spring-projects-issues

Closing due to lack of requested feedback. If you would like us to look at this issue, please provide the requested information and we will re-open the issue.