本文主要是介绍stacktrace: java.lang.ClassCastException: java.util.HashMap cannot be cast to,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
今天线上发了好几封预警邮件,邮件内容如下:
看了下项目报错的代码:
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.WithdrawResultDtoat 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 的版本,使用新路径就好了?
这篇关于stacktrace: java.lang.ClassCastException: java.util.HashMap cannot be cast to的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!