Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

序列化异常 #200

Open
xjywp2008 opened this issue Feb 15, 2023 · 0 comments · May be fixed by #201
Open

序列化异常 #200

xjywp2008 opened this issue Feb 15, 2023 · 0 comments · May be fixed by #201

Comments

@xjywp2008
Copy link

xjywp2008 commented Feb 15, 2023

背景: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);
    }
}
@wxbty wxbty linked a pull request Feb 15, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant