Bug 3016 : This manual serialization of ImmutableList was done because in routed... 92/20092/1
authorHarman Singh <harmasin@cisco.com>
Thu, 30 Apr 2015 21:37:25 +0000 (14:37 -0700)
committerTony Tkacik <ttkacik@cisco.com>
Tue, 12 May 2015 08:37:41 +0000 (08:37 +0000)
remote server was not able to deserialize the object in AKKA messages properly.
Following exception was thrown:

ERROR Remoting - cannot assign instance of com.google.common.collect.RegularImmutableList
to field org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.legacyPath of type
com.google.common.collect.ImmutableList in instance of org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier

Change-Id: I74daf7ab5a6d4c164bb87b1bebc5f4e2dffb8753
Signed-off-by: Harman Singh <harmasin@cisco.com>
(cherry picked from commit 63c9eb4f3bd1a50b6841bbfebb53c1443e5e6ff4)

yang/yang-data-api/src/main/java/org/opendaylight/yangtools/yang/data/api/YangInstanceIdentifier.java

index 53b8343cd18760a5977a2681c879672c10dcbfde..4488ac32c27d937fc6bc92f19d687ab782289b4e 100644 (file)
@@ -22,6 +22,7 @@ import java.lang.reflect.Array;
 import java.lang.reflect.Field;
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.Collection;
 import java.util.Collections;
 import java.util.Iterator;
 import java.util.List;
@@ -87,7 +88,7 @@ public final class YangInstanceIdentifier implements Path<YangInstanceIdentifier
     private final transient Iterable<PathArgument> pathArguments;
     private final int hash;
 
-    private volatile ImmutableList<PathArgument> legacyPath = null;
+    private transient volatile ImmutableList<PathArgument> legacyPath = null;
     private transient volatile String toStringCache = null;
 
     static {
@@ -805,6 +806,7 @@ public final class YangInstanceIdentifier implements Path<YangInstanceIdentifier
 
     private void readObject(final ObjectInputStream inputStream) throws IOException, ClassNotFoundException {
         inputStream.defaultReadObject();
+        legacyPath = ImmutableList.copyOf((Collection<PathArgument>)inputStream.readObject());
 
         try {
             PATHARGUMENTS_FIELD.set(this, legacyPath);
@@ -825,7 +827,8 @@ public final class YangInstanceIdentifier implements Path<YangInstanceIdentifier
          * it out. The read path does the opposite -- it reads the legacyPath and then
          * uses invocation API to set the field.
          */
-        getLegacyPath();
+        ImmutableList<PathArgument> pathArguments = getLegacyPath();
         outputStream.defaultWriteObject();
+        outputStream.writeObject(pathArguments);
     }
 }