2016-01-25 34 views
0

我的實際問題是標題的衍生,但標題是我的問題的根本原因:爲什麼GenericArrayTypeImpl無法在java 6中強制轉換爲java.lang.Class,何時可以在java 7中執行?

我正在開發一個java web應用程序在工作。我的應用程序將部署在服務器上,只接受Java 6或更低版本(WebLogic 10.3.2)

我需要在我的應用程序中調用Web服務。我在這方面的經驗有限。我已經能夠使它發揮作用,但是當我結合我的代碼到Web應用程序,編譯和測試它,我得到這個錯誤:

Exception in thread "main" java.lang.ClassCastException: sun.reflect.generics.reflectiveObjects.GenericArrayTypeImpl cannot be cast to java.lang.Class 
    at com.sun.xml.internal.bind.v2.model.impl.RuntimeModelBuilder.createArrayInfo(Unknown Source) 
    at com.sun.xml.internal.bind.v2.model.impl.RuntimeModelBuilder.createArrayInfo(Unknown Source) 
    at com.sun.xml.internal.bind.v2.model.impl.ModelBuilder.getTypeInfo(Unknown Source) 
    at com.sun.xml.internal.bind.v2.model.impl.ElementInfoImpl.<init>(Unknown Source) 
    at com.sun.xml.internal.bind.v2.model.impl.RuntimeElementInfoImpl.<init>(Unknown Source) 
    at com.sun.xml.internal.bind.v2.model.impl.RuntimeModelBuilder.createElementInfo(Unknown Source) 
    at com.sun.xml.internal.bind.v2.model.impl.RuntimeModelBuilder.createElementInfo(Unknown Source) 
    at com.sun.xml.internal.bind.v2.model.impl.RegistryInfoImpl.<init>(Unknown Source) 
    at com.sun.xml.internal.bind.v2.model.impl.ModelBuilder.addRegistry(Unknown Source) 
    at com.sun.xml.internal.bind.v2.model.impl.ModelBuilder.getTypeInfo(Unknown Source) 
    at com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl.getTypeInfoSet(Unknown Source) 
    at com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl.<init>(Unknown Source) 
    at com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl$JAXBContextBuilder.build(Unknown Source) 
    at com.sun.xml.internal.bind.v2.ContextFactory.createContext(Unknown Source) 
    at com.sun.xml.internal.bind.api.JAXBRIContext.newInstance(Unknown Source) 
    at com.sun.xml.internal.ws.developer.JAXBContextFactory$1.createJAXBContext(Unknown Source) 
    at com.sun.xml.internal.ws.model.AbstractSEIModelImpl$1.run(Unknown Source) 
    at com.sun.xml.internal.ws.model.AbstractSEIModelImpl$1.run(Unknown Source) 
    at java.security.AccessController.doPrivileged(Native Method) 
    at com.sun.xml.internal.ws.model.AbstractSEIModelImpl.createJAXBContext(Unknown Source) 
    at com.sun.xml.internal.ws.model.AbstractSEIModelImpl.postProcess(Unknown Source) 
    at com.sun.xml.internal.ws.model.RuntimeModeler.buildRuntimeModel(Unknown Source) 
    at com.sun.xml.internal.ws.client.WSServiceDelegate.createSEIPortInfo(Unknown Source) 
    at com.sun.xml.internal.ws.client.WSServiceDelegate.addSEI(Unknown Source) 
    at com.sun.xml.internal.ws.client.WSServiceDelegate.getPort(Unknown Source) 
    at com.sun.xml.internal.ws.client.WSServiceDelegate.getPort(Unknown Source) 
    at com.sun.xml.internal.ws.client.WSServiceDelegate.getPort(Unknown Source) 
    at com.sun.xml.internal.ws.client.WSServiceDelegate.getPort(Unknown Source) 
    at javax.xml.ws.Service.getPort(Unknown Source) 
    at com.example.mypackage.MyClient.invokeService(MyClient.java:64) 
    at Test.main(Test.java:7) 

我已經跟蹤這個錯誤重新成爲一個java版本的問題。它在7中工作,但是如果我在6中進行編譯,則必須在方法執行上拋出異常,這對於Web應用程序來說是必須的。在我的異常被拋出的線,是具有以下NotificationRecieverSoapInterface.class

NotifikationRecieverSoap service = null; 
    try { 
     service = new NotifikationRecieverSoap(new URL("[myURL].svc?wsdl")); 
    } catch (MalformedURLException e) { 
     e.printStackTrace(); 
    } 
    NotificationRecieverSoapInterface notificationService = service.getPort(NotificationRecieverSoapInterface.class); 
    notifikationService.createNotificationRequest(logHeader, loginModule, parmV, priority, recipients); 

Service.getPort() - 方法似乎在兩個Java版本是相同的,所以我在虧損出現。 sun.reflect.generics.reflectiveObjects.GenericArrayTypeImpl在6和7中也是相同的。

我在網上發現類似問題的最接近的東西是:http://forum.spring.io/forum/spring-projects/container/26020-classcastexception-genericarraytypeimpl-cannot-be-cast-to-class。不幸的是,這裏的解決方案是在春天有一個錯誤,我不使用...

有沒有人知道我的問題更具體是什麼,如果它可以解決,只使用Java 6?

我確實有很多代碼需要顯示。我選擇了我認爲與問題最相關的部分。我可以根據請求爲數據結構提供jax-ws生成的類,也可以提供xml樣例。

+0

在IDE中設置斷點時共享調試信息。這將向我們展示更好的背景 – Woot4Moo

+0

良好的計劃。我會盡快回復 – KjetilNordin

+0

@ Woot4Moo ...至今沒有運氣。我在我的maven-setup中充滿了源代碼和javadocs。在我自己的代碼中突出顯示異常的行時,我沒有更接近找到調試數據。 – KjetilNordin

回答

相關問題