Affects: 5.3.10,The same goes for the latest version 5.3.16

The Spring Framework source code for the last step is

package org.springframework.expression.spel.ast.SpelNodeImpl 
@Override
    public void setValue(ExpressionState expressionState, @Nullable Object newValue) throws EvaluationException {
        throw new SpelEvaluationException(getStartPosition(), SpelMessage.SETVALUE_NOT_SUPPORTED, getClass());
    }

Why does this method throw an exception directly? Why does the same expression, getValue, work correctly, while setValue reports an error? I think it might be a bug, normally, the get method should work just as well as the set method,or maybe I'm using it the wrong way? If you have any questions, please point them out to me. Thank you very much!!!

The entry object is as follows

@Accessors(chain = true)
@Data
public class OutDtoDigestLogDemo {
    private InDtoDigestLogDemo inDtoDigestLogDemo;

    public InDtoDigestLogDemo getInDtoDigestLogDemo() {
        return inDtoDigestLogDemo;
    }
}


@Accessors(chain = true)
@Data
public class InDtoDigestLogDemo {

    private List<InnerDtoDigestLogDemo> innerDtoDigestLogDemoList = new ArrayList<>();
    private List<InnerSecondDtoDigestLogDemo> innerSecondDtoDigestLogDemos = new ArrayList<>();}


@Accessors(chain = true)
@Data
public class InnerDtoDigestLogDemo {
    private String demoStr;

    private String demo;

    private String str;}



@Accessors(chain = true)
@Data
public class InnerSecondDtoDigestLogDemo {
    private String demoStrSecond;

    private String demoSecond;

    private String strSecond;}

The test method is as follows

    /*githubDemo*/
    public OutDtoDigestLogDemo getListRequestParam() {
        OutDtoDigestLogDemo outDtoDigestLogDemo = new OutDtoDigestLogDemo();
        InDtoDigestLogDemo inDtoDigestLogDemo = new InDtoDigestLogDemo();
        InnerDtoDigestLogDemo innerDtoDigestLogDemo1 = new InnerDtoDigestLogDemo();
        InnerDtoDigestLogDemo innerDtoDigestLogDemo2 = new InnerDtoDigestLogDemo();
        InnerDtoDigestLogDemo innerDtoDigestLogDemo3 = new InnerDtoDigestLogDemo();
        innerDtoDigestLogDemo1.setDemoStr("12313").setDemo("456465465").setStr(",,,,");
        innerDtoDigestLogDemo2.setDemoStr("3145342").setDemo("sfsf").setStr(".....");
        innerDtoDigestLogDemo3.setDemoStr("543235").setDemo("gssg").setStr("!!!!");

        InnerSecondDtoDigestLogDemo innerSecondDtoDigestLogDemo1 = new InnerSecondDtoDigestLogDemo();
        InnerSecondDtoDigestLogDemo innerSecondDtoDigestLogDemo2 = new InnerSecondDtoDigestLogDemo();
        InnerSecondDtoDigestLogDemo innerSecondDtoDigestLogDemo3 = new InnerSecondDtoDigestLogDemo();
        innerSecondDtoDigestLogDemo1.setDemoStrSecond("12313").setDemoSecond("456465465").setStrSecond(",,,,");
        innerSecondDtoDigestLogDemo2.setDemoStrSecond("3145342").setDemoSecond("sfsf").setStrSecond(".....");
        innerSecondDtoDigestLogDemo3.setDemoStrSecond("543235").setDemoSecond("gssg").setStrSecond("!!!!");

        List<InnerDtoDigestLogDemo> innerDtoDigestLogDemos
                = Arrays.asList(innerDtoDigestLogDemo1, innerDtoDigestLogDemo2, innerDtoDigestLogDemo3);
        List<InnerSecondDtoDigestLogDemo> innerSecondDtoDigestLogDemos
                = Arrays.asList(innerSecondDtoDigestLogDemo1, innerSecondDtoDigestLogDemo2, innerSecondDtoDigestLogDemo3);
        inDtoDigestLogDemo.setInnerDtoDigestLogDemoList(innerDtoDigestLogDemos).setInnerSecondDtoDigestLogDemos(innerSecondDtoDigestLogDemos);
        outDtoDigestLogDemo.setInDtoDigestLogDemo(inDtoDigestLogDemo);
        return outDtoDigestLogDemo;
    }

    @Test
    public void testGetValue() {
        String[] expressions = new String[]{"#request.inDtoDigestLogDemo.innerDtoDigestLogDemoList.![#this.demoStr]"};
        SpelExpressionParser parser = new SpelExpressionParser();
        // spring的表达式上下文对象
        EvaluationContext context = new StandardEvaluationContext();
        // 给上下文赋值
        context.setVariable("request", getListRequestParam());
        String printFiledValue;
        //获取关注参数
        // 解析过后的Spring表达式对象
        List<Expression> expressionList = Arrays.stream(expressions)
                .map(parser::parseExpression)
                .collect(Collectors.toList());
        printFiledValue = expressionList.stream()
                .map(expression -> Objects.nonNull(expression.getValue(context)) ? expression.getValue(context).toString() : "")
                .map(attentionFiledValueStr -> attentionFiledValueStr.replaceAll(",", "==&=="))
                .collect(Collectors.joining("==&=="));
        printFiledValue = StringUtils.isBlank(printFiledValue) ? "" : printFiledValue;
        System.out.println("============================================================");
        System.out.println(printFiledValue);
    }

    @Test
    public void testSetValue() {
        String[] expressions = new String[]{"#request.inDtoDigestLogDemo.innerDtoDigestLogDemoList.![#this.demoStr]"};
        SpelExpressionParser parser = new SpelExpressionParser();
        // spring的表达式上下文对象
        EvaluationContext context = new StandardEvaluationContext();
        // 给上下文赋值
        context.setVariable("request", getListRequestParam());
        String printFiledValue;
        // 解析过后的Spring表达式对象
        List<Expression> expressionList = Arrays.stream(expressions)
                .map(parser::parseExpression)
                .collect(Collectors.toList());
        expressionList.forEach(expression -> expression.setValue(context, null));
        //之后取出所有的参数put进一个map
        Map<String, Object> paramsMap = Maps.newHashMap();
        String expressionStr = "#request";
        Expression expression = parser.parseExpression(expressionStr);
        paramsMap.put("request", expression.getValue(context));
        String jsonString = JSON.toJSONString(paramsMap);
        printFiledValue = jsonString.replaceAll(",", "==&==");
        printFiledValue = StringUtils.isBlank(printFiledValue) ? "" : printFiledValue;
        System.out.println("============================================================");
        System.out.println(printFiledValue);
    }

Comment From: snicoll

Duplicate of #28092

Please review the suggestions in the other issue you've already created.