3 Replies Latest reply on Nov 21, 2008 7:13 AM by adrian.brock

    Is ParameterizedClassInfo serialization broken

    alesj

      Looking at ParameterizedClassInfo, I have a few doubts about its serialization.

      public class ParameterizedClassInfo extends DelegateClassInfo
      {
       /** The serialVersionUID */
       private static final long serialVersionUID = 2;
      
       /** The factory */
       protected transient IntrospectionTypeInfoFactoryImpl factory;
      
       /** The parameterized type */
       transient ParameterizedType parameterizedType;
      
       /** The owner type */
       private TypeInfo ownerType = ClassInfoImpl.UNKNOWN_TYPE;
      
       /** The type arguments */
       private TypeInfo[] typeArguments = ClassInfoImpl.UNKNOWN_TYPES;
      
       /** The component type */
       private transient TypeInfo componentType = ClassInfoImpl.UNKNOWN_TYPE;
      
       /** The key type */
       private transient TypeInfo keyType = ClassInfoImpl.UNKNOWN_TYPE;
      
       /** The key type */
       private transient TypeInfo valueType = ClassInfoImpl.UNKNOWN_TYPE;
      
       /**
       * Create a new ParameterizedClassInfo.
       *
       * @param factory the factory
       * @param delegate the raw array info
       * @param parameterizedType the parameterized type
       */
       public ParameterizedClassInfo(IntrospectionTypeInfoFactoryImpl factory, ClassInfo delegate, ParameterizedType parameterizedType)
       {
       super(delegate);
       this.factory = factory;
       this.delegate = delegate;
       this.parameterizedType = parameterizedType;
       }
      
       public TypeInfoFactory getTypeInfoFactory()
       {
       return factory;
       }
      
       @Override
       public TypeInfo[] getActualTypeArguments()
       {
       if (typeArguments == ClassInfoImpl.UNKNOWN_TYPES)
       typeArguments = factory.getActualTypeArguments(this);
       return typeArguments;
       }
      
       @Override
       public TypeInfo getOwnerType()
       {
       if (ownerType == ClassInfoImpl.UNKNOWN_TYPE)
       ownerType = factory.getOwnerType(this);
       return ownerType;
       }
      
       @Override
       public ClassInfo getRawType()
       {
       return delegate;
       }
      
       @Override
       public TypeInfo getComponentType()
       {
       if (componentType == ClassInfoImpl.UNKNOWN_TYPE)
       componentType = factory.getComponentType(this);
       return componentType;
       }
      
       @Override
       public TypeInfo getKeyType()
       {
       if (keyType == ClassInfoImpl.UNKNOWN_TYPE);
       keyType = factory.getKeyType(this);
       return keyType;
       }
      
       @Override
       public TypeInfo getValueType()
       {
       if (valueType == ClassInfoImpl.UNKNOWN_TYPE)
       valueType = factory.getValueType(this);
       return valueType;
       }
      


      After serialization, componentType, keyType, valueType are all gonna be null == not ClassInfoImpl.UNKNOWN_TYPE,
      hence null would be returned.
      Even if they were equal to ClassInfoImpl.UNKNOWN_TYPE,
      NPE would be thrown due to factory being null.

      Is this expected behavior (the first, not NPE :-))?

      ps: just saw that there is ';' at the end of 'if' in getKeyType :-)

        • 1. Re: Is ParameterizedClassInfo serialization broken

           

          "alesj" wrote:

          Is this expected behavior (the first, not NPE :-))?


          Well obviously its broken unless this works:

          ParameterizedClassInfo pci = ...
          ParameterizedClassInfo pci2 = serializeDeserialize(pci, ParameterizedClassInfo.class);
          assertEquals(pci, pci2);
          


          That's usually the serialization contract (but not always ;-).

          • 2. Re: Is ParameterizedClassInfo serialization broken
            alesj

             

            "adrian@jboss.org" wrote:

            Well obviously its broken unless this works:

            Well, this works
             ClassInfo typeInfo = (ClassInfo) factory.getTypeInfo(clazz);
             ClassInfo superClassInfo = typeInfo.getGenericSuperclass(); // <-- PCI
            
             ClassInfo tmp = superClassInfo;
             superClassInfo = serializeDeserialize(superClassInfo, ClassInfo.class);
             assertEquals(tmp, superClassInfo);
             assertEquals(superClassInfo, tmp);
            

            so fine by me. :-)

            • 3. Re: Is ParameterizedClassInfo serialization broken

               

              "alesj" wrote:

               ClassInfo typeInfo = (ClassInfo) factory.getTypeInfo(clazz);
               ClassInfo superClassInfo = typeInfo.getGenericSuperclass(); // <-- PCI
              
               ClassInfo tmp = superClassInfo;
               superClassInfo = serializeDeserialize(superClassInfo, ClassInfo.class);
               assertEquals(tmp, superClassInfo);
               assertEquals(superClassInfo, tmp);
              

              so fine by me. :-)


              Well I guess that depends upon what "clazz" is :-)