From 8e5712b021916cb90dc1b6d357509aa541b124ac Mon Sep 17 00:00:00 2001 From: xiaolei55 Date: Thu, 1 Jun 2023 11:28:50 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E4=BF=AE=E5=A4=8D=E6=9C=AA=E6=AD=A3?= =?UTF-8?q?=E7=A1=AE=E5=85=B3=E9=97=AD=E6=B5=81=E5=AF=BC=E8=87=B4=E7=9A=84?= =?UTF-8?q?=E5=86=85=E5=AD=98=E6=B3=84=E6=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core/serialize/HessianSerializer.java | 28 +++++++++++++++---- 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/repeater-plugin-core/src/main/java/com/alibaba/jvm/sandbox/repeater/plugin/core/serialize/HessianSerializer.java b/repeater-plugin-core/src/main/java/com/alibaba/jvm/sandbox/repeater/plugin/core/serialize/HessianSerializer.java index a6c7629f..ac4a48d4 100644 --- a/repeater-plugin-core/src/main/java/com/alibaba/jvm/sandbox/repeater/plugin/core/serialize/HessianSerializer.java +++ b/repeater-plugin-core/src/main/java/com/alibaba/jvm/sandbox/repeater/plugin/core/serialize/HessianSerializer.java @@ -7,6 +7,7 @@ import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; +import java.io.IOException; import java.util.Map; /** @@ -37,12 +38,17 @@ public byte[] serialize(Object object, ClassLoader classLoader) throws Serialize output.setSerializerFactory(getFactory(classLoader)); try { output.writeObject(object); - output.close(); + return byteArray.toByteArray(); } catch (Throwable t) { // may produce sof exception throw new SerializeException("[Error-1001]-hessian-serialize-error", t); + } finally { + try { + output.close(); + } catch (IOException e) { + // ignore + } } - return byteArray.toByteArray(); } @Override @@ -53,11 +59,16 @@ public T deserialize(byte[] bytes, Class type, ClassLoader classLoader) t Object readObject; try { readObject = input.readObject(type); - input.close(); + return (T) readObject; } catch (Throwable t) { throw new SerializeException("[Error-1002]-hessian-deserialize-error", t); + } finally { + try { + input.close(); + } catch (IOException e) { + // ignore + } } - return (T) readObject; } @Override @@ -67,11 +78,16 @@ public Object deserialize(byte[] bytes) throws SerializeException { Object readObject; try { readObject = input.readObject(); - input.close(); + return readObject; } catch (Throwable t) { throw new SerializeException("[Error-1002]-hessian-deserialize-error", t); + } finally { + try { + input.close(); + } catch (IOException e) { + // ignore + } } - return readObject; } /**