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

nizhikov pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ignite.git


The following commit(s) were added to refs/heads/master by this push:
     new b051dfb1bb3 [MINOR] Move BinaryClassDescriptor#newInstance to 
BinaryReaderExImpl (#12628)
b051dfb1bb3 is described below

commit b051dfb1bb347091638a0b1762f5ac737f3310ca
Author: Nikolay <[email protected]>
AuthorDate: Tue Jan 13 16:29:56 2026 +0300

    [MINOR] Move BinaryClassDescriptor#newInstance to BinaryReaderExImpl 
(#12628)
---
 .../internal/binary/BinaryClassDescriptor.java     | 17 +---------------
 .../ignite/internal/binary/BinaryReaderExImpl.java | 23 +++++++++++++++++++---
 2 files changed, 21 insertions(+), 19 deletions(-)

diff --git 
a/modules/binary/api/src/main/java/org/apache/ignite/internal/binary/BinaryClassDescriptor.java
 
b/modules/binary/api/src/main/java/org/apache/ignite/internal/binary/BinaryClassDescriptor.java
index 9b82ee2d9d0..b3ee81ffd78 100644
--- 
a/modules/binary/api/src/main/java/org/apache/ignite/internal/binary/BinaryClassDescriptor.java
+++ 
b/modules/binary/api/src/main/java/org/apache/ignite/internal/binary/BinaryClassDescriptor.java
@@ -20,7 +20,6 @@ package org.apache.ignite.internal.binary;
 import java.io.Serializable;
 import java.lang.reflect.Constructor;
 import java.lang.reflect.Field;
-import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
 import java.lang.reflect.Modifier;
 import java.lang.reflect.Proxy;
@@ -46,7 +45,6 @@ import org.apache.ignite.internal.UnregisteredClassException;
 import org.apache.ignite.internal.marshaller.optimized.OptimizedMarshaller;
 import org.apache.ignite.internal.processors.cache.CacheObject;
 import org.apache.ignite.internal.util.CommonUtils;
-import org.apache.ignite.internal.util.GridUnsafe;
 import org.apache.ignite.internal.util.tostring.GridToStringExclude;
 import org.apache.ignite.internal.util.typedef.F;
 import org.apache.ignite.internal.util.typedef.internal.S;
@@ -64,7 +62,7 @@ class BinaryClassDescriptor {
     private final BinaryContext ctx;
 
     /** */
-    final Class<?> cls;
+    private final Class<?> cls;
 
     /** Configured serializer. */
     final BinarySerializer serializer;
@@ -1006,19 +1004,6 @@ class BinaryClassDescriptor {
             writer.postWriteHashCode(registered ? null : cls.getName());
     }
 
-    /**
-     * @return Instance.
-     * @throws BinaryObjectException In case of error.
-     */
-    Object newInstance() throws BinaryObjectException {
-        try {
-            return ctor != null ? ctor.newInstance() : 
GridUnsafe.allocateInstance(cls);
-        }
-        catch (InstantiationException | InvocationTargetException | 
IllegalAccessException e) {
-            throw new BinaryObjectException("Failed to instantiate instance: " 
+ cls, e);
-        }
-    }
-
     /** */
     Constructor<?> ctor() {
         return ctor;
diff --git 
a/modules/binary/impl/src/main/java/org/apache/ignite/internal/binary/BinaryReaderExImpl.java
 
b/modules/binary/impl/src/main/java/org/apache/ignite/internal/binary/BinaryReaderExImpl.java
index 4bb061ff7f3..fca203666fe 100644
--- 
a/modules/binary/impl/src/main/java/org/apache/ignite/internal/binary/BinaryReaderExImpl.java
+++ 
b/modules/binary/impl/src/main/java/org/apache/ignite/internal/binary/BinaryReaderExImpl.java
@@ -19,6 +19,7 @@ package org.apache.ignite.internal.binary;
 
 import java.io.EOFException;
 import java.io.IOException;
+import java.lang.reflect.Constructor;
 import java.lang.reflect.InvocationTargetException;
 import java.math.BigDecimal;
 import java.sql.Time;
@@ -2365,13 +2366,14 @@ class BinaryReaderExImpl implements BinaryReaderEx {
      */
     private Object read(BinaryClassDescriptor desc) throws 
BinaryObjectException {
         try {
-            assert desc.mode != BinaryWriteMode.OPTIMIZED : 
"OptimizedMarshaller should not be used here: " + desc.cls.getName();
+            assert desc.mode != BinaryWriteMode.OPTIMIZED
+                : "OptimizedMarshaller should not be used here: " + 
desc.describedClass().getName();
 
             Object res;
 
             switch (desc.mode) {
                 case BINARY:
-                    res = desc.newInstance();
+                    res = newInstance(desc.ctor(), desc.describedClass());
 
                     setHandle(res);
 
@@ -2383,7 +2385,7 @@ class BinaryReaderExImpl implements BinaryReaderEx {
                     break;
 
                 case OBJECT:
-                    res = desc.newInstance();
+                    res = newInstance(desc.ctor(), desc.describedClass());
 
                     setHandle(res);
 
@@ -2749,6 +2751,21 @@ class BinaryReaderExImpl implements BinaryReaderEx {
         return BinaryUtils.doReadBinaryEnum(in, ctx, 
BinaryUtils.doReadEnumType(in));
     }
 
+    /**
+     * @param ctor Constructor.
+     * @param cls Class.
+     * @return Instance.
+     * @throws BinaryObjectException In case of error.
+     */
+    private static Object newInstance(@Nullable Constructor<?> ctor, Class<?> 
cls) throws BinaryObjectException {
+        try {
+            return ctor != null ? ctor.newInstance() : 
GridUnsafe.allocateInstance(cls);
+        }
+        catch (InstantiationException | InvocationTargetException | 
IllegalAccessException e) {
+            throw new BinaryObjectException("Failed to instantiate instance: " 
+ cls, e);
+        }
+    }
+
     /**
      * Flag.
      */

Reply via email to