zrlw commented on PR #92:
URL: 
https://github.com/apache/dubbo-hessian-lite/pull/92#issuecomment-3310129651

   Maybe all xxxSerializers need to be checked whether exist such issues,
   
   1. do not call ```addRef``` at the beginning of ```writeObject``` method, 
e.g.,
   ```
   public class LongAdderSerializer extends AbstractSerializer {
   
       @Override
       public void writeObject(Object obj, AbstractHessianOutput out)
               throws IOException {
   
           String replacedClName = 
"java.util.concurrent.atomic.LongAdder$SerializationProxy";
   
           int ref = out.writeObjectBegin(replacedClName);
   ```
   Each xxxSerializers should calling ```addRef```, even it's a collection 
serializer, just like ```CollectionSerializer``` does.
   
   2. write a new replaced object directly at ```writeObject``` (does not 
implement ```writeReplace```) which will cause reference mechanism failure, 
calling ```addRef``` method for such object always return false because 
```_refs``` key is based on ```identityHashCode```, each new object has a 
almost unique ```identityHashCode```(it is calculated by JVM, all overridden 
hashCode methods are ignored), the probability of a hash collision occurring is 
extremely low.
   e.g.,
   ```
   public class List12Serializer extends AbstractSerializer {
   
       @Override
       public void writeObject(Object obj, AbstractHessianOutput out) throws 
IOException {
           if (obj == null) {
               out.writeNull();
               return;
           }
   
           out.writeObject(new ArrayList<>((List) obj));
       }
   }
   ```
   such methods should be refactored to ```writeReplace``` method.
   
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscr...@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscr...@dubbo.apache.org
For additional commands, e-mail: notifications-h...@dubbo.apache.org

Reply via email to