ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From agoncha...@apache.org
Subject ignite git commit: Validate hash code presence in BinaryObject. Fixes #928
Date Wed, 28 Sep 2016 13:52:52 GMT
Repository: ignite
Updated Branches:
  refs/heads/master ed4739235 -> 2489b8afb


Validate hash code presence in BinaryObject. Fixes #928


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

Branch: refs/heads/master
Commit: 2489b8afb408fec7760760aedd98d44085f95748
Parents: ed47392
Author: Alexander Paschenko <alexander.a.paschenko@gmail.com>
Authored: Wed Sep 28 16:46:46 2016 +0300
Committer: Alexey Goncharuk <alexey.goncharuk@gmail.com>
Committed: Wed Sep 28 16:50:52 2016 +0300

----------------------------------------------------------------------
 .../internal/binary/BinaryClassDescriptor.java  | 16 ++++-
 .../internal/binary/BinaryEnumObjectImpl.java   |  5 ++
 .../ignite/internal/binary/BinaryObjectEx.java  |  8 +++
 .../internal/binary/BinaryObjectImpl.java       |  7 +++
 .../binary/BinaryObjectOffheapImpl.java         |  7 +++
 .../ignite/internal/binary/BinaryUtils.java     |  5 +-
 .../internal/binary/BinaryWriterExImpl.java     |  6 +-
 .../binary/builder/BinaryObjectBuilderImpl.java | 11 +++-
 .../processors/cache/GridCacheUtils.java        |  5 ++
 .../ignite/internal/util/IgniteUtils.java       | 23 ++++++-
 ...ridCacheStoreManagerDeserializationTest.java |  1 +
 .../cache/GridCacheUtilsSelfTest.java           | 64 +++++++++++++++++++-
 ...calCacheStoreManagerDeserializationTest.java |  2 +-
 .../GridCacheBinaryObjectsAbstractSelfTest.java | 31 ++++++++++
 14 files changed, 182 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/2489b8af/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 083057d..4c824d4 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
@@ -41,6 +41,7 @@ import org.apache.ignite.binary.BinarySerializer;
 import org.apache.ignite.binary.Binarylizable;
 import org.apache.ignite.internal.processors.cache.CacheObjectImpl;
 import org.apache.ignite.internal.util.GridUnsafe;
+import org.apache.ignite.internal.util.IgniteUtils;
 import org.apache.ignite.internal.util.tostring.GridToStringExclude;
 import org.apache.ignite.internal.util.typedef.internal.S;
 import org.apache.ignite.internal.util.typedef.internal.U;
@@ -114,6 +115,9 @@ public class BinaryClassDescriptor {
     private final boolean excluded;
 
     /** */
+    private final boolean overridesHashCode;
+
+    /** */
     private final Class<?>[] intfs;
 
     /**
@@ -164,6 +168,8 @@ public class BinaryClassDescriptor {
         this.mapper = mapper;
         this.registered = registered;
 
+        overridesHashCode = IgniteUtils.overridesEqualsAndHashCode(cls);
+
         schemaReg = ctx.schemaRegistry(typeId);
 
         excluded = MarshallerExclusions.isExcluded(cls);
@@ -845,7 +851,15 @@ public class BinaryClassDescriptor {
      * @param obj Object.
      */
     private void postWrite(BinaryWriterExImpl writer, Object obj) {
-        writer.postWrite(userType, registered, obj instanceof CacheObjectImpl ? 0 : obj.hashCode());
+        if (obj instanceof CacheObjectImpl)
+            writer.postWrite(userType, registered, 0, false);
+        else if (obj instanceof BinaryObjectEx) {
+            boolean flagSet = ((BinaryObjectEx)obj).isFlagSet(BinaryUtils.FLAG_EMPTY_HASH_CODE);
+
+            writer.postWrite(userType, registered, obj.hashCode(), !flagSet);
+        }
+        else
+            writer.postWrite(userType, registered, obj.hashCode(), overridesHashCode);
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/ignite/blob/2489b8af/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryEnumObjectImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryEnumObjectImpl.java
b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryEnumObjectImpl.java
index c9874ed..dcfcc9d 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryEnumObjectImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryEnumObjectImpl.java
@@ -139,6 +139,11 @@ public class BinaryEnumObjectImpl implements BinaryObjectEx, Externalizable,
Cac
     }
 
     /** {@inheritDoc} */
+    @Override public boolean isFlagSet(short flag) {
+        return false;
+    }
+
+    /** {@inheritDoc} */
     @Override public <F> F field(String fieldName) throws BinaryObjectException {
         return null;
     }

http://git-wip-us.apache.org/repos/asf/ignite/blob/2489b8af/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryObjectEx.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryObjectEx.java
b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryObjectEx.java
index e3566bc..4e137b7 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryObjectEx.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryObjectEx.java
@@ -38,4 +38,12 @@ public interface BinaryObjectEx extends BinaryObject {
      * @throws BinaryObjectException If failed.
      */
     @Nullable public BinaryType rawType() throws BinaryObjectException;
+
+    /**
+     * Check if flag set.
+     *
+     * @param flag flag to check.
+     * @return {@code true} if flag is set, {@code false} otherwise.
+     */
+    public boolean isFlagSet(short flag);
 }

http://git-wip-us.apache.org/repos/asf/ignite/blob/2489b8af/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryObjectImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryObjectImpl.java
b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryObjectImpl.java
index 7b42c03..f37d7c2 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryObjectImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryObjectImpl.java
@@ -246,6 +246,13 @@ public final class BinaryObjectImpl extends BinaryObjectExImpl implements
Extern
     }
 
     /** {@inheritDoc} */
