设为首页 加入收藏

TOP

深入Spring Boot: 怎样排查 java.lang.ArrayStoreException(二)
2018-03-11 09:11:29 】 浏览:2281
Tags:深入 Spring Boot: 怎样 排查 java.lang.ArrayStoreException
SE] at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping.afterPropertiesSet(RequestMappingHandlerMapping.java:129) ~[spring-webmvc-5.0.4.RELEASE.jar:5.0.4.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1769) ~[spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1706) ~[spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE] ... 16 common frames omitted

使用 Java Exception Breakpoint

下面来排查这个问题。

在IDE里,新建一个断点,类型是Java Exception Breakpoint(如果不清楚怎么添加,可以搜索对应IDE的使用文档),异常类是上面抛出来的java.lang.ArrayStoreException

当断点起效时,查看AnnotationUtils.findAnnotation(Class<?>, Class<A>, Set<Annotation>) line: 686 函数的参数。

可以发现

  • clazz是 class com.example.springboot1starter.MyHealthIndicatorAutoConfiguration$$EnhancerBySpringCGLIB$$945c1f
  • annotationType是 interface org.springframework.boot.actuate.endpoint.annotation.Endpoint

说明是尝试从MyHealthIndicatorAutoConfiguration里查找@Endpoint信息时出错的。

MyHealthIndicatorAutoConfiguration上的确没有@Endpoint,但是为什么抛出java.lang.ArrayStoreException?

尝试以简单例子复现异常

首先尝试直接 new MyHealthIndicatorAutoConfiguration :

    public static void main(String[] args) {
        MyHealthIndicatorAutoConfiguration cc = new MyHealthIndicatorAutoConfiguration();
    }

本以为会抛出异常来,但是发现执行正常。

再仔细看异常栈,可以发现是在at java.lang.Class.getDeclaredAnnotation(Class.java:3458)抛出的异常,则再尝试下面的代码:

    public static void main(String[] args) {
        MyHealthIndicatorAutoConfiguration.class.getDeclaredAnnotation(Endpoint.class);
    }

发现可以复现异常了:

Exception in thread "main" java.lang.ArrayStoreException: sun.reflect.annotation.TypeNotPresentExceptionProxy
    at sun.reflect.annotation.AnnotationParser.parseClassArray(AnnotationParser.java:724)
    at sun.reflect.annotation.AnnotationParser.parseArray(AnnotationParser.java:531)
    at sun.reflect.annotation.AnnotationParser.parseMemberValue(AnnotationParser.java:355)
    at sun.reflect.annotation.AnnotationParser.parseAnnotation2(AnnotationParser.java:286)
    at sun.reflect.annotation.AnnotationParser.parseAnnotations2(AnnotationParser.java:120)
    at sun.reflect.annotation.AnnotationParser.parseAnnotations(AnnotationParser.java:72)
    at java.lang.Class.createAnnotationData(Class.java:3521)
    at java.lang.Class.annotationData(Class.java:3510)
    at java.lang.Class.getDeclaredAnnotation(Class.java:3458)

 

为什么会是java.lang.ArrayStoreException

再仔细看异常信息:java.lang.ArrayStoreException: sun.reflect.annotation.TypeNotPresentExceptionProxy

ArrayStoreException是一个数组越界的异常,它只有一个String信息,并没有cause

那么我们尝试在 sun.reflect.annotation.TypeNotPresentExceptionProxy 的构造函数里打断点。

public class TypeNotPresentExceptionProxy extends ExceptionProxy {
    private static final long serialVersionUID = 5565925172427947573L;
    String typeName;
    Throwable cause;

    public TypeNotPresentExceptionProxy(String typeName, Throwable cause) {
        this.typeName = typeName;
        this.cause = cause;
    }

在断点里,我们可以发现:

  • typeName是 o
首页 上一页 1 2 3 下一页 尾页 2/3/3
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇MySQL 系统变量配置基础 下一篇使用Java函数接口及lambda表达式..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目