使用IDEA异常断点来定位java.lang.ArrayStoreException的问题
作者:空山新雨 发布时间:2022-06-14 00:43:18
前言
最近对 base-spring-boot 项目进行了升级。在将其用于应用开发中时遇到java.lang.ArrayStoreException的异常导致程序无法启动。平常开发过程中面对这种描述不够清楚,无法定位具体原因的问题该如何处理?本文分享通过使用IDEA异常断点来定位此类问题的方法。
启动程序时抛出如下异常,导致启动失败
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'devGlobalExceptionHandler' defined in class path resource [cn/jboost/springboot/autoconfig/error/exception/ExceptionHandlerAutoConfiguration.class]: Post-processing of merged bean definition failed; nested exception is java.lang.ArrayStoreException: sun.reflect.annotation.TypeNotPresentExceptionProxy
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:570) ~[spring-beans-5.1.7.RELEASE.jar:5.1.7.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:515) ~[spring-beans-5.1.7.RELEASE.jar:5.1.7.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:320) ~[spring-beans-5.1.7.RELEASE.jar:5.1.7.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[spring-beans-5.1.7.RELEASE.jar:5.1.7.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318) ~[spring-beans-5.1.7.RELEASE.jar:5.1.7.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) ~[spring-beans-5.1.7.RELEASE.jar:5.1.7.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:843) ~[spring-beans-5.1.7.RELEASE.jar:5.1.7.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:877) ~[spring-context-5.1.7.RELEASE.jar:5.1.7.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:549) ~[spring-context-5.1.7.RELEASE.jar:5.1.7.RELEASE]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:142) ~[spring-boot-2.1.5.RELEASE.jar:2.1.5.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:775) [spring-boot-2.1.5.RELEASE.jar:2.1.5.RELEASE]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397) [spring-boot-2.1.5.RELEASE.jar:2.1.5.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:316) [spring-boot-2.1.5.RELEASE.jar:2.1.5.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1260) [spring-boot-2.1.5.RELEASE.jar:2.1.5.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1248) [spring-boot-2.1.5.RELEASE.jar:2.1.5.RELEASE]
at com.cnbot.kindergarten.CnbotKindergartenApplication.main(CnbotKindergartenApplication.java:10) [classes/:na]
Caused by: java.lang.ArrayStoreException: sun.reflect.annotation.TypeNotPresentExceptionProxy
at sun.reflect.annotation.AnnotationParser.parseClassArray(AnnotationParser.java:724) ~[na:1.8.0_201]
at sun.reflect.annotation.AnnotationParser.parseArray(AnnotationParser.java:531) ~[na:1.8.0_201]
at sun.reflect.annotation.AnnotationParser.parseMemberValue(AnnotationParser.java:355) ~[na:1.8.0_201]
at sun.reflect.annotation.AnnotationParser.parseAnnotation2(AnnotationParser.java:286) ~[na:1.8.0_201]
at sun.reflect.annotation.AnnotationParser.parseAnnotations2(AnnotationParser.java:120) ~[na:1.8.0_201]
at sun.reflect.annotation.AnnotationParser.parseAnnotations(AnnotationParser.java:72) ~[na:1.8.0_201]
...
单纯看异常栈,无法定位问题原因,只能看到是在调用devGlobalExceptionHandler创建bean时出错,错误信息java.lang.ArrayStoreException: sun.reflect.annotation.TypeNotPresentExceptionProxy。
这属于框架内部抛出的异常,通常的设置断点Debug的方法很难定位到具体原因,可通过IDEA的异常断点来进行定位,它会在程序运行过程中出现指定异常时进行阻断。
1. 添加异常断点
在IDEA的Debug面板中,点击“View Breakpoints”(两个重叠的红色圈按钮),如下
打开“Breakpoints”窗口,在该窗口中点击“+”按钮,选择“Java Exception Breakpoints”, 如下图
然后在弹出的“Enter Exception Class”窗口中输入ArrayStoreException选中对应异常,依次点击OK,Done按钮即完成异常断点添加。
2. 程序debug
开始以Debug模式启动程序。 程序运行后,在前面配置的异常出现时,将会进行阻断,如图
可以看到程序阻断在上图高亮的那行代码处,异常便是从这里抛出的。查看parseClassValue方法,可看到这里有catchTypeNotPresentException异常,并且包装成我们在异常栈看到的TypeNotPresentExceptionProxy返回。离真相很近了。
我们可以在上述catch块中添加一个断点,查看异常包装前的状态,如图
重新Debug运行,将定位到上图代码处,查看异常,看到如下图所示信息
该信息表示org.springframework.security.access.AccessDeniedException这个类不存在,导致BaseWebApplicationExceptionHandler类型的bean实例化时出错。这时候问题基本已经定位到了。
查看源码,在BaseWebApplicationExceptionHandler中有对AccessDeniedException的统一处理,但是spring-boot-autoconfigure所有的依赖都是optional的(不会传递依赖),而在新开发的项目中,并没有引入spring-security,因此导致AccessDeniedException这个类找不到而报错。目前通过去掉该部分处理解决。
总结
IDEA的Debug支持好几种断点类型,如前文介绍的异常断点,以及比较常用的条件断点等。当无法从异常栈信息找到问题所在时,借用这些类型的断点进行Debug,往往事情就变得简单了。
来源:http://blog.jboost.cn/2019/06/21/issue-errortrack.html


