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

NullPointerException if class with generic-array parameters is set to rootClassNames

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Open
    • Priority: Major
    • Resolution: Unresolved
    • Affects Version/s: 2.7.8
    • Fix Version/s: None
    • Component/s: Aegis Databinding
    • Environment:

      RHEL6.3 (64b), JDK1.6, Spring 3.0.6, CXF 2.7.8

    • Estimated Complexity:
      Unknown

      Description

      I want to expose a set of classes by setting the aegisContext:

      <bean id="aegisContext" class="org.apache.cxf.aegis.AegisContext" scope="prototype">
              <property name="writeXsiTypes" value="true"/>
              <property name="rootClassNames">
                  <ref bean="bindingList"/>
              </property>
      </bean>
      

      One of the class in the list is as a response pojo which has generic-array field like:

      public class Subject<T extends Score>{
      ...
      	private T[] score;
              //and getter/setter also
      ...
      

      During the deployment phase, while debugging with the CXF code, I found that below codes in TypeUtil.java under cxf-rt-databinding-aegis-2.7.8.jar will case issue:

      public static Class<?> getTypeRelatedClass(Type type) {
              Class<?> directClass = getTypeClass(type, false);
              if (directClass != null) {
                  return directClass;
              }
              
              if (type instanceof ParameterizedType) {
                  ParameterizedType pType = (ParameterizedType) type;
                  return getTypeRelatedClass(pType.getRawType());
              }
              
              if (type instanceof GenericArrayType) {
                  GenericArrayType gat = (GenericArrayType) type;
                  Type compType = gat.getGenericComponentType();             
                  Class<?> arrayBaseType = getTypeRelatedClass(compType);
                  // believe it or not, this seems to be the only way to get the
                  // Class object for an array of primitive type.
                  Object instance = Array.newInstance(arrayBaseType, 0);
                  return instance.getClass();
              }
              return null;
          }
      


      Note: the arrayBaseType will always be null while initializing that class so it will cause the next line of code NPE!!

      Did I miss anything for this kind of class mapping while using aegis?

        Attachments

        1. learning-spring_cxf.zip
          8 kB
          Bright Zheng

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              itstarting Bright Zheng
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated: