Return-Path: X-Original-To: apmail-ignite-commits-archive@minotaur.apache.org Delivered-To: apmail-ignite-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 826171837F for ; Fri, 30 Oct 2015 08:14:48 +0000 (UTC) Received: (qmail 92769 invoked by uid 500); 30 Oct 2015 08:14:48 -0000 Delivered-To: apmail-ignite-commits-archive@ignite.apache.org Received: (qmail 92687 invoked by uid 500); 30 Oct 2015 08:14:48 -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 92482 invoked by uid 99); 30 Oct 2015 08:14:48 -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; Fri, 30 Oct 2015 08:14:48 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 3A108E0BCB; Fri, 30 Oct 2015 08:14:48 +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: Fri, 30 Oct 2015 08:14:56 -0000 Message-Id: In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [09/10] ignite git commit: ignite-1717: NPE during running ScalarCreditRiskExample with portableMarshaller ignite-1717: NPE during running ScalarCreditRiskExample with portableMarshaller Project: http://git-wip-us.apache.org/repos/asf/ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/15da54b9 Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/15da54b9 Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/15da54b9 Branch: refs/heads/ignite-1282 Commit: 15da54b9e392791818c5419068e0761d7a78f613 Parents: 48de059 Author: Andrey Gura Authored: Thu Oct 29 16:15:07 2015 +0300 Committer: Denis Magda Committed: Thu Oct 29 16:15:07 2015 +0300 ---------------------------------------------------------------------- .../internal/portable/PortableWriterExImpl.java | 66 +++++++++++--------- 1 file changed, 35 insertions(+), 31 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ignite/blob/15da54b9/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableWriterExImpl.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableWriterExImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableWriterExImpl.java index 1d5ca60..a43ebc3 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableWriterExImpl.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableWriterExImpl.java @@ -77,7 +77,7 @@ import static org.apache.ignite.internal.portable.GridPortableMarshaller.UNREGIS import static org.apache.ignite.internal.portable.GridPortableMarshaller.UUID; import static org.apache.ignite.internal.portable.GridPortableMarshaller.UUID_ARR; - /** +/** * Portable writer implementation. */ public class PortableWriterExImpl implements PortableWriter, PortableRawWriterEx, ObjectOutput { @@ -187,6 +187,16 @@ public class PortableWriterExImpl implements PortableWriter, PortableRawWriterEx * @throws PortableException In case of error. */ void marshal(Object obj, boolean detached) throws PortableException { + marshal(obj, detached, true); + } + + /** + * @param obj Object. + * @param detached Detached or not. + * @param enableReplace Object replacing enabled flag. + * @throws PortableException In case of error. + */ + void marshal(Object obj, boolean detached, boolean enableReplace) throws PortableException { assert obj != null; cls = obj.getClass(); @@ -218,11 +228,11 @@ public class PortableWriterExImpl implements PortableWriter, PortableRawWriterEx return; } - if (desc.getWriteReplaceMethod() != null) { - Object replace; + if (enableReplace && desc.getWriteReplaceMethod() != null) { + Object replacedObj; try { - replace = desc.getWriteReplaceMethod().invoke(obj); + replacedObj = desc.getWriteReplaceMethod().invoke(obj); } catch (IllegalAccessException e) { throw new RuntimeException(e); @@ -234,21 +244,14 @@ public class PortableWriterExImpl implements PortableWriter, PortableRawWriterEx throw new PortableException("Failed to execute writeReplace() method on " + obj, e); } - if (replace == null) { + if (replacedObj == null) { doWriteByte(NULL); return; } - if (cls != replace.getClass()) { - cls = replace.getClass(); - - desc = ctx.descriptorForClass(cls); - - if (desc == null) - throw new PortableException("Object is not portable: [class=" + cls + ']'); - } + marshal(replacedObj, detached, false); - obj = replace; + return; } typeId = desc.typeId(); @@ -301,7 +304,7 @@ public class PortableWriterExImpl implements PortableWriter, PortableRawWriterEx wCtx.out.position(pos); } - /** + /** * @param bytes Number of bytes to reserve. * @return Offset. */ @@ -1740,7 +1743,7 @@ public class PortableWriterExImpl implements PortableWriter, PortableRawWriterEx return reserve(LEN_INT); } - /** {@inheritDoc} */ + /** {@inheritDoc} */ @Override public void writeInt(int pos, int val) throws PortableException { wCtx.out.writeInt(pos, val); } @@ -1764,27 +1767,28 @@ public class PortableWriterExImpl implements PortableWriter, PortableRawWriterEx doWriteInt(id); } - /** - * Attempts to write the object as a handle. - * - * @param obj Object to write. - * @return {@code true} if the object has been written as a handle. - */ - boolean tryWriteAsHandle(Object obj) { - int handle = handle(obj); + /** + * Attempts to write the object as a handle. + * + * @param obj Object to write. + * @return {@code true} if the object has been written as a handle. + */ + boolean tryWriteAsHandle(Object obj) { + int handle = handle(obj); - if (handle >= 0) { - doWriteByte(GridPortableMarshaller.HANDLE); - doWriteInt(handle); + if (handle >= 0) { + doWriteByte(GridPortableMarshaller.HANDLE); + doWriteInt(handle); - return true; - } + return true; + } - return false; - } + return false; + } /** * Create new writer with same context. + * * @param typeId type * @return New writer. */