猜你喜欢
- 目录Bitmap类BitmapData类参考:Bitmap类Bitmap对象封装了GDI+中的一个位图,此位图由图形图像及其属性的像素数据组
- 原文是 java ,现在将它翻译成 C# ,并对代码重新编排整理,博主是一个今年刚出来的应届毕业生,不足之处请多多包涵。根据银行卡号判断所属
- 在POI的使用过程中,对大多数API User来说经常面临两个问题,这也是GridExcel致力解决的问题。问题1. 仅使用简单的导入导出功
- 在Java中从字符串中删除空格有很多不同的方法,如trim,replaceAll等。但是,在JDK 11添加了一些新的功能,如strip、s
- 进度条以一种客观化的方式,让我们知道程序正在执行的情况,在程序需要时间执行任务的时候,提示进度条友好的告诉用户说,当前任务还没有完成,请稍稍
- 1.拉取centos镜像docker pull centos:72.基于拉取到的镜像运行一个容器docker run -it --name
- 本文实例讲述了java采用中文方式显示时间的方法。分享给大家供大家参考。具体如下:其中t为秒,比如有时候需要计算两个任务相差多久,或者该任务
- 我就废话不多说了,大家还是直接看代码吧~Caused by: java.net.SocketException: Software caus
- 先来回忆下在mybatis中的resultMap作用和是什么resultMap的作用是什么在使用传统的mybatis时,我们一般都会在xml
- IP地址与整数之间的转换1、IP地址转换为整数原理:IP地址每段可以看成是8位无符号整数即0-255,把每段拆分成一个二进制形式组合起来,然
- 本文实例讲述了WinForm实现仿视频播放器左下角滚动新闻效果的方法。分享给大家供大家参考。具体实现方法如下:using System;us
- 前言这篇文章主要是从类中static修饰的成员变量,static修饰的成员方法这两个方面来讲解static,static成员变量的初始化会在
- 读取本地的xml文件,通过DOM进行解析,DOM解析的特点就是把整个xml文件装载入内存中,形成一颗DOM树形结构,树结构是方便遍历和和操纵
- 概述线上项目发布一般有以下几种方案:机发布蓝绿部署滚动部署灰度发布停机发布 这种发布一般在夜里或者进行大版本升级的时候发布,因为需要停机,所
- 我们知道HashMap集合是允许存放null值的hashMap是根据key的hashCode来寻找存放位置的,那当key为null时, 怎么
- 在使用java项目时,如果没有详细的管理和辅助流程,就会像程序失去了系统的调配一样。在java中有一种专门管理项目的工具,叫做maven,除
- 本文实例为大家分享了java桌球小游戏的具体代码,供大家参考,具体内容如下源码:import java.awt.*;import javax
- 刚开始学习Service的时候以为它是一个线程的封装,也可以执行耗时操作。其实不然,Service是运行在主线程的。直接执行耗时操作是会阻塞
- 之前一直在Android应用层上做工作,最近开始研究Android平台上的东东了,主要是在Android Frameworks层和系统库层进
- 通常在写程序的时候,当要用到某些组件,采用的方法一般都是动态创建,用完以后就释放掉。Visual C#在程序运行的时