zoukankan      html  css  js  c++  java
  • Dubbo:'org.springframework.expression.spel.SpelEvaluationException' could not be instantiated

    某个跑数据的接口日志里发现了如下日常:

    [ New I/O client worker #1-1:158555 ] - [ WARN ] com.alibaba.dubbo.rpc.protocol.dubbo.DecodeableRpcResult.decode(DecodeableRpcResult.java:116)  [DUBBO] Decode rpc result failed: 'org.springframework.expression.spel.SpelEvaluationException' could not be instantiated, dubbo version: 2.6.2, current host: 192.168.x.x
    com.alibaba.com.caucho.hessian.io.HessianProtocolException: 'org.springframework.expression.spel.SpelEvaluationException' could not be instantiated
            at com.alibaba.com.caucho.hessian.io.JavaDeserializer.instantiate(JavaDeserializer.java:316)
            at com.alibaba.com.caucho.hessian.io.JavaDeserializer.readObject(JavaDeserializer.java:201)
            at com.alibaba.com.caucho.hessian.io.SerializerFactory.readObject(SerializerFactory.java:526)
    ...
    Caused by: java.lang.reflect.InvocationTargetException
            at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
            at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
            at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
            at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
            at com.alibaba.com.caucho.hessian.io.JavaDeserializer.instantiate(JavaDeserializer.java:312)
            ... 28 more
    Caused by: java.lang.NullPointerException
            at org.springframework.expression.spel.SpelEvaluationException.<init>(SpelEvaluationException.java:37)
            ... 33 more
    

    进一步在其调用的Dubbo接口所在的应用日志查看:

    |ERROR|DubboServerHandler-192.168:x.x:xxx-thread-488|c.a.d.r.f.ExceptionFilter:85
          [DUBBO] Got unchecked and undeclared exception which called by 192.168.x.x. service: com.biz.XxxService, method: xxx, exception: org.springframework.expression.spel.SpelEvaluationException: EL1007E:(pos 0): Property or field 'createTimestamp' cannot be found on null, dubbo version: x, current host: 192.168.x.x
    org.springframework.expression.spel.SpelEvaluationException: EL1007E:(pos 0): Property or field 'createTimestamp' cannot be found on null
            at org.springframework.expression.spel.ast.PropertyOrFieldReference.readProperty(PropertyOrFieldReference.java:220)
            at org.springframework.expression.spel.ast.PropertyOrFieldReference.getValueInternal(PropertyOrFieldReference.java:94)
            at org.springframework.expression.spel.ast.PropertyOrFieldReference.getValueInternal(PropertyOrFieldReference.java:81)
            at org.springframework.expression.spel.ast.SpelNodeImpl.getValue(SpelNodeImpl.java:120)
            at org.springframework.expression.spel.standard.SpelExpression.getValue(SpelExpression.java:242)
            at com.xxx.ExpressionUtil...
    ...
    

    某个转换使用了Spring的Express表达式,其中对象为null时,抛了一个SpelEvaluationException异常,
    org.springframework.expression.spel.ast.PropertyOrFieldReference的220行:

    if (contextObject.getValue() == null) {
        throw new SpelEvaluationException(SpelMessage.PROPERTY_OR_FIELD_NOT_READABLE_ON_NULL, name);
    }
    

    SpelEvaluationException最终继承与EvaluationException,但它本身缺少了无参构造函数,因此在Dubbo的调用方提示不能实例化。

    解决方法:

    1. 修正通过Spring的Express表达式处理,增量null值判断;
    2. 捕获SpelEvaluationException,转换为该服务的业务异常。
  • 相关阅读:
    iOS拓展---[转载]视频相关,一定要看呀
    iOS拓展---碰到奇葩需求
    iOS拓展---【转载】成熟的夜间模式解决方案
    2018年度总结
    linux常用命令
    自我认识
    SpringBoot入门最详细教程
    SVN分支的合并和同步
    java Data、String、Long三种日期类型之间的相互转换
    徐胜治:我要留下真正的东西
  • 原文地址:https://www.cnblogs.com/cdfive2018/p/14024023.html
Copyright © 2011-2022 走看看