Uploaded image for project: 'CXF'
  1. CXF
  2. CXF-3613

Various problems with "java.lang.Class"

Attach filesAttach ScreenshotVotersWatch issueWatchersCreate sub-taskLinkCloneUpdate Comment AuthorReplace String in CommentUpdate Comment VisibilityDelete Comments
    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Critical
    • Resolution: Fixed
    • 2.4.1
    • 2.5.7, 2.6.4, 2.7.1
    • Aegis Databinding
    • None

    Description

      I just noted that the following exception is thrown when trying to create server for some service interface that contains some reference to "java.lang.Class".

      Consider a service interface like this:

      package org.apache.cxf.aegis.type.java5;
      
      import java.io.Serializable;
      
      public class GenericsService {
      
          public <T extends Serializable> T createInstance(Class<T> type)
              throws InstantiationException, IllegalAccessException {
              return type.newInstance();
          }
      }
      


      The problem is, that during creation time it throws a NullPointerException like this:

      java.lang.NullPointerException
      	at org.apache.cxf.aegis.type.basic.BeanTypeInfo$1.compare(BeanTypeInfo.java:307)
      	at org.apache.cxf.aegis.type.basic.BeanTypeInfo$1.compare(BeanTypeInfo.java:306)
      	at java.util.Arrays.mergeSort(Arrays.java:1270)
      	at java.util.Arrays.mergeSort(Arrays.java:1282)
      	at java.util.Arrays.mergeSort(Arrays.java:1281)
      	at java.util.Arrays.mergeSort(Arrays.java:1281)
      	at java.util.Arrays.sort(Arrays.java:1210)
      	at org.apache.cxf.aegis.type.basic.BeanTypeInfo.initializeProperties(BeanTypeInfo.java:305)
      	at org.apache.cxf.aegis.type.basic.BeanTypeInfo.<init>(BeanTypeInfo.java:75)
      	at org.apache.cxf.aegis.type.java5.AnnotatedTypeInfo.<init>(AnnotatedTypeInfo.java:41)
      	at org.apache.cxf.aegis.type.java5.AnnotatedTypeInfo.<init>(AnnotatedTypeInfo.java:36)
      	at org.apache.cxf.aegis.type.java5.Java5TypeCreator.createDefaultType(Java5TypeCreator.java:208)
      	at org.apache.cxf.aegis.type.XMLTypeCreator.createDefaultType(XMLTypeCreator.java:398)
      	at org.apache.cxf.aegis.type.AbstractTypeCreator.createTypeForClass(AbstractTypeCreator.java:135)
      	at org.apache.cxf.aegis.databinding.AegisDatabinding.getParameterType(AegisDatabinding.java:574)
      	at org.apache.cxf.aegis.databinding.AegisDatabinding.initializeMessage(AegisDatabinding.java:315)
      	at org.apache.cxf.aegis.databinding.AegisDatabinding.initializeOperation(AegisDatabinding.java:273)
      	at org.apache.cxf.aegis.databinding.AegisDatabinding.initialize(AegisDatabinding.java:239)
      	at org.apache.cxf.service.factory.AbstractServiceFactoryBean.initializeDataBindings(AbstractServiceFactoryBean.java:86)
      	at org.apache.cxf.service.factory.ReflectionServiceFactoryBean.buildServiceFromClass(ReflectionServiceFactoryBean.java:438)
      	at org.apache.cxf.service.factory.ReflectionServiceFactoryBean.initializeServiceModel(ReflectionServiceFactoryBean.java:501)
      	at org.apache.cxf.service.factory.ReflectionServiceFactoryBean.create(ReflectionServiceFactoryBean.java:241)
      	at org.apache.cxf.frontend.AbstractWSDLBasedEndpointFactory.createEndpoint(AbstractWSDLBasedEndpointFactory.java:101)
      	at org.apache.cxf.frontend.ServerFactoryBean.create(ServerFactoryBean.java:157)
      	at org.apache.cxf.dosgi.dsw.handlers.HttpServiceConfigurationTypeHandler.createServer(HttpServiceConfigurationTypeHandler.java:169)
      	at org.apache.cxf.dosgi.dsw.service.RemoteServiceAdminCore.exportService(RemoteServiceAdminCore.java:245)
      	at org.apache.cxf.dosgi.dsw.service.RemoteServiceAdminInstance$1.run(RemoteServiceAdminInstance.java:78)
      	at org.apache.cxf.dosgi.dsw.service.RemoteServiceAdminInstance$1.run(RemoteServiceAdminInstance.java:71)
      	at java.security.AccessController.doPrivileged(Native Method)
      	at org.apache.cxf.dosgi.dsw.service.RemoteServiceAdminInstance.exportService(RemoteServiceAdminInstance.java:71)
      	at org.apache.cxf.dosgi.dsw.service.RemoteServiceAdminInstance.exportService(RemoteServiceAdminInstance.java:40)
      	at org.apache.cxf.dosgi.topologymanager.TopologyManager$2.run(TopologyManager.java:259)
      	at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
      	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
      	at java.lang.Thread.run(Thread.java:662)
      

      The cause for this is that the "org.springframework.beans.BeanUtils#getPropertyDescriptor" method returns "null" for the property "classLoader". However, this is not a real problem, so as a test I just modified the "org.apache.cxf.aegis.type.basic.BeanTypeInfo#initializeProperties" method to omit any PropertyDescriptor that is null.

      So far so good, but immediately afterwards, I get the next error:

      java.lang.NullPointerException
      	at java.lang.reflect.Array.newArray(Native Method)
      	at java.lang.reflect.Array.newInstance(Array.java:52)
      	at org.apache.cxf.aegis.type.TypeUtil.getTypeRelatedClass(TypeUtil.java:261)
      	at org.apache.cxf.aegis.type.AbstractTypeCreator.createTypeForClass(AbstractTypeCreator.java:108)
      	at org.apache.cxf.aegis.type.AbstractTypeCreator.createType(AbstractTypeCreator.java:395)
      	at org.apache.cxf.aegis.type.basic.BeanTypeInfo.getType(BeanTypeInfo.java:196)
      	at org.apache.cxf.aegis.type.basic.BeanType.getDependencies(BeanType.java:532)
      	at org.apache.cxf.aegis.databinding.AegisDatabinding.addDependencies(AegisDatabinding.java:394)
      	at org.apache.cxf.aegis.databinding.AegisDatabinding.initializeMessage(AegisDatabinding.java:370)
      	at org.apache.cxf.aegis.databinding.AegisDatabinding.initializeOperation(AegisDatabinding.java:273)
      	at org.apache.cxf.aegis.databinding.AegisDatabinding.initialize(AegisDatabinding.java:239)
      	at org.apache.cxf.service.factory.AbstractServiceFactoryBean.initializeDataBindings(AbstractServiceFactoryBean.java:86)
      	at org.apache.cxf.service.factory.ReflectionServiceFactoryBean.buildServiceFromClass(ReflectionServiceFactoryBean.java:438)
      	at org.apache.cxf.service.factory.ReflectionServiceFactoryBean.initializeServiceModel(ReflectionServiceFactoryBean.java:501)
      	at org.apache.cxf.service.factory.ReflectionServiceFactoryBean.create(ReflectionServiceFactoryBean.java:241)
      	at org.apache.cxf.frontend.AbstractWSDLBasedEndpointFactory.createEndpoint(AbstractWSDLBasedEndpointFactory.java:101)
      	at org.apache.cxf.frontend.ServerFactoryBean.create(ServerFactoryBean.java:157)
      	at org.apache.cxf.aegis.AbstractAegisTest.createService(AbstractAegisTest.java:151)
      	at org.apache.cxf.aegis.type.java5.GenericsTypeTest.testCreateService(GenericsTypeTest.java:85)
      	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      	at java.lang.reflect.Method.invoke(Method.java:597)
      	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
      	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
      	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
      	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
      	at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
      	at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
      	at org.junit.runners.BlockJUnit4ClassRunner.runNotIgnored(BlockJUnit4ClassRunner.java:79)
      	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:71)
      	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49)
      	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
      	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
      	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
      	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
      	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
      	at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
      	at org.apache.maven.surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java:53)
      	at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:119)
      	at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:101)
      	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      	at java.lang.reflect.Method.invoke(Method.java:597)
      	at org.apache.maven.surefire.booter.ProviderFactory$ClassLoaderProxy.invoke(ProviderFactory.java:103)
      	at $Proxy0.invoke(Unknown Source)
      	at org.apache.maven.surefire.booter.SurefireStarter.invokeProvider(SurefireStarter.java:150)
      	at org.apache.maven.surefire.booter.SurefireStarter.runSuitesInProcess(SurefireStarter.java:91)
      	at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:69)
      


      This one is for the property "java.lang.Class#enumConstants" and I guess there are even more errors coming.

      What I had in ming was to substitute "java.lang.Class" with "java.lang.String" on-the-fly, so that there is an automatic default handling, e.g.:

      • public <T extends Serializable> T createInstance(Class<T> type) will become something like public Serializable createInstance(String type)
      • public Class getType(Serializable obj) will become something like public String getType(Serializable obj)

      ...so that CXF internally does something like "ClassLoaderUtils.loadClass(type, refClass);" and "type.getName()" for the other way around.

      What do you think?

      Attachments

        Activity

          This comment will be Viewable by All Users Viewable by All Users
          Cancel

          People

            dkulp Daniel Kulp
            ancoron Ancoron Luciferis
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Slack

                Issue deployment