ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vkuliche...@apache.org
Subject ignite git commit: IGNITE-2450 - Fixed java.lang.reflect.Proxy serialization
Date Tue, 02 Feb 2016 03:20:15 GMT
Repository: ignite
Updated Branches:
  refs/heads/ignite-2450 [created] 98dd3e765


IGNITE-2450 - Fixed java.lang.reflect.Proxy serialization


Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/98dd3e76
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/98dd3e76
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/98dd3e76

Branch: refs/heads/ignite-2450
Commit: 98dd3e765dcaa4fd68f6743ae2f56ad17c1aaa7f
Parents: 62502b2
Author: Valentin Kulichenko <valentin.kulichenko@gmail.com>
Authored: Mon Feb 1 19:20:03 2016 -0800
Committer: Valentin Kulichenko <valentin.kulichenko@gmail.com>
Committed: Mon Feb 1 19:20:03 2016 -0800

----------------------------------------------------------------------
 .../internal/binary/BinaryClassDescriptor.java  | 22 +++++++++
 .../internal/binary/BinaryReaderExImpl.java     |  8 +++-
 .../ignite/internal/binary/BinaryUtils.java     | 48 ++++++++++++++------
 .../ignite/internal/binary/BinaryWriteMode.java |  3 ++
 .../internal/binary/BinaryWriterExImpl.java     | 34 ++++++++++++++
 .../internal/binary/GridBinaryMarshaller.java   |  3 ++
 .../optimized/OptimizedClassDescriptor.java     | 37 ++++++++++++++-
 .../optimized/OptimizedMarshallerUtils.java     |  3 ++
 .../optimized/OptimizedObjectInputStream.java   | 15 +++++-
 .../optimized/OptimizedObjectOutputStream.java  |  4 +-
 pom.xml                                         |  2 +-
 11 files changed, 158 insertions(+), 21 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/98dd3e76/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryClassDescriptor.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryClassDescriptor.java
b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryClassDescriptor.java
index 233e74b..42952d2 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryClassDescriptor.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryClassDescriptor.java
@@ -22,6 +22,7 @@ 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;
 import java.math.BigDecimal;
 import java.sql.Timestamp;
 import java.util.ArrayList;
