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

ilyak 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 c55d91d  IGNITE-12324 Exception is masked in fieldOrder method with 
binary object of unregistered type - Fixes #7002.
c55d91d is described below

commit c55d91de4de321673c6da0819547da5d4ab2fa5a
Author: ktkalenko <[email protected]>
AuthorDate: Thu Oct 24 14:41:08 2019 +0300

    IGNITE-12324 Exception is masked in fieldOrder method with binary object of 
unregistered type - Fixes #7002.
    
    Signed-off-by: Ilya Kasnacheev <[email protected]>
---
 .../ignite/internal/binary/BinaryFieldImpl.java    | 15 +++++--
 .../binary/BinaryFieldExtractionSelfTest.java      | 46 +++++++++++++++++++++-
 2 files changed, 56 insertions(+), 5 deletions(-)

diff --git 
a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryFieldImpl.java
 
b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryFieldImpl.java
index f047704..0933de5 100644
--- 
a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryFieldImpl.java
+++ 
b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryFieldImpl.java
@@ -285,13 +285,22 @@ public class BinaryFieldImpl implements BinaryFieldEx {
         if (typeId != obj.typeId()) {
             BinaryType expType = ctx.metadata(typeId);
             BinaryType actualType = obj.type();
+            String actualTypeName = null;
+            Exception actualTypeNameEx = null;
+
+            try {
+                actualTypeName = actualType.typeName();
+            }
+            catch (BinaryObjectException e) {
+                actualTypeNameEx = new BinaryObjectException("Failed to get 
actual binary type name.", e);
+            }
 
             throw new BinaryObjectException("Failed to get field because type 
ID of passed object differs" +
                 " from type ID this " + BinaryField.class.getSimpleName() + " 
belongs to [expected=[typeId=" + typeId +
                 ", typeName=" + (nonNull(expType) ? expType.typeName() : null) 
+ "], actual=[typeId=" +
-                actualType.typeId() + ", typeName=" + actualType.typeName() + 
"], fieldId=" + fieldId +
-                ", fieldName=" + fieldName + ", fieldType=" +
-                (nonNull(expType) ? expType.fieldTypeName(fieldName) : null) + 
']');
+                actualType.typeId() + ", typeName=" + actualTypeName + "], 
fieldId=" + fieldId + ", fieldName=" +
+                fieldName + ", fieldType=" + (nonNull(expType) ? 
expType.fieldTypeName(fieldName) : null) + ']',
+                actualTypeNameEx);
         }
 
         int schemaId = obj.schemaId();
diff --git 
a/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryFieldExtractionSelfTest.java
 
b/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryFieldExtractionSelfTest.java
index 9846fa6..55ebd7c 100644
--- 
a/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryFieldExtractionSelfTest.java
+++ 
b/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryFieldExtractionSelfTest.java
@@ -31,6 +31,7 @@ import org.apache.ignite.marshaller.MarshallerContextTestImpl;
 import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
 import org.junit.Test;
 
+import static 
org.apache.ignite.internal.binary.GridBinaryMarshaller.TYPE_ID_POS;
 import static org.apache.ignite.testframework.GridTestUtils.assertThrows;
 
 /**
@@ -98,7 +99,7 @@ public class BinaryFieldExtractionSelfTest extends 
GridCommonAbstractTest {
             buf.flip();
 
             for (BinaryFieldEx field : fields)
-                assertEquals(field.value(bObj), field.readField(buf));
+                assertEquals((Object)field.value(bObj), field.readField(buf));
 
             buf.flip();
         }
@@ -195,6 +196,47 @@ public class BinaryFieldExtractionSelfTest extends 
GridCommonAbstractTest {
     }
 
     /**
+     * Check that when changing typeId of BinaryObject, when trying to get the
+     * field value BinaryObjectException will be thrown with the corresponding
+     * text.
+     *
+     * @throws Exception If failed.
+     */
+    @Test
+    public void testChangeTypeIdOfBinaryFieldCaseNotFoundActualTypeId() throws 
Exception {
+        BinaryMarshaller marsh = createMarshaller();
+
+        TimeValue timeVal = new TimeValue(11111L);
+
+        BinaryObjectImpl timeValBinObj = toBinary(timeVal, marsh);
+
+        BinaryFieldEx timeBinField = 
(BinaryFieldEx)timeValBinObj.type().field("time");
+
+        int beforeTypeId = timeValBinObj.typeId();
+
+        String fieldType = 
binaryContext(marsh).metadata(timeValBinObj.typeId()).fieldTypeName(timeBinField.name());
+
+        Field startField = U.findField(timeValBinObj.getClass(), "start");
+        int start = (int)startField.get(timeValBinObj);
+
+        Field arrField = U.findField(timeValBinObj.getClass(), "arr");
+        byte[] arr = (byte[])arrField.get(timeValBinObj);
+        arr[start + TYPE_ID_POS] += 1;
+
+        String expMsg = exceptionMessageOfDifferentTypeIdBinaryField(
+            beforeTypeId,
+            timeVal.getClass().getName(),
+            timeValBinObj.typeId(),
+            null,
+            U.field(timeBinField, "fieldId"),
+            timeBinField.name(),
+            fieldType
+        );
+
+        assertThrows(log, () -> timeBinField.value(timeValBinObj), 
BinaryObjectException.class, expMsg);
+    }
+
+    /**
      * @throws Exception If failed.
      */
     @Test
@@ -223,7 +265,7 @@ public class BinaryFieldExtractionSelfTest extends 
GridCommonAbstractTest {
 
             buf.flip();
 
-            assertEquals(field.value(binObj), field.readField(buf));
+            assertEquals((Object)field.value(binObj), field.readField(buf));
 
             buf.clear();
         }

Reply via email to