Open xjywp2008 opened 1 year ago
背景:java.util.GregorianCalendar 与 对象内含有内存地址相同的属性,顺序不一样结果会不同,其中一种情况序列化会失败。具体代码如下,放到repeater-plugin-core模块的test模块下直接可以复现。
test1()正常 test()异常
package com.alibaba.jvm.sandbox.repeater.plugin.core.serialize; import com.alibaba.jvm.sandbox.repeater.plugin.core.wrapper.SerializerWrapper; import com.alibaba.jvm.sandbox.repeater.plugin.domain.MockInvocation; import java.util.*; import java.util.concurrent.ConcurrentHashMap; public class HessianTest { public static void main(String[] args) throws SerializeException { test1(); test(); } public static void test() throws SerializeException { List<MockInvocation> ml = new ArrayList<>(); MockInvocation m1 = new MockInvocation(); MockInvocation m2 = new MockInvocation(); Object[] org = new Object[1]; org[0] = new GregorianCalendar(); m1.setCurrentArgs(org); ArrayList xxx = new ArrayList(); xxx.add(123); Map<String,Object> map = new ConcurrentHashMap<>(); map.put("xx",xxx); map.put("jj",xxx); Object[] ol = new Object[1]; ol[0] = map; m2.setCurrentArgs(ol); ml.add(m1); ml.add(m2); String ens = SerializerWrapper.hessianSerialize(ml); Object xx = SerializerWrapper.hessianDeserialize(ens); System.out.println(xx); } public static void test1() throws SerializeException { List<MockInvocation> ml = new ArrayList<>(); MockInvocation m1 = new MockInvocation(); MockInvocation m2 = new MockInvocation(); ArrayList xxx = new ArrayList(); xxx.add(123); Map<String,Object> map = new HashMap<>(); map.put("xx",xxx); map.put("jj",xxx); Object[] ol = new Object[1]; ol[0] = map; m1.setCurrentArgs(ol); Object[] org = new Object[1]; org[0] = new GregorianCalendar(); m2.setCurrentArgs(org); ml.add(m1); ml.add(m2); String ens = SerializerWrapper.hessianSerialize(ml); Object xx = SerializerWrapper.hessianDeserialize(ens); System.out.println(xx); } }
背景:java.util.GregorianCalendar 与 对象内含有内存地址相同的属性,顺序不一样结果会不同,其中一种情况序列化会失败。具体代码如下,放到repeater-plugin-core模块的test模块下直接可以复现。
test1()正常 test()异常