Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 464E4200C17 for ; Thu, 5 Jan 2017 09:58:07 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id 44F4B160B27; Thu, 5 Jan 2017 08:58:07 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 25EF0160B5D for ; Thu, 5 Jan 2017 09:58:05 +0100 (CET) Received: (qmail 11498 invoked by uid 500); 5 Jan 2017 08:58:05 -0000 Mailing-List: contact commits-help@ignite.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@ignite.apache.org Delivered-To: mailing list commits@ignite.apache.org Received: (qmail 10851 invoked by uid 99); 5 Jan 2017 08:58:05 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 05 Jan 2017 08:58:05 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id D3DA9DFD6F; Thu, 5 Jan 2017 08:58:04 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: vozerov@apache.org To: commits@ignite.apache.org Date: Thu, 05 Jan 2017 08:58:23 -0000 Message-Id: In-Reply-To: <76c54cad1ab1489682d63371d771d299@git.apache.org> References: <76c54cad1ab1489682d63371d771d299@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [20/26] ignite git commit: IGNITE-4109 - BinaryType.isEnum() throws an exception if typeId==0 archived-at: Thu, 05 Jan 2017 08:58:07 -0000 IGNITE-4109 - BinaryType.isEnum() throws an exception if typeId==0 Project: http://git-wip-us.apache.org/repos/asf/ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/2ccae40e Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/2ccae40e Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/2ccae40e Branch: refs/heads/master Commit: 2ccae40e2a21398d15c3762b72575216c56a7fb0 Parents: 2da2816 Author: dkarachentsev Authored: Fri Dec 23 17:51:49 2016 +0300 Committer: dkarachentsev Committed: Fri Dec 23 17:51:49 2016 +0300 ---------------------------------------------------------------------- .../ignite/internal/binary/BinaryContext.java | 4 ++-- .../ignite/internal/binary/BinaryTypeProxy.java | 15 ++++++++++++--- .../ignite/internal/binary/BinaryUtils.java | 4 +++- .../internal/binary/BinaryEnumsSelfTest.java | 18 ++++++++++++++++++ 4 files changed, 35 insertions(+), 6 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ignite/blob/2ccae40e/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryContext.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryContext.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryContext.java index cc18318..4030ef0 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryContext.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryContext.java @@ -928,7 +928,7 @@ public class BinaryContext { * @param typeId Type ID. * @return Instance of ID mapper. */ - public BinaryInternalMapper userTypeMapper(int typeId) { + BinaryInternalMapper userTypeMapper(int typeId) { BinaryInternalMapper mapper = typeId2Mapper.get(typeId); return mapper != null ? mapper : SIMPLE_NAME_LOWER_CASE_MAPPER; @@ -938,7 +938,7 @@ public class BinaryContext { * @param clsName Type name. * @return Instance of ID mapper. */ - private BinaryInternalMapper userTypeMapper(String clsName) { + BinaryInternalMapper userTypeMapper(String clsName) { BinaryInternalMapper mapper = cls2Mappers.get(clsName); if (mapper != null) http://git-wip-us.apache.org/repos/asf/ignite/blob/2ccae40e/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryTypeProxy.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryTypeProxy.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryTypeProxy.java index 17b0bc6..df9901e 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryTypeProxy.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryTypeProxy.java @@ -24,6 +24,7 @@ import org.apache.ignite.internal.util.tostring.GridToStringExclude; import org.apache.ignite.internal.util.typedef.internal.S; import java.util.Collection; +import org.jetbrains.annotations.Nullable; /** * Binary type proxy. Is used to delay or completely avoid metadata lookup. @@ -34,21 +35,26 @@ public class BinaryTypeProxy implements BinaryType { private final BinaryContext ctx; /** Type ID. */ - private final int typeId; + private int typeId; + + /** Raw data. */ + private final String clsName; /** Target type. */ @GridToStringExclude private volatile BinaryType target; /** - * Constrcutor. + * Constructor. * * @param ctx Context. * @param typeId Type ID. + * @param clsName Class name. */ - public BinaryTypeProxy(BinaryContext ctx, int typeId) { + public BinaryTypeProxy(BinaryContext ctx, int typeId, @Nullable String clsName) { this.ctx = ctx; this.typeId = typeId; + this.clsName = clsName; } /** {@inheritDoc} */ @@ -93,6 +99,9 @@ public class BinaryTypeProxy implements BinaryType { if (target == null) { synchronized (this) { if (target == null) { + if (typeId == GridBinaryMarshaller.UNREGISTERED_TYPE_ID && clsName != null) + typeId = ctx.typeId(clsName); + target = ctx.metadata(typeId); if (target == null) http://git-wip-us.apache.org/repos/asf/ignite/blob/2ccae40e/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 bbf5021..fdc54c7 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 @@ -2228,7 +2228,9 @@ public class BinaryUtils { if (ctx == null) throw new BinaryObjectException("BinaryContext is not set for the object."); - return new BinaryTypeProxy(ctx, obj.typeId()); + String clsName = obj instanceof BinaryEnumObjectImpl ? ((BinaryEnumObjectImpl)obj).className() : null; + + return new BinaryTypeProxy(ctx, obj.typeId(), clsName); } /** http://git-wip-us.apache.org/repos/asf/ignite/blob/2ccae40e/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryEnumsSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryEnumsSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryEnumsSelfTest.java index fb7e618..91add0d 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryEnumsSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryEnumsSelfTest.java @@ -28,6 +28,7 @@ import org.apache.ignite.cache.CacheMode; import org.apache.ignite.configuration.BinaryConfiguration; import org.apache.ignite.configuration.CacheConfiguration; import org.apache.ignite.configuration.IgniteConfiguration; +import org.apache.ignite.internal.IgniteEx; import org.apache.ignite.internal.IgniteKernal; import org.apache.ignite.internal.processors.cache.binary.CacheObjectBinaryProcessorImpl; import org.apache.ignite.marshaller.Marshaller; @@ -389,6 +390,23 @@ public class BinaryEnumsSelfTest extends GridCommonAbstractTest { } /** + * Check ability to resolve typeId from class name. + * + * @throws Exception If failed. + */ + public void testZeroTypeId() throws Exception { + startUp(true); + + final BinaryContext ctx = + ((CacheObjectBinaryProcessorImpl)((IgniteEx)node1).context().cacheObjects()).binaryContext(); + + final BinaryObject enumObj = + new BinaryEnumObjectImpl(ctx, 0, EnumType.class.getName(), EnumType.ONE.ordinal()); + + assert enumObj.type().isEnum(); + } + + /** * Validate simple array. * * @param registered Registered flag.