Return-Path: X-Original-To: apmail-flume-commits-archive@www.apache.org Delivered-To: apmail-flume-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 6A486D041 for ; Thu, 18 Oct 2012 16:40:26 +0000 (UTC) Received: (qmail 37550 invoked by uid 500); 18 Oct 2012 16:40:26 -0000 Delivered-To: apmail-flume-commits-archive@flume.apache.org Received: (qmail 37506 invoked by uid 500); 18 Oct 2012 16:40:25 -0000 Mailing-List: contact commits-help@flume.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@flume.apache.org Delivered-To: mailing list commits@flume.apache.org Received: (qmail 37492 invoked by uid 99); 18 Oct 2012 16:40:25 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 18 Oct 2012 16:40:25 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 25C319861; Thu, 18 Oct 2012 16:40:25 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: brock@apache.org To: commits@flume.apache.org X-Mailer: ASF-Git Admin Mailer Subject: git commit: FLUME-1622: MemoryChannel throws NPE if the event has no body Message-Id: <20121018164025.25C319861@tyr.zones.apache.org> Date: Thu, 18 Oct 2012 16:40:25 +0000 (UTC) Updated Branches: refs/heads/trunk bad9e9ab8 -> 250c45790 FLUME-1622: MemoryChannel throws NPE if the event has no body (Hari Shreedharan via Brock Noland) Project: http://git-wip-us.apache.org/repos/asf/flume/repo Commit: http://git-wip-us.apache.org/repos/asf/flume/commit/250c4579 Tree: http://git-wip-us.apache.org/repos/asf/flume/tree/250c4579 Diff: http://git-wip-us.apache.org/repos/asf/flume/diff/250c4579 Branch: refs/heads/trunk Commit: 250c4579033b36f2ea2e66a581e1c0834c627732 Parents: bad9e9a Author: Brock Noland Authored: Thu Oct 18 11:37:57 2012 -0500 Committer: Brock Noland Committed: Thu Oct 18 11:37:57 2012 -0500 ---------------------------------------------------------------------- .../org/apache/flume/channel/MemoryChannel.java | 7 +++- .../apache/flume/channel/TestMemoryChannel.java | 28 +++++++++++++++ 2 files changed, 34 insertions(+), 1 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/flume/blob/250c4579/flume-ng-core/src/main/java/org/apache/flume/channel/MemoryChannel.java ---------------------------------------------------------------------- diff --git a/flume-ng-core/src/main/java/org/apache/flume/channel/MemoryChannel.java b/flume-ng-core/src/main/java/org/apache/flume/channel/MemoryChannel.java index a656c8b..06c90d9 100644 --- a/flume-ng-core/src/main/java/org/apache/flume/channel/MemoryChannel.java +++ b/flume-ng-core/src/main/java/org/apache/flume/channel/MemoryChannel.java @@ -330,6 +330,11 @@ public class MemoryChannel extends BasicChannelSemantics { private long estimateEventSize(Event event) { - return event.getBody().length; + byte[] body = event.getBody(); + if(body != null && body.length != 0) { + return body.length; + } + //Each event occupies at least 1 slot, so return 1. + return 1; } } http://git-wip-us.apache.org/repos/asf/flume/blob/250c4579/flume-ng-core/src/test/java/org/apache/flume/channel/TestMemoryChannel.java ---------------------------------------------------------------------- diff --git a/flume-ng-core/src/test/java/org/apache/flume/channel/TestMemoryChannel.java b/flume-ng-core/src/test/java/org/apache/flume/channel/TestMemoryChannel.java index 4af4a40..e1a61c2 100644 --- a/flume-ng-core/src/test/java/org/apache/flume/channel/TestMemoryChannel.java +++ b/flume-ng-core/src/test/java/org/apache/flume/channel/TestMemoryChannel.java @@ -411,4 +411,32 @@ public class TestMemoryChannel { //success } } + + /* + * This would cause a NPE without FLUME-1622. + */ + @Test + public void testNullEmptyEvent() { + Context context = new Context(); + Map parms = new HashMap(); + parms.put("byteCapacity", "2000"); + parms.put("byteCapacityBufferPercentage", "20"); + context.putAll(parms); + Configurables.configure(channel, context); + + Transaction tx = channel.getTransaction(); + tx.begin(); + //This line would cause a NPE without FLUME-1622. + channel.put(EventBuilder.withBody(null)); + tx.commit(); + tx.close(); + + tx = channel.getTransaction(); + tx.begin(); + channel.put(EventBuilder.withBody(new byte[0])); + tx.commit(); + tx.close(); + + + } }