flume-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From br...@apache.org
Subject git commit: FLUME-1622: MemoryChannel throws NPE if the event has no body
Date Thu, 18 Oct 2012 16:40:12 GMT
Updated Branches:
  refs/heads/flume-1.4 218f2400c -> 7157802eb


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/7157802e
Tree: http://git-wip-us.apache.org/repos/asf/flume/tree/7157802e
Diff: http://git-wip-us.apache.org/repos/asf/flume/diff/7157802e

Branch: refs/heads/flume-1.4
Commit: 7157802eb86f83f9b9467827b6cc6d7387cc21bb
Parents: 218f240
Author: Brock Noland <brock@apache.org>
Authored: Thu Oct 18 11:37:57 2012 -0500
Committer: Brock Noland <brock@apache.org>
Committed: Thu Oct 18 11:39:30 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/7157802e/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/7157802e/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<String, String> parms = new HashMap<String, String>();
+    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();
+
+
+  }
 }


Mime
View raw message