deltaspike-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From strub...@apache.org
Subject git commit: DELTASPIKE-354 prevent NPE when passing null to a @MessageBundle
Date Sat, 11 May 2013 10:21:40 GMT
Updated Branches:
  refs/heads/master d3d26f8de -> b43b71208


DELTASPIKE-354 prevent NPE when passing null to a @MessageBundle


Project: http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/commit/b43b7120
Tree: http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/tree/b43b7120
Diff: http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/diff/b43b7120

Branch: refs/heads/master
Commit: b43b71208e28d02ec1f07b4761195d66ba4337e8
Parents: d3d26f8
Author: Mark Struberg <struberg@apache.org>
Authored: Sat May 11 12:07:41 2013 +0200
Committer: Mark Struberg <struberg@apache.org>
Committed: Sat May 11 12:21:06 2013 +0200

----------------------------------------------------------------------
 .../message/MessageBundleInvocationHandler.java    |   10 +++++++---
 .../test/core/api/message/SimpleMessageTest.java   |    8 ++++++++
 2 files changed, 15 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/b43b7120/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/message/MessageBundleInvocationHandler.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/message/MessageBundleInvocationHandler.java
b/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/message/MessageBundleInvocationHandler.java
index 3bb99f7..ae84341 100644
--- a/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/message/MessageBundleInvocationHandler.java
+++ b/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/message/MessageBundleInvocationHandler.java
@@ -138,12 +138,16 @@ public class MessageBundleInvocationHandler implements InvocationHandler,
Serial
             {
                 Object arg = args[i];
 
-                if (i == 0 && MessageContext.class.isAssignableFrom(args[0].getClass()))
+                if (i == 0 && arg != null && MessageContext.class.isAssignableFrom(arg.getClass()))
                 {
                     continue;
                 }
 
-                if (arg instanceof Serializable)
+                if (arg == null)
+                {
+                    arguments.add("'null'");
+                }
+                else if (arg instanceof Serializable)
                 {
                     arguments.add((Serializable) arg);
                 }
@@ -160,7 +164,7 @@ public class MessageBundleInvocationHandler implements InvocationHandler,
Serial
 
     private MessageContext resolveMessageContextFromArguments(Object[] args)
     {
-        if (args != null && args.length > 0 &&
+        if (args != null && args.length > 0 &&  args[0] != null &&
             MessageContext.class.isAssignableFrom(args[0].getClass()))
         {
             return (MessageContext) args[0];

http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/b43b7120/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/api/message/SimpleMessageTest.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/api/message/SimpleMessageTest.java
b/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/api/message/SimpleMessageTest.java
index ebebbd7..e7767e3 100644
--- a/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/api/message/SimpleMessageTest.java
+++ b/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/api/message/SimpleMessageTest.java
@@ -91,4 +91,12 @@ public class SimpleMessageTest
         String result = simpleMessage.welcomeWithFloatVariable(f);
         assertEquals(expectedResult, result);
     }
+
+    @Test
+    public void testNullMessage()
+    {
+        String expectedResult = "Welcome to 'null'";
+        String result = simpleMessage.welcomeWithStringVariable(null);
+        assertEquals(expectedResult, result);
+    }
 }


Mime
View raw message