stacktrace: java.lang.ClassCastException: java.util.HashMap cannot be cast to[通俗易懂]

stacktrace: java.lang.ClassCastException: java.util.HashMap cannot be cast to[通俗易懂]今天线上发了好几封预警邮件,邮件内容如下:看了下项目报错的代码:ApiResult<WithdrawResultDto>withdrawResult=loanApiService.queryWithdrawResult(contractNo);WithdrawResultDtowithdraw=withdrawResult.getDa…

大家好,又见面了,我是你们的朋友全栈君。如果您正在找激活码,请点击查看最新教程,关注关注公众号 “全栈程序员社区” 获取激活教程,可能之前旧版本教程已经失效.最新Idea2022.1教程亲测有效,一键激活。

Jetbrains全系列IDE使用 1年只要46元 售后保障 童叟无欺

今天线上发了好几封预警邮件,邮件内容如下:

在这里插入图片描述

看了下项目报错的代码:

        ApiResult<WithdrawResultDto> withdrawResult = loanApiService.queryWithdrawResult(contractNo);
        WithdrawResultDto withdraw = withdrawResult.getData();

ApiResult 的代码:

public class ApiResult<T> implements Serializable {
    private static final long serialVersionUID = 1L;
    private boolean success;
    private String code;
    private String message;
    private String requestId;
    private T data;

    private ApiResult() {
    }
 }

发现逻辑上是完全没有问题的,报错是第二行代码,又看了下日志,终于发现了问题的原因:

[NettyClientWorker-thread-13{New I/O client worker #1-13}]  |-|WARN  |-|2018-12-19T16:42:37.938+08:00  |-|c.a.c.c.h.i.SerializerFactory[652]  |-|Hessian/Burla
p: 'com.xxxx.malm.api.protoss.dto.WithdrawResultDto' is an unknown class in org.springframework.boot.loader.LaunchedURLClassLoader@507b79f7:
java.lang.ClassNotFoundException: com.mljr.malm.api.protoss.dto.WithdrawResultDto  |-|
[DubboServerHandler-10.8.104.106:24475-thread-199]  |-|INFO  |-|2018-12-19T16:42:37.940+08:00  |-|c.m.a.b.a.d.s.i.DeductionServiceImpl[268]  |-|【撤销结
算单】查询数据返回信息:{"code":"0","data":{"payUsStatus":2,"no":"18121710054227356449","withholdingRequire":1,"withdrawType":0,"lendingWay":1
,"withdrawStatus":3},"message":"成功","success":true};业务编号为18121710054227356449  |-|
[DubboServerHandler-10.8.104.106:24475-thread-199]  |-|ERROR  |-|2018-12-19T16:42:37.940+08:00  |-|c.m.a.b.a.d.f.BgisDeductionFacadeImpl[96]  |-|【结算
单撤销】系统异常,异常原因:  |-|
java.lang.ClassCastException: java.util.HashMap cannot be cast to com.xxxx.malm.api.mac.dto.WithdrawResultDto
        at com.xxxx.acs.xxxx.apps.deduction.service.impl.DeductionServiceImpl.isCancelByTerm(DeductionServiceImpl.java:273)
        at com.xxxx.acs.xxxx.apps.deduction.service.impl.DeductionServiceImpl.cancelDeduction(DeductionServiceImpl.java:245)
        at com.xxxx.acs.xxxx.apps.deduction.biz.impl.DeductionBizImpl.cancelDeductionBill(DeductionBizImpl.java:110)
        at com.xxxx.acs.xxxx.apps.deduction.facade.BgisDeductionFacadeImpl.cancelDeductionBill(BgisDeductionFacadeImpl.java:88)
        at com.alibaba.dubbo.common.bytecode.Wrapper107.invokeMethod(Wrapper107.java)
        at com.alibaba.dubbo.rpc.proxy.javassist.JavassistProxyFactory$1.doInvoke(JavassistProxyFactory.java:46)
        at com.alibaba.dubbo.rpc.proxy.AbstractProxyInvoker.invoke(AbstractProxyInvoker.java:72)
        at com.alibaba.dubbo.rpc.protocol.InvokerWrapper.invoke(InvokerWrapper.java:53)
        at com.alibaba.dubbo.rpc.filter.ExceptionFilter.invoke(ExceptionFilter.java:64)
        at com.alibaba.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:69)
        at com.alibaba.dubbo.monitor.support.MonitorFilter.invoke(MonitorFilter.java:75)
        at com.alibaba.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:69)
        at com.alibaba.dubbo.rpc.filter.TimeoutFilter.invoke(TimeoutFilter.java:42)
        at com.alibaba.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:69)
        at com.alibaba.dubbo.rpc.filter.AccessLogFilter.invoke(AccessLogFilter.java:154)
        at com.alibaba.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:69)

前面的warning 信息指出:‘com.xxxx.malm.api.protoss.dto.WithdrawResultDto’ is an unknown class…
后面报 ClassCastException 的却是com.xxxx.malm.api.mac.dto.WithdrawResultDto。

看到这里,我忽然就想到了,应该是其他组的api 中涉及的dto 修改了路径,但是我们用的还是低版本的老路径,在执行下面的代码时,相当于类型的转换(从T到WithdrawResultDto):

WithdrawResultDto withdraw = withdrawResult.getData();

因为转换的时候涉及到读取对象的全路径,全路径不一致,就报错了。

最后就是我们升级下 调用的 api 的版本,使用新路径就好了?

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/195718.html原文链接:https://javaforall.cn

【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛

【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...

(1)


相关推荐

发表回复

您的电子邮箱地址不会被公开。

关注全栈程序员社区公众号