2015-11-14 48 views
0

我試圖使用FasterXML Jackson-Databind爲了從JSON文件加載配置。嘗試使用Jackson加載配置時發生異常

我的應用程序使用AspectJ。方面J通過以下命令行開關加載:「-javaagent:target \ aspectjweaver-1.6.12.jar」。

當我嘗試加載配置而不啓動AspectJ時,一切正常。

當我嘗試加載使用AspectJ的配置,我碰到下面的錯誤堆棧:

Exception in thread "main" java.lang.ExceptionInInitializerError 
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) 
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39) 
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27) 
    at java.lang.reflect.Constructor.newInstance(Constructor.java:513) 
    at java.lang.reflect.Proxy.newInstance(Proxy.java:717) 
    at java.lang.reflect.Proxy.newProxyInstance(Proxy.java:708) 
    at sun.reflect.annotation.AnnotationParser.annotationForMap(AnnotationParser.java:239) 
    at sun.reflect.annotation.AnnotationParser.parseAnnotation(AnnotationParser.java:229) 
    at sun.reflect.annotation.AnnotationParser.parseAnnotations2(AnnotationParser.java:69) 
    at sun.reflect.annotation.AnnotationParser.parseAnnotations(AnnotationParser.java:52) 
    at java.lang.Class.initAnnotationsIfNecessary(Class.java:3079) 
    at java.lang.Class.getAnnotation(Class.java:3038) 
    at sun.reflect.annotation.AnnotationType.<init>(AnnotationType.java:113) 
    at sun.reflect.annotation.AnnotationType.getInstance(AnnotationType.java:66) 
    at sun.reflect.annotation.AnnotationParser.parseAnnotation(AnnotationParser.java:202) 
    at sun.reflect.annotation.AnnotationParser.parseAnnotations2(AnnotationParser.java:69) 
    at sun.reflect.annotation.AnnotationParser.parseAnnotations(AnnotationParser.java:52) 
    at java.lang.Class.initAnnotationsIfNecessary(Class.java:3079) 
    at java.lang.Class.getAnnotation(Class.java:3038) 
    at com.fasterxml.jackson.databind.introspect.VisibilityChecker$Std.<clinit>(VisibilityChecker.java:170) 
    at com.fasterxml.jackson.databind.ObjectMapper.<clinit>(ObjectMapper.java:261) 
    at com.mytest.core.ConfigurationManager.loadConfiguration(ConfigurationManager.java:44) 
    at com.mytest.core.ConfigurationManager.getOrLoadConfigurationData(ConfigurationManager.java:33) 
    at com.mytest.core.ApplicationContext.getConfigruation(ApplicationContext.java:51) 
    at com.mytest.core.services.FootprintsServiceClient.init(FootprintsServiceClient.java:43) 
    at com.mytest.core.AppManager.init(AppManager.java:43) 
    at com.mytest.core.AppManager.getInstance(AppManager.java:61) 
    at com.mytest.core.aspects.TestAspect.ajc$before$com_mytest_core_aspects_TestAspect$1$93e74aa7(TestAspect.aj:21) 
    at io.demo.App.main(App.java:12) 
Caused by: java.lang.NullPointerException 
     at com.fasterxml.jackson.databind.ObjectMapper.<init>(ObjectMapper.java:530) 
     at com.fasterxml.jackson.databind.ObjectMapper.<init>(ObjectMapper.java:448) 
     at com.mytest.core.ConfigurationManager.loadConfiguration(ConfigurationManager.java:44) 
     at com.mytest.core.ConfigurationManager.getOrLoadConfigurationData(ConfigurationManager.java:33) 
     at com.mytest.core.ApplicationContext.getConfigruation(ApplicationContext.java:51) 
     at com.mytest.core.services.FootprintsServiceClient.init(FootprintsServiceClient.java:43) 
     at com.mytest.core.AppManager.init(AppManager.java:43) 
     at com.mytest.core.AppManager.getInstance(AppManager.java:61) 
     at com.mytest.core.aspects.TestAspect.ajc$before$com_mytest_core_aspects_TestAspect$1$93e74aa7(TestAspect.aj:21) 
     at com.sun.proxy.$Proxy3.<clinit>(Unknown Source) 
     ... 29 more 

我會明白,如果你能指出我的根本原因或推薦的調試技術。

親切的問候,

Nadav

編輯 請注意,我知道什麼是空指針。我的問題是,我從ObjectMapper類的一個實例中獲取NullPointerException,它是Jackson框架的一部分。

+0

我知道什麼是空指針異常。問題在於它是由ObjectMapper引發的,它是Jackson框架的一部分。 – nadavy

+0

什麼版本的傑克遜? –

+0

版本2.6.3。看起來像最新的.. – nadavy

回答

1

您的註釋處理器正在重新進入。如果你通過從主要向上堆棧跟蹤,你看:

at io.demo.App.main(App.java:12) 
at com.mytest.core.aspects.TestAspect.ajc$before$com_mytest_core_aspects_TestAspect$1$93e74aa7(TestAspect.aj:21) 
at com.mytest.core.AppManager.getInstance(AppManager.java:61) 

它開始加載傑克遜

at com.fasterxml.jackson.databind.ObjectMapper.<clinit>(ObjectMapper.java:261) 
at com.fasterxml.jackson.databind.introspect.VisibilityChecker$Std.<clinit>(VisibilityChecker.java:170) 
at java.lang.Class.getAnnotation(Class.java:3038) 

VisibilityChecker線170具有靜態intialisation加載的標準類註釋,所以這可以追溯到到反射,最終:

at sun.reflect.annotation.AnnotationParser.annotationForMap(AnnotationParser.java:239) 

創建一個代理(實現註釋的?),這在上課時初始化試圖去通過一個asp再次ECT:

at com.sun.proxy.$Proxy3.<clinit>(Unknown Source) 
    at com.mytest.core.aspects.TestAspect.ajc$before$com_mytest_core_aspects_TestAspect$1$93e74aa7(TestAspect.aj:21) 
    at com.mytest.core.AppManager.getInstance(AppManager.java:61) 

,現在我們回到AppManager.getInstance 61行

at com.mytest.core.ConfigurationManager.loadConfiguration(ConfigurationManager.java:44) 
    at com.fasterxml.jackson.databind.ObjectMapper.<init>(ObjectMapper.java:448) 

,這是試圖構建一個ObjectMapper的ObjectMapper類初始化具有completed-這並不奇怪之前,導致錯誤。

我沒有解決方案(因爲我對AspectJ不夠熟悉),但這是正在發生的事情的核心。可能是像設置一個標誌來指示配置是否被卸載/加載/加載,以及避免在實際加載配置時嘗試重新輸入配置加載。

+0

謝謝 - 我昨天也注意到了。好的趕上! :) – nadavy

相關問題