1 Reply Latest reply on Oct 5, 2007 7:44 AM by alesj

    ManagedProperty serialization issue

    alesj

      If we wanted to invoke this piece of code after our ManagedProperty has been serialized - to the client or on the server side - we will get 'null method' since ReflectMethodInfoImpl (the actual instance of PropertyInfo's setter) currently has transient field method field and no read implementation.

       if (info != null)
       {
       Object bean = getManagedObject().getAttachment();
       try
       {
       info.set(bean, value);
       }
      


      I guess this should be added (or is this even part of what I was changing with implementing serialization to ClassInfo?), although it looks like an ugly implementation is about to come out of this. :-)

      What about with other Reflect(Constructor|Field)InfoImpl?


        • 1. Re: ManagedProperty serialization issue
          alesj

           

          "alesj" wrote:
          I guess this should be added (or is this even part of what I was changing with implementing serialization to ClassInfo?), although it looks like an ugly implementation is about to come out of this. :-)

          I added this to ReflectMethodInfoImpl (+ similar code to other ReflectX classes):
           private void readObject(ObjectInputStream oistream)
           throws IOException, ClassNotFoundException, NoSuchMethodException
           {
           oistream.defaultReadObject();
           int length = parameterTypes != null ? parameterTypes.length : 0;
           Class<?>[] classes = new Class<?>[length];
           for(int j = 0; j < length; j++)
           classes[j] = parameterTypes[j].getType();
           method = ReflectionUtils.findExactMethod(getDeclaringClass().getType(), name, classes);
           }
          


          Utils code:
          
           public static Method findMethod(Class clazz, String name, Class<?>... parameterTypes)
           {
           if (clazz == null)
           return null;
          
           try
           {
           return clazz.getDeclaredMethod(name, parameterTypes);
           }
           catch(Exception ignored)
           {
           }
           return findMethod(clazz.getSuperclass(), name, parameterTypes);
           }
          
           public static Method findExactMethod(Class clazz, String name, Class<?>... parameterTypes)
           throws NoSuchMethodException
           {
           Method method = findMethod(clazz, name, parameterTypes);
           if (method == null)
           throw new NoSuchMethodException(clazz + "." + name + " - " + Arrays.asList(parameterTypes));
           return method;
           }
          


          Which makes ReflectX classes know their Member instance after deserialization.