Skip to content

Commit ac829d1

Browse files
authored
Merge pull request #91 from eclipse-mat/backwards-compatibility-classimpl-ser-deser
fix #89 - read and write List instead of Set during ClassImpl serialization
2 parents 7c46a05 + d2a4ce6 commit ac829d1

File tree

1 file changed

+31
-1
lines changed
  • plugins/org.eclipse.mat.parser/src/org/eclipse/mat/parser/model

1 file changed

+31
-1
lines changed

plugins/org.eclipse.mat.parser/src/org/eclipse/mat/parser/model/ClassImpl.java

+31-1
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,12 @@
1515
package org.eclipse.mat.parser.model;
1616

1717
import java.io.IOException;
18+
import java.io.ObjectInputStream;
19+
import java.io.ObjectOutputStream;
1820
import java.io.Serializable;
1921
import java.util.ArrayList;
2022
import java.util.Arrays;
23+
import java.util.Collection;
2124
import java.util.Collections;
2225
import java.util.LinkedHashSet;
2326
import java.util.LinkedList;
@@ -69,7 +72,7 @@ public class ClassImpl extends AbstractObjectImpl implements IClass, Comparable<
6972
protected volatile long totalSize;
7073
protected boolean isArrayType;
7174

72-
private Set<IClass> subClasses;
75+
private Collection<IClass> subClasses;
7376

7477
private Serializable cacheEntry;
7578

@@ -507,4 +510,31 @@ public void setSnapshot(ISnapshot dump)
507510
}
508511
}
509512

513+
private void writeObject(ObjectOutputStream out) throws IOException {
514+
// TODO intent is to remove this code at some point and simply use Set
515+
// For backwards compatibility serialize as List - https://github.com/eclipse-mat/mat/issues/89
516+
final Collection<IClass> originalSubclasses = subClasses;
517+
try
518+
{
519+
if (originalSubclasses != null)
520+
{
521+
subClasses = new ArrayList<>(originalSubclasses);
522+
}
523+
out.defaultWriteObject();
524+
}
525+
finally
526+
{
527+
subClasses = originalSubclasses;
528+
}
529+
}
530+
531+
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
532+
// For backwards compatibility serialize as List - https://github.com/eclipse-mat/mat/issues/89
533+
in.defaultReadObject();
534+
if (subClasses instanceof List)
535+
{
536+
subClasses = new LinkedHashSet<>(subClasses);
537+
}
538+
}
539+
510540
}

0 commit comments

Comments
 (0)