From d4ffe85d3b573a1e8d03673ea7d7b15fce4a2d7c Mon Sep 17 00:00:00 2001 From: wangxiaobin Date: Wed, 15 Feb 2023 17:28:17 +0800 Subject: [PATCH] fix hession bug --- .../com/caucho/hessian/io/Hessian2Output.java | 18 +++------ repeater-plugin-core/pom.xml | 12 ++++++ .../core/serialize/HessianSerializerTest.java | 38 +++++++++++++++++++ 3 files changed, 55 insertions(+), 13 deletions(-) diff --git a/hessian-lite/src/main/java/com/caucho/hessian/io/Hessian2Output.java b/hessian-lite/src/main/java/com/caucho/hessian/io/Hessian2Output.java index a8aab727..403c1dc6 100644 --- a/hessian-lite/src/main/java/com/caucho/hessian/io/Hessian2Output.java +++ b/hessian-lite/src/main/java/com/caucho/hessian/io/Hessian2Output.java @@ -1329,23 +1329,15 @@ protected void writeRef(int value) public boolean addRef(Object object) throws IOException { - if (_isUnshared) { - _refCount++; - return false; - } - - int newRef = _refCount; + int ref = _refs.get(object); - int ref = addRef(object, newRef, false); - - if (ref != newRef) { + if (ref >= 0) { writeRef(ref); return true; - } - else { - _refCount++; - + } else { + _refs.put(object, _refs.size(),false); + return false; } } diff --git a/repeater-plugin-core/pom.xml b/repeater-plugin-core/pom.xml index 4255039c..1b2374e0 100644 --- a/repeater-plugin-core/pom.xml +++ b/repeater-plugin-core/pom.xml @@ -10,6 +10,18 @@ 4.0.0 repeater-plugin-core + + + + org.apache.maven.plugins + maven-compiler-plugin + + 7 + 7 + + + + diff --git a/repeater-plugin-core/src/test/java/com/alibaba/jvm/sandbox/repeater/plugin/core/serialize/HessianSerializerTest.java b/repeater-plugin-core/src/test/java/com/alibaba/jvm/sandbox/repeater/plugin/core/serialize/HessianSerializerTest.java index b42a7329..e56a0bd4 100644 --- a/repeater-plugin-core/src/test/java/com/alibaba/jvm/sandbox/repeater/plugin/core/serialize/HessianSerializerTest.java +++ b/repeater-plugin-core/src/test/java/com/alibaba/jvm/sandbox/repeater/plugin/core/serialize/HessianSerializerTest.java @@ -1,8 +1,16 @@ 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 org.testng.Assert; import org.testng.annotations.Test; +import java.util.ArrayList; +import java.util.GregorianCalendar; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + /** * {@link } *

@@ -41,4 +49,34 @@ public void deserialize() { Assert.fail(e.getMessage()); } } + + @Test + public void serializeSpec() { + List list = new ArrayList<>(); + MockInvocation m1 = new MockInvocation(); + MockInvocation m2 = new MockInvocation(); + list.add(m1); + list.add(m2); + + Object[] org = new Object[1]; + org[0] = new GregorianCalendar(); + m1.setCurrentArgs(org); + + Object xxx = new Object(); + + Map map = new HashMap<>(); + map.put("xx", xxx); + map.put("jj", xxx); + Object[] ol = new Object[1]; + ol[0] = map; + m2.setCurrentArgs(ol); + + try { + String ens = SerializerWrapper.hessianSerialize(list); + SerializerWrapper.hessianDeserialize(ens); + } catch (SerializeException e) { + Assert.assertNull(e); + } + Assert.assertTrue(true); + } } \ No newline at end of file