+    @Override public boolean isFlagSet(short flag) {
+        short flags = BinaryPrimitives.readShort(arr, start + GridBinaryMarshaller.FLAGS_POS);
+
+        return BinaryUtils.isFlagSet(flags, flag);
+    }
+
+    /** {@inheritDoc} */
     @Override public int typeId() {
         int off = start + GridBinaryMarshaller.TYPE_ID_POS;
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/2489b8af/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryObjectOffheapImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryObjectOffheapImpl.java
b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryObjectOffheapImpl.java
index 2225b7a..9cbbaa2 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryObjectOffheapImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryObjectOffheapImpl.java
@@ -145,6 +145,13 @@ public class BinaryObjectOffheapImpl extends BinaryObjectExImpl implements
Exter
     }
 
     /** {@inheritDoc} */
+    @Override public boolean isFlagSet(short flag) {
+        short flags = BinaryPrimitives.readShort(ptr, start + GridBinaryMarshaller.FLAGS_POS);
+
+        return BinaryUtils.isFlagSet(flags, flag);
+    }
+
+    /** {@inheritDoc} */
     @Nullable @Override public BinaryType type() throws BinaryObjectException {
         return BinaryUtils.typeProxy(ctx, this);
     }

http://git-wip-us.apache.org/repos/asf/ignite/blob/2489b8af/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 b5834a5..25d87ff 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
@@ -109,6 +109,9 @@ public class BinaryUtils {
     /** Flag: compact footer, no field IDs. */
     public static final short FLAG_COMPACT_FOOTER = 0x0020;
 
+    /** Flag: no hash code has been set. */
+    public static final short FLAG_EMPTY_HASH_CODE = 0x0040;
+
     /** Offset which fits into 1 byte. */
     public static final int OFFSET_1 = 1;
 
@@ -305,7 +308,7 @@ public class BinaryUtils {
      * @param flag Flag.
      * @return {@code True} if flag is set in flags.
      */
-    private static boolean isFlagSet(short flags, short flag) {
+    static boolean isFlagSet(short flags, short flag) {
         return (flags & flag) == flag;
     }
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/2489b8af/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 1a81819..22b4d1f 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
@@ -245,8 +245,9 @@ public class BinaryWriterExImpl implements BinaryWriter, BinaryRawWriterEx,
Obje
      * @param userType User type flag.
      * @param registered Whether type is registered.
      * @param hashCode Hash code.
+     * @param isHashCodeSet Hash code presence flag.
      */
-    public void postWrite(boolean userType, boolean registered, int hashCode) {
+    public void postWrite(boolean userType, boolean registered, int hashCode, boolean isHashCodeSet)
{
         short flags;
         boolean useCompactFooter;
 
@@ -303,6 +304,9 @@ public class BinaryWriterExImpl implements BinaryWriter, BinaryRawWriterEx,
Obje
             }
         }
 
+        if (!isHashCodeSet)
+            flags |= BinaryUtils.FLAG_EMPTY_HASH_CODE;
+
         // Actual write.
         int retPos = out.position();
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/2489b8af/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/BinaryObjectBuilderImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/BinaryObjectBuilderImpl.java
b/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/BinaryObjectBuilderImpl.java
index 086da5c..2c76192 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/BinaryObjectBuilderImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/BinaryObjectBuilderImpl.java
@@ -86,6 +86,9 @@ public class BinaryObjectBuilderImpl implements BinaryObjectBuilder {
     /** */
     private int hashCode;
 
+    /** */
+    private boolean isHashCodeSet;
+
     /**
      * @param clsName Class name.
      * @param ctx Binary context.
@@ -117,7 +120,7 @@ public class BinaryObjectBuilderImpl implements BinaryObjectBuilder {
      */
     public BinaryObjectBuilderImpl(BinaryObjectImpl obj) {
         this(new BinaryBuilderReader(obj), obj.start());
-
+        isHashCodeSet = !obj.isFlagSet(BinaryUtils.FLAG_EMPTY_HASH_CODE);
         reader.registerObject(this);
     }
 
@@ -329,7 +332,8 @@ public class BinaryObjectBuilderImpl implements BinaryObjectBuilder {
                 reader.position(start + BinaryUtils.length(reader, start));
             }
 
-            writer.postWrite(true, registeredType, hashCode);
+            //noinspection NumberEquality
+            writer.postWrite(true, registeredType, hashCode, isHashCodeSet);
 
             // Update metadata if needed.
             int schemaId = writer.schemaId();
@@ -408,9 +412,12 @@ public class BinaryObjectBuilderImpl implements BinaryObjectBuilder {
     }
 
     /** {@inheritDoc} */
+    @SuppressWarnings("UnnecessaryBoxing")
     @Override public BinaryObjectBuilderImpl hashCode(int hashCode) {
         this.hashCode = hashCode;
 
+        isHashCodeSet = true;
+
         return this;
     }
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/2489b8af/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheUtils.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheUtils.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheUtils.java
index 1a4ffd5..0f4e89b 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheUtils.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheUtils.java
@@ -1170,6 +1170,7 @@ public class GridCacheUtils {
 
     /**
      * Validates that cache key object has overridden equals and hashCode methods.
+     * Will also check that a BinaryObject has a hash code set.
      *
      * @param key Key.
      * @throws IllegalArgumentException If equals or hashCode is not implemented.
@@ -1181,6 +1182,10 @@ public class GridCacheUtils {
         if (!U.overridesEqualsAndHashCode(key))
             throw new IllegalArgumentException("Cache key must override hashCode() and equals()
methods: " +
                 key.getClass().getName());
+
+        if (U.isHashCodeEmpty(key))
+            throw new IllegalArgumentException("Cache key created with BinaryBuilder is missing
hash code - " +
+                "please set it explicitly during building by using BinaryBuilder.hashCode(int)");
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/ignite/blob/2489b8af/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteUtils.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteUtils.java b/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteUtils.java
index 93acc75..569a25f 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteUtils.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteUtils.java
@@ -149,6 +149,7 @@ import org.apache.ignite.IgniteException;
 import org.apache.ignite.IgniteInterruptedException;
 import org.apache.ignite.IgniteLogger;
 import org.apache.ignite.IgniteSystemProperties;
+import org.apache.ignite.binary.BinaryObject;
 import org.apache.ignite.binary.BinaryRawReader;
 import org.apache.ignite.binary.BinaryRawWriter;
 import org.apache.ignite.cluster.ClusterGroupEmptyException;
@@ -170,6 +171,8 @@ import org.apache.ignite.internal.IgniteFutureTimeoutCheckedException;
 import org.apache.ignite.internal.IgniteInternalFuture;
 import org.apache.ignite.internal.IgniteInterruptedCheckedException;
 import org.apache.ignite.internal.IgniteNodeAttributes;
+import org.apache.ignite.internal.binary.BinaryObjectEx;
+import org.apache.ignite.internal.binary.BinaryUtils;
 import org.apache.ignite.internal.cluster.ClusterGroupEmptyCheckedException;
 import org.apache.ignite.internal.cluster.ClusterTopologyCheckedException;
 import org.apache.ignite.internal.compute.ComputeTaskCancelledCheckedException;
@@ -8514,9 +8517,15 @@ public abstract class IgniteUtils {
      * @return {@code True} if given object has overridden equals and hashCode method.
      */
     public static boolean overridesEqualsAndHashCode(Object obj) {
-        try {
-            Class<?> cls = obj.getClass();
+        return overridesEqualsAndHashCode(obj.getClass());
+    }
 
+    /**
+     * @param cls Class.
+     * @return {@code True} if given class has overridden equals and hashCode method.
+     */
+    public static boolean overridesEqualsAndHashCode(Class<?> cls) {
+        try {
             return !Object.class.equals(cls.getMethod("equals", Object.class).getDeclaringClass())
&&
                 !Object.class.equals(cls.getMethod("hashCode").getDeclaringClass());
         }
@@ -8526,6 +8535,16 @@ public abstract class IgniteUtils {
     }
 
     /**
+     * @param obj Object.
+     * @return {@code True} if given object is a {@link BinaryObjectEx} and
+     * has {@link BinaryUtils#FLAG_EMPTY_HASH_CODE} set
+     */
+    public static boolean isHashCodeEmpty(Object obj) {
+        return obj != null && obj instanceof BinaryObjectEx &&
+            ((BinaryObjectEx)obj).isFlagSet(BinaryUtils.FLAG_EMPTY_HASH_CODE);
+    }
+
+    /**
      * Checks if error is MAC invalid argument error which ususally requires special handling.
      *
      * @param e Exception.

http://git-wip-us.apache.org/repos/asf/ignite/blob/2489b8af/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheStoreManagerDeserializationTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheStoreManagerDeserializationTest.java
b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheStoreManagerDeserializationTest.java
index 4a069a9..39ce33d 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheStoreManagerDeserializationTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheStoreManagerDeserializationTest.java
@@ -279,6 +279,7 @@ public class GridCacheStoreManagerDeserializationTest extends GridCommonAbstract
 
         for (int i = 0; i < 1; i++) {
             builder.setField("id", i);
+            builder.hashCode(i);
 
             entity = builder.build();
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/2489b8af/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheUtilsSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheUtilsSelfTest.java
b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheUtilsSelfTest.java
index d5888e7..5f2c004 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheUtilsSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheUtilsSelfTest.java
@@ -18,7 +18,21 @@
 package org.apache.ignite.internal.processors.cache;
 
 import java.util.concurrent.Callable;
+import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.binary.BinaryObject;
+import org.apache.ignite.configuration.BinaryConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.binary.BinaryCachingMetadataHandler;
+import org.apache.ignite.internal.binary.BinaryContext;
+import org.apache.ignite.internal.binary.BinaryMarshaller;
+import org.apache.ignite.internal.binary.BinaryObjectImpl;
+import org.apache.ignite.internal.binary.GridBinaryMarshaller;
+import org.apache.ignite.internal.binary.builder.BinaryObjectBuilderImpl;
+import org.apache.ignite.internal.util.IgniteUtils;
 import org.apache.ignite.internal.util.typedef.internal.CU;
+import org.apache.ignite.internal.util.typedef.internal.U;
+import org.apache.ignite.logger.NullLogger;
+import org.apache.ignite.marshaller.MarshallerContextTestImpl;
 import org.apache.ignite.testframework.GridTestUtils;
 import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
 
@@ -104,7 +118,8 @@ public class GridCacheUtilsSelfTest extends GridCommonAbstractTest {
 
     /**
      */
-    public void testCacheKeyValidation() {
+    @SuppressWarnings("ResultOfMethodCallIgnored")
+    public void testCacheKeyValidation() throws IgniteCheckedException {
         CU.validateCacheKey("key");
 
         CU.validateCacheKey(1);
@@ -124,6 +139,53 @@ public class GridCacheUtilsSelfTest extends GridCommonAbstractTest {
         assertThrowsForInvalidKey(new NoHashCode());
 
         assertThrowsForInvalidKey(new WrongEquals());
+
+        BinaryObjectBuilderImpl binBuilder = new BinaryObjectBuilderImpl(binaryContext(),
+            EqualsAndHashCode.class.getName());
+
+        assertThrowsForInvalidKey(binBuilder.build());
+
+        binBuilder.hashCode(0xFE12);
+
+        BinaryObject binObj = binBuilder.build();
+
+        CU.validateCacheKey(binObj);
+
+        BinaryObjectBuilderImpl binBuilder2 = new BinaryObjectBuilderImpl((BinaryObjectImpl)
binObj);
+
+        CU.validateCacheKey(binBuilder2.build());
+    }
+
+    /**
+     * @return Binary marshaller.
+     * @throws IgniteCheckedException if failed.
+     */
+    private BinaryMarshaller binaryMarshaller() throws IgniteCheckedException {
+        IgniteConfiguration iCfg = new IgniteConfiguration();
+
+        BinaryConfiguration bCfg = new BinaryConfiguration();
+
+        iCfg.setBinaryConfiguration(bCfg);
+
+        BinaryContext ctx = new BinaryContext(BinaryCachingMetadataHandler.create(), iCfg,
new NullLogger());
+
+        BinaryMarshaller marsh = new BinaryMarshaller();
+
+        marsh.setContext(new MarshallerContextTestImpl(null));
+
+        IgniteUtils.invoke(BinaryMarshaller.class, marsh, "setBinaryContext", ctx, iCfg);
+
+        return marsh;
+    }
+
+    /**
+     * @return Binary context.
+     * @throws IgniteCheckedException if failed.
+     */
+    private BinaryContext binaryContext() throws IgniteCheckedException {
+        GridBinaryMarshaller impl = U.field(binaryMarshaller(), "impl");
+
+        return impl.context();
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/ignite/blob/2489b8af/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridLocalCacheStoreManagerDeserializationTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridLocalCacheStoreManagerDeserializationTest.java
b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridLocalCacheStoreManagerDeserializationTest.java
index 827b3cf..b86fe53 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridLocalCacheStoreManagerDeserializationTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridLocalCacheStoreManagerDeserializationTest.java
@@ -86,7 +86,7 @@ public class GridLocalCacheStoreManagerDeserializationTest extends GridCacheStor
 
         final BinaryObjectBuilder builder = grid.binary().builder("custom_type");
 
-        final BinaryObject entity = builder.setField("id", 0).build();
+        final BinaryObject entity = builder.setField("id", 0).hashCode(0).build();
 
         cache.put(entity, entity);
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/2489b8af/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/GridCacheBinaryObjectsAbstractSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/GridCacheBinaryObjectsAbstractSelfTest.java
b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/GridCacheBinaryObjectsAbstractSelfTest.java
index 3a510c3..7936ea4 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/GridCacheBinaryObjectsAbstractSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/GridCacheBinaryObjectsAbstractSelfTest.java
@@ -28,6 +28,7 @@ import java.util.Iterator;
 import java.util.Map;
 import java.util.Set;
 import java.util.UUID;
+import java.util.concurrent.Callable;
 import javax.cache.Cache;
 import javax.cache.processor.EntryProcessor;
 import javax.cache.processor.EntryProcessorException;
@@ -887,6 +888,36 @@ public abstract class GridCacheBinaryObjectsAbstractSelfTest extends
GridCommonA
     }
 
     /**
+     * @throws Exception If failed.
+     */
+    @SuppressWarnings({ "ThrowableResultOfMethodCallIgnored", "unchecked" })
+    public void testPutWithoutHashCode() throws Exception {
+        final IgniteCache c = jcache(0);
+
+        GridTestUtils.assertThrows(log, new Callable<Object>() {
+            /** {@inheritDoc} */
+            @Override public Object call() throws Exception {
+                c.put(new TestObject(5), 5);
+                return null;
+            }
+        }, IllegalArgumentException.class, "Cache key must override hashCode() and equals()
methods: ");
+
+        BinaryObjectBuilder bldr = grid(0).binary().builder(TestObject.class.getName());
+        bldr.setField("val", 5);
+
+        final BinaryObject binKey = bldr.build();
+
+        GridTestUtils.assertThrows(log, new Callable<Object>() {
+            /** {@inheritDoc} */
+            @Override public Object call() throws Exception {
+                c.put(binKey, 5);
+                return null;
+            }
+        }, IllegalArgumentException.class, "Cache key created with BinaryBuilder is missing
hash code - " +
+            "please set it explicitly during building by using BinaryBuilder.hashCode(int)");
+    }
+
+    /**
      * @throws Exception if failed.
      */
     public void testKeepBinaryTxOverwrite() throws Exception {


Mime
View raw message