@@ -113,6 +114,9 @@ public class BinaryClassDescriptor {
     /** */
     private final boolean excluded;
 
+    /** */
+    private final Class<?>[] intfs;
+
     /**
      * @param ctx Context.
      * @param cls Class.
@@ -233,6 +237,16 @@ public class BinaryClassDescriptor {
                 fields = null;
                 stableFieldsMeta = null;
                 stableSchema = null;
+                intfs = null;
+
+                break;
+
+            case PROXY:
+                ctor = null;
+                fields = null;
+                stableFieldsMeta = null;
+                stableSchema = null;
+                intfs = cls.getInterfaces();
 
                 break;
 
@@ -241,6 +255,7 @@ public class BinaryClassDescriptor {
                 fields = null;
                 stableFieldsMeta = null;
                 stableSchema = null;
+                intfs = null;
 
                 break;
 
@@ -295,6 +310,8 @@ public class BinaryClassDescriptor {
 
                 stableSchema = schemaBuilder.build();
 
+                intfs = null;
+
                 break;
 
             default:
@@ -615,6 +632,11 @@ public class BinaryClassDescriptor {
 
                 break;
 
+            case PROXY:
+                writer.doWriteProxy((Proxy)obj, intfs);
+
+                break;
+
             case BINARY_OBJ:
                 writer.doWriteBinaryObject((BinaryObjectImpl)obj);
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/98dd3e76/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryReaderExImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryReaderExImpl.java
b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryReaderExImpl.java
index 607dabc..f9e7aa5 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryReaderExImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryReaderExImpl.java
@@ -68,6 +68,7 @@ import static org.apache.ignite.internal.binary.GridBinaryMarshaller.NULL;
 import static org.apache.ignite.internal.binary.GridBinaryMarshaller.OBJ;
 import static org.apache.ignite.internal.binary.GridBinaryMarshaller.OBJ_ARR;
 import static org.apache.ignite.internal.binary.GridBinaryMarshaller.OPTM_MARSH;
+import static org.apache.ignite.internal.binary.GridBinaryMarshaller.PROXY;
 import static org.apache.ignite.internal.binary.GridBinaryMarshaller.SHORT;
 import static org.apache.ignite.internal.binary.GridBinaryMarshaller.SHORT_ARR;
 import static org.apache.ignite.internal.binary.GridBinaryMarshaller.STRING;
@@ -1621,6 +1622,11 @@ public class BinaryReaderExImpl implements BinaryReader, BinaryRawReaderEx,
Bina
 
                 break;
 
+            case PROXY:
+                obj = BinaryUtils.doReadProxy(in, ctx, ldr, this);
+
+                break;
+
             case OPTM_MARSH:
                 obj = BinaryUtils.doReadOptimized(in, ctx, ldr);
 
@@ -2013,7 +2019,7 @@ public class BinaryReaderExImpl implements BinaryReader, BinaryRawReaderEx,
Bina
     /**
      * Flag.
      */
-    private static enum Flag {
+    private enum Flag {
         /** Regular. */
         NORMAL,
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/98dd3e76/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryUtils.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryUtils.java
b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryUtils.java
index a82b65f..c3343d4 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryUtils.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryUtils.java
@@ -17,28 +17,15 @@
 
 package org.apache.ignite.internal.binary;
 
-import org.apache.ignite.IgniteCheckedException;
-import org.apache.ignite.binary.BinaryCollectionFactory;
-import org.apache.ignite.binary.BinaryInvalidTypeException;
-import org.apache.ignite.binary.BinaryMapFactory;
-import org.apache.ignite.binary.BinaryObject;
-import org.apache.ignite.binary.BinaryObjectException;
-import org.apache.ignite.binary.Binarylizable;
-import org.apache.ignite.internal.binary.builder.BinaryLazyValue;
-import org.apache.ignite.internal.binary.streams.BinaryInputStream;
-import org.apache.ignite.internal.util.typedef.F;
-import org.apache.ignite.internal.util.typedef.internal.U;
-import org.apache.ignite.lang.IgniteBiTuple;
-import org.jetbrains.annotations.Nullable;
-import org.jsr166.ConcurrentHashMap8;
-
 import java.io.ByteArrayInputStream;
 import java.io.Externalizable;
 import java.io.ObjectInputStream;
 import java.io.ObjectOutputStream;
 import java.lang.reflect.Array;
+import java.lang.reflect.InvocationHandler;
 import java.lang.reflect.Method;
 import java.lang.reflect.Modifier;
+import java.lang.reflect.Proxy;
 import java.math.BigDecimal;
 import java.math.BigInteger;
 import java.sql.Timestamp;
@@ -58,6 +45,20 @@ import java.util.TreeSet;
 import java.util.UUID;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ConcurrentSkipListSet;
+import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.binary.BinaryCollectionFactory;
+import org.apache.ignite.binary.BinaryInvalidTypeException;
+import org.apache.ignite.binary.BinaryMapFactory;
+import org.apache.ignite.binary.BinaryObject;
+import org.apache.ignite.binary.BinaryObjectException;
+import org.apache.ignite.binary.Binarylizable;
+import org.apache.ignite.internal.binary.builder.BinaryLazyValue;
+import org.apache.ignite.internal.binary.streams.BinaryInputStream;
+import org.apache.ignite.internal.util.typedef.F;
+import org.apache.ignite.internal.util.typedef.internal.U;
+import org.apache.ignite.lang.IgniteBiTuple;
+import org.jetbrains.annotations.Nullable;
+import org.jsr166.ConcurrentHashMap8;
 
 import static java.nio.charset.StandardCharsets.UTF_8;
 
@@ -1042,6 +1043,8 @@ public class BinaryUtils {
             return BinaryWriteMode.ENUM;
         else if (cls == Class.class)
             return BinaryWriteMode.CLASS;
+        else if (Proxy.class.isAssignableFrom(cls))
+            return BinaryWriteMode.PROXY;
         else
             return BinaryWriteMode.OBJECT;
     }
@@ -1365,6 +1368,21 @@ public class BinaryUtils {
     }
 
     /**
+     * @return Value.
+     */
+    public static Object doReadProxy(BinaryInputStream in, BinaryContext ctx, ClassLoader
ldr,
+        BinaryReaderHandlesHolder handles) {
+        Class<?>[] intfs = new Class<?>[in.readInt()];
+
+        for (int i = 0; i < intfs.length; i++)
+            intfs[i] = doReadClass(in, ctx, ldr);
+
+        InvocationHandler ih = (InvocationHandler)doReadObject(in, ctx, ldr, handles);
+
+        return Proxy.newProxyInstance(ldr != null ? ldr : U.gridClassLoader(), intfs, ih);
+    }
+
+    /**
      * Read plain type.
      *
      * @param in Input stream.

http://git-wip-us.apache.org/repos/asf/ignite/blob/98dd3e76/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryWriteMode.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryWriteMode.java
b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryWriteMode.java
index b037945..7e8c9bd 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryWriteMode.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryWriteMode.java
@@ -148,6 +148,9 @@ public enum BinaryWriteMode {
     CLASS(GridBinaryMarshaller.CLASS),
 
     /** */
+    PROXY(GridBinaryMarshaller.PROXY),
+
+    /** */
     BINARY(GridBinaryMarshaller.BINARY_OBJ),
 
     /** */

http://git-wip-us.apache.org/repos/asf/ignite/blob/98dd3e76/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryWriterExImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryWriterExImpl.java
b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryWriterExImpl.java
index 877a2db..8060a13 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryWriterExImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryWriterExImpl.java
@@ -19,7 +19,9 @@ package org.apache.ignite.internal.binary;
 
 import java.io.IOException;
 import java.io.ObjectOutput;
+import java.lang.reflect.InvocationHandler;
 import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Proxy;
 import java.math.BigDecimal;
 import java.math.BigInteger;
 import java.sql.Timestamp;
@@ -817,6 +819,38 @@ public class BinaryWriterExImpl implements BinaryWriter, BinaryRawWriterEx,
Obje
     }
 
     /**
+     * @param proxy Proxy.
+     */
+    public void doWriteProxy(Proxy proxy, Class<?>[] intfs) {
+        if (proxy == null)
+            out.writeByte(GridBinaryMarshaller.NULL);
+        else {
+            out.unsafeEnsure(1 + 4);
+
+            out.unsafeWriteByte(GridBinaryMarshaller.PROXY);
+            out.unsafeWriteInt(intfs.length);
+
+            for (Class<?> intf : intfs) {
+                BinaryClassDescriptor desc = ctx.descriptorForClass(intf, false);
+
+                if (desc.registered())
+                    out.writeInt(desc.typeId());
+                else {
+                    out.writeInt(GridBinaryMarshaller.UNREGISTERED_TYPE_ID);
+
+                    doWriteString(intf.getName());
+                }
+            }
+
+            InvocationHandler ih = Proxy.getInvocationHandler(proxy);
+
+            assert ih != null;
+
+            doWriteObject(ih);
+        }
+    }
+
+    /**
      * @param po Binary object.
      */
     public void doWriteBinaryObject(@Nullable BinaryObjectImpl po) {

http://git-wip-us.apache.org/repos/asf/ignite/blob/98dd3e76/modules/core/src/main/java/org/apache/ignite/internal/binary/GridBinaryMarshaller.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/GridBinaryMarshaller.java
b/modules/core/src/main/java/org/apache/ignite/internal/binary/GridBinaryMarshaller.java
index da43558..687cfeb 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/binary/GridBinaryMarshaller.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/GridBinaryMarshaller.java
@@ -144,6 +144,9 @@ public class GridBinaryMarshaller {
     /** Timestamp array. */
     public static final byte TIMESTAMP_ARR = 34;
 
+    /** Proxy. */
+    public static final byte PROXY = 35;
+
     /** */
     public static final byte NULL = (byte)101;
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/98dd3e76/modules/core/src/main/java/org/apache/ignite/marshaller/optimized/OptimizedClassDescriptor.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/marshaller/optimized/OptimizedClassDescriptor.java
b/modules/core/src/main/java/org/apache/ignite/marshaller/optimized/OptimizedClassDescriptor.java
index a4f4cdc..0c6c402 100644
--- a/modules/core/src/main/java/org/apache/ignite/marshaller/optimized/OptimizedClassDescriptor.java
+++ b/modules/core/src/main/java/org/apache/ignite/marshaller/optimized/OptimizedClassDescriptor.java
@@ -26,9 +26,11 @@ import java.io.ObjectStreamField;
 import java.io.Serializable;
 import java.lang.reflect.Constructor;
 import java.lang.reflect.Field;
+import java.lang.reflect.InvocationHandler;
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
 import java.lang.reflect.Modifier;
+import java.lang.reflect.Proxy;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.Comparator;
@@ -80,6 +82,7 @@ import static org.apache.ignite.marshaller.optimized.OptimizedMarshallerUtils.LO
 import static org.apache.ignite.marshaller.optimized.OptimizedMarshallerUtils.LONG_ARR;
 import static org.apache.ignite.marshaller.optimized.OptimizedMarshallerUtils.OBJ_ARR;
 import static org.apache.ignite.marshaller.optimized.OptimizedMarshallerUtils.PROPS;
+import static org.apache.ignite.marshaller.optimized.OptimizedMarshallerUtils.PROXY;
 import static org.apache.ignite.marshaller.optimized.OptimizedMarshallerUtils.SERIALIZABLE;
 import static org.apache.ignite.marshaller.optimized.OptimizedMarshallerUtils.SHORT;
 import static org.apache.ignite.marshaller.optimized.OptimizedMarshallerUtils.SHORT_ARR;
@@ -164,6 +167,9 @@ class OptimizedClassDescriptor {
     /** Access order field offset. */
     private long accessOrderFieldOff;
 
+    /** Proxy interfaces. */
+    private Class<?>[] proxyIntfs;
+
     /**
      * Creates descriptor for class.
      *
@@ -331,6 +337,11 @@ class OptimizedClassDescriptor {
 
                 isCls = true;
             }
+            else if (Proxy.class.isAssignableFrom(cls)) {
+                type = PROXY;
+
+                proxyIntfs = cls.getInterfaces();
+            }
             else {
                 Class<?> c = cls;
 
@@ -560,6 +571,13 @@ class OptimizedClassDescriptor {
     }
 
     /**
+     * @return {@code True} if descriptor is for {@link Proxy}.
+     */
+    boolean isProxy() {
+        return type == PROXY;
+    }
+
+    /**
      * Replaces object.
      *
      * @param obj Object.
@@ -740,6 +758,23 @@ class OptimizedClassDescriptor {
 
                 break;
 
+            case PROXY:
+                out.writeInt(proxyIntfs.length);
+
+                for (Class<?> intf : proxyIntfs) {
+                    OptimizedClassDescriptor intfDesc = classDescriptor(clsMap, intf, ctx,
mapper);
+
+                    intfDesc.writeTypeData(out);
+                }
+
+                InvocationHandler ih = Proxy.getInvocationHandler(obj);
+
+                assert ih != null;
+
+                out.writeObject(ih);
+
+                break;
+
             case ENUM:
                 writeTypeData(out);
 
@@ -1019,4 +1054,4 @@ class OptimizedClassDescriptor {
             return fields.get(i);
         }
     }
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/98dd3e76/modules/core/src/main/java/org/apache/ignite/marshaller/optimized/OptimizedMarshallerUtils.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/marshaller/optimized/OptimizedMarshallerUtils.java
b/modules/core/src/main/java/org/apache/ignite/marshaller/optimized/OptimizedMarshallerUtils.java
index da92b90..303c2a6 100644
--- a/modules/core/src/main/java/org/apache/ignite/marshaller/optimized/OptimizedMarshallerUtils.java
+++ b/modules/core/src/main/java/org/apache/ignite/marshaller/optimized/OptimizedMarshallerUtils.java
@@ -140,6 +140,9 @@ class OptimizedMarshallerUtils {
     static final byte CLS = 28;
 
     /** */
+    static final byte PROXY = 29;
+
+    /** */
     static final byte ENUM = 100;
 
     /** */

http://git-wip-us.apache.org/repos/asf/ignite/blob/98dd3e76/modules/core/src/main/java/org/apache/ignite/marshaller/optimized/OptimizedObjectInputStream.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/marshaller/optimized/OptimizedObjectInputStream.java
b/modules/core/src/main/java/org/apache/ignite/marshaller/optimized/OptimizedObjectInputStream.java
index ce9ee0b..adbc4f9 100644
--- a/modules/core/src/main/java/org/apache/ignite/marshaller/optimized/OptimizedObjectInputStream.java
+++ b/modules/core/src/main/java/org/apache/ignite/marshaller/optimized/OptimizedObjectInputStream.java
@@ -25,8 +25,10 @@ import java.io.ObjectInputValidation;
 import java.io.ObjectStreamClass;
 import java.lang.reflect.Array;
 import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationHandler;
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Date;
@@ -78,6 +80,7 @@ import static org.apache.ignite.marshaller.optimized.OptimizedMarshallerUtils.LO
 import static org.apache.ignite.marshaller.optimized.OptimizedMarshallerUtils.NULL;
 import static org.apache.ignite.marshaller.optimized.OptimizedMarshallerUtils.OBJ_ARR;
 import static org.apache.ignite.marshaller.optimized.OptimizedMarshallerUtils.PROPS;
+import static org.apache.ignite.marshaller.optimized.OptimizedMarshallerUtils.PROXY;
 import static org.apache.ignite.marshaller.optimized.OptimizedMarshallerUtils.SERIALIZABLE;
 import static org.apache.ignite.marshaller.optimized.OptimizedMarshallerUtils.SHORT;
 import static org.apache.ignite.marshaller.optimized.OptimizedMarshallerUtils.SHORT_ARR;
@@ -301,6 +304,16 @@ class OptimizedObjectInputStream extends ObjectInputStream {
             case CLS:
                 return readClass();
 
+            case PROXY:
+                Class<?>[] intfs = new Class<?>[readInt()];
+
+                for (int i = 0; i < intfs.length; i++)
+                    intfs[i] = readClass();
+
+                InvocationHandler ih = (InvocationHandler)readObject();
+
+                return Proxy.newProxyInstance(clsLdr != null ? clsLdr : U.gridClassLoader(),
intfs, ih);
+
             case ENUM:
             case EXTERNALIZABLE:
             case SERIALIZABLE:
@@ -1219,4 +1232,4 @@ class OptimizedObjectInputStream extends ObjectInputStream {
             return objs[fieldInfo.getIndex(name)] != null ? (T)objs[fieldInfo.getIndex(name)]
: dflt;
         }
     }
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/98dd3e76/modules/core/src/main/java/org/apache/ignite/marshaller/optimized/OptimizedObjectOutputStream.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/marshaller/optimized/OptimizedObjectOutputStream.java
b/modules/core/src/main/java/org/apache/ignite/marshaller/optimized/OptimizedObjectOutputStream.java
index d884564..96cbbcd 100644
--- a/modules/core/src/main/java/org/apache/ignite/marshaller/optimized/OptimizedObjectOutputStream.java
+++ b/modules/core/src/main/java/org/apache/ignite/marshaller/optimized/OptimizedObjectOutputStream.java
@@ -227,7 +227,7 @@ class OptimizedObjectOutputStream extends ObjectOutputStream {
 
                 int handle = -1;
 
-                if (!desc.isPrimitive() && !desc.isEnum() && !desc.isClass())
+                if (!desc.isPrimitive() && !desc.isEnum() && !desc.isClass()
&& !desc.isProxy())
                     handle = handles.lookup(obj);
 
                 if (obj0 != obj) {
@@ -895,4 +895,4 @@ class OptimizedObjectOutputStream extends ObjectOutputStream {
             objs[i] = F.t(info.type(), val);
         }
     }
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/98dd3e76/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index bead3ae..0645283 100644
--- a/pom.xml
+++ b/pom.xml
@@ -84,7 +84,7 @@
         <module>modules/osgi-paxlogging</module>
         <module>modules/osgi-karaf</module>
         <module>modules/osgi</module>
-		<module>modules/benchmarks</module>
+		<!--<module>modules/benchmarks</module>-->
     </modules>
 
     <profiles>


Mime
View raw message