flume-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bes...@apache.org
Subject flume git commit: FLUME-2966. Fix NPE in JMS Source
Date Mon, 26 Sep 2016 13:58:26 GMT
Repository: flume
Updated Branches:
  refs/heads/trunk d9c9a7dd9 -> 591b13832


FLUME-2966. Fix NPE in JMS Source

JMS Source does not check for null text in a TextMessage. This can lead to NullPointerException.
This commit fixes that problem by checking for nullity of textMessage.getText().

Reviewers: Denes Arvay, Attila Simon, Mike Percy, Bessenyei Balázs Donát

(Siddharth Ahuja via Bessenyei Balázs Donát)


Project: http://git-wip-us.apache.org/repos/asf/flume/repo
Commit: http://git-wip-us.apache.org/repos/asf/flume/commit/591b1383
Tree: http://git-wip-us.apache.org/repos/asf/flume/tree/591b1383
Diff: http://git-wip-us.apache.org/repos/asf/flume/diff/591b1383

Branch: refs/heads/trunk
Commit: 591b138321280cea1e7d61efcaf625a67202cb3d
Parents: d9c9a7d
Author: Siddharth Ahuja <sahuja@cloudera.com>
Authored: Mon Sep 26 15:50:51 2016 +0200
Committer: Bessenyei Balázs Donát <bessbd@apache.org>
Committed: Mon Sep 26 15:52:57 2016 +0200

----------------------------------------------------------------------
 .../source/jms/DefaultJMSMessageConverter.java  |  5 ++++-
 .../jms/TestDefaultJMSMessageConverter.java     | 21 ++++++++++++++++++++
 2 files changed, 25 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flume/blob/591b1383/flume-ng-sources/flume-jms-source/src/main/java/org/apache/flume/source/jms/DefaultJMSMessageConverter.java
----------------------------------------------------------------------
diff --git a/flume-ng-sources/flume-jms-source/src/main/java/org/apache/flume/source/jms/DefaultJMSMessageConverter.java
b/flume-ng-sources/flume-jms-source/src/main/java/org/apache/flume/source/jms/DefaultJMSMessageConverter.java
index acb5118..003f591 100644
--- a/flume-ng-sources/flume-jms-source/src/main/java/org/apache/flume/source/jms/DefaultJMSMessageConverter.java
+++ b/flume-ng-sources/flume-jms-source/src/main/java/org/apache/flume/source/jms/DefaultJMSMessageConverter.java
@@ -100,7 +100,10 @@ public class DefaultJMSMessageConverter implements JMSMessageConverter
{
       }
     } else if (message instanceof TextMessage) {
       TextMessage textMessage = (TextMessage)message;
-      event.setBody(textMessage.getText().getBytes(charset));
+      String text = textMessage.getText();
+      if (text != null) {
+        event.setBody(text.getBytes(charset));
+      }
     } else if (message instanceof ObjectMessage) {
       ObjectMessage objectMessage = (ObjectMessage)message;
       Object object = objectMessage.getObject();

http://git-wip-us.apache.org/repos/asf/flume/blob/591b1383/flume-ng-sources/flume-jms-source/src/test/java/org/apache/flume/source/jms/TestDefaultJMSMessageConverter.java
----------------------------------------------------------------------
diff --git a/flume-ng-sources/flume-jms-source/src/test/java/org/apache/flume/source/jms/TestDefaultJMSMessageConverter.java
b/flume-ng-sources/flume-jms-source/src/test/java/org/apache/flume/source/jms/TestDefaultJMSMessageConverter.java
index 0b2193c..f0e46ca 100644
--- a/flume-ng-sources/flume-jms-source/src/test/java/org/apache/flume/source/jms/TestDefaultJMSMessageConverter.java
+++ b/flume-ng-sources/flume-jms-source/src/test/java/org/apache/flume/source/jms/TestDefaultJMSMessageConverter.java
@@ -66,6 +66,13 @@ public class TestDefaultJMSMessageConverter {
     when(message.getText()).thenReturn(TEXT);
     this.message = message;
   }
+
+  void createNullTextMessage() throws Exception {
+    TextMessage message = mock(TextMessage.class);
+    when(message.getText()).thenReturn(null);
+    this.message = message;
+  }
+
   void createBytesMessage() throws Exception {
     BytesMessage message = mock(BytesMessage.class);
     when(message.getBodyLength()).thenReturn((long)BYTES.length);
@@ -117,6 +124,20 @@ public class TestDefaultJMSMessageConverter {
     assertEquals(headers, event.getHeaders());
     assertEquals(TEXT, new String(event.getBody(), Charsets.UTF_8));
   }
+
+  @Test
+  public void testNullTextMessage() throws Exception {
+    createNullTextMessage();
+    headers.put("key1", "value1");
+    headers.put("key2", "value2");
+    createHeaders();
+    Event event = converter.convert(message).iterator().next();
+    assertEquals(headers, event.getHeaders());
+    // In case of a null text message, the event's body will be empty due to
+    // SimpleEvent's body not updated with a valid text message.
+    assertEquals(event.getBody().length, 0);
+  }
+
   @Test
   public void testBytesMessage() throws Exception {
     createBytesMessage();


Mime
View raw message