You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by mp...@apache.org on 2025/09/01 14:53:22 UTC

(ignite-3) branch IGNITE-26181 created (now 27406dc14f9)

This is an automated email from the ASF dual-hosted git repository.

mpochatkin pushed a change to branch IGNITE-26181
in repository https://gitbox.apache.org/repos/asf/ignite-3.git


      at 27406dc14f9 IGNITE-26181 Fix default byte array marshalling

This branch includes the following new commits:

     new 27406dc14f9 IGNITE-26181 Fix default byte array marshalling

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



(ignite-3) 01/01: IGNITE-26181 Fix default byte array marshalling

Posted by mp...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

mpochatkin pushed a commit to branch IGNITE-26181
in repository https://gitbox.apache.org/repos/asf/ignite-3.git

commit 27406dc14f942f474128f4e90a5f743df26c9133
Author: Pochatkin Mikhail <m....@gmail.com>
AuthorDate: Mon Sep 1 17:52:04 2025 +0300

    IGNITE-26181 Fix default byte array marshalling
---
 .../ignite/marshalling/ByteArrayMarshaller.java    | 31 +++++++++-
 .../JavaSerializationByteArrayMarshalling.java     | 70 ----------------------
 2 files changed, 29 insertions(+), 72 deletions(-)

diff --git a/modules/api/src/main/java/org/apache/ignite/marshalling/ByteArrayMarshaller.java b/modules/api/src/main/java/org/apache/ignite/marshalling/ByteArrayMarshaller.java
index 50bfa3d51e4..b84d4804a13 100644
--- a/modules/api/src/main/java/org/apache/ignite/marshalling/ByteArrayMarshaller.java
+++ b/modules/api/src/main/java/org/apache/ignite/marshalling/ByteArrayMarshaller.java
@@ -17,6 +17,12 @@
 
 package org.apache.ignite.marshalling;
 
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.ObjectStreamClass;
 import java.io.Serializable;
 import org.jetbrains.annotations.Nullable;
 
@@ -39,7 +45,14 @@ public interface ByteArrayMarshaller<T> extends Marshaller<T, byte[]> {
         }
 
         if (object instanceof Serializable) {
-            return JavaSerializationByteArrayMarshalling.marshal((Serializable) object);
+            try (var baos = new ByteArrayOutputStream(); var out = new ObjectOutputStream(baos)) {
+                out.writeObject(object);
+                out.flush();
+
+                return baos.toByteArray();
+            } catch (IOException e) {
+                throw new MarshallingException(e);
+            }
         }
 
         throw new UnsupportedObjectTypeMarshallingException(object.getClass());
@@ -51,6 +64,20 @@ public interface ByteArrayMarshaller<T> extends Marshaller<T, byte[]> {
             return null;
         }
 
-        return JavaSerializationByteArrayMarshalling.unmarshal(raw);
+        try (var bais = new ByteArrayInputStream(raw); var ois = new ObjectInputStream(bais) {
+            @Override
+            protected Class<?> resolveClass(ObjectStreamClass desc) throws IOException, ClassNotFoundException {
+                String name = desc.getName();
+                try {
+                    return Class.forName(name, false, ByteArrayMarshaller.this.getClass().getClassLoader());
+                } catch (ClassNotFoundException ex) {
+                    return super.resolveClass(desc);
+                }
+            }
+        }) {
+            return (T) ois.readObject();
+        } catch (IOException | ClassNotFoundException e) {
+            throw new MarshallingException(e);
+        }
     }
 }
diff --git a/modules/api/src/main/java/org/apache/ignite/marshalling/JavaSerializationByteArrayMarshalling.java b/modules/api/src/main/java/org/apache/ignite/marshalling/JavaSerializationByteArrayMarshalling.java
deleted file mode 100644
index 12845167478..00000000000
--- a/modules/api/src/main/java/org/apache/ignite/marshalling/JavaSerializationByteArrayMarshalling.java
+++ /dev/null
@@ -1,70 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.marshalling;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
-import java.io.Serializable;
-import org.jetbrains.annotations.Nullable;
-
-/**
- * Default java serialization marshaller. It is used by default if no other marshaller is provided.
- */
-class JavaSerializationByteArrayMarshalling {
-    /**
-     * Writes the object to a byte array with java serialization.
-     *
-     * @param <T> object.
-     * @return byte array that represents the object.
-     */
-    public static <T extends Serializable> byte @Nullable [] marshal(T object) {
-        if (object == null) {
-            return null;
-        }
-
-        try (var baos = new ByteArrayOutputStream(); var out = new ObjectOutputStream(baos)) {
-            out.writeObject(object);
-            out.flush();
-
-            return baos.toByteArray();
-        } catch (IOException e) {
-            throw new MarshallingException(e);
-        }
-    }
-
-    /**
-     * Reads the object from a byte array with java serialization.
-     *
-     * @param raw byte array that represents the object.
-     * @return object.
-     */
-    public static <T> @Nullable T unmarshal(byte @Nullable [] raw) {
-        if (raw == null) {
-            return null;
-        }
-
-        try (var bais = new ByteArrayInputStream(raw); var ois = new ObjectInputStream(bais)) {
-            return (T) ois.readObject();
-        } catch (IOException | ClassNotFoundException e) {
-            throw new MarshallingException(e);
-        }
-    }
-}