You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cayenne.apache.org by nt...@apache.org on 2018/05/23 07:14:49 UTC

cayenne git commit: CAY-2436 NPE in CayenneRuntimeException constructor

Repository: cayenne
Updated Branches:
  refs/heads/STABLE-4.0 8a2b5a88c -> 4944e863d


CAY-2436 NPE in CayenneRuntimeException constructor


Project: http://git-wip-us.apache.org/repos/asf/cayenne/repo
Commit: http://git-wip-us.apache.org/repos/asf/cayenne/commit/4944e863
Tree: http://git-wip-us.apache.org/repos/asf/cayenne/tree/4944e863
Diff: http://git-wip-us.apache.org/repos/asf/cayenne/diff/4944e863

Branch: refs/heads/STABLE-4.0
Commit: 4944e863d6d31e2d96a592c4cf4fefbb2a2c1b1e
Parents: 8a2b5a8
Author: Nikita Timofeev <st...@gmail.com>
Authored: Wed May 23 10:14:23 2018 +0300
Committer: Nikita Timofeev <st...@gmail.com>
Committed: Wed May 23 10:14:23 2018 +0300

----------------------------------------------------------------------
 RELEASE-NOTES.txt                               |  4 ++-
 .../apache/cayenne/CayenneRuntimeException.java |  7 ++---
 .../cayenne/CayenneRuntimeExceptionTest.java    | 33 ++++++++++++++------
 3 files changed, 29 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cayenne/blob/4944e863/RELEASE-NOTES.txt
----------------------------------------------------------------------
diff --git a/RELEASE-NOTES.txt b/RELEASE-NOTES.txt
index 828731c..c09f88b 100644
--- a/RELEASE-NOTES.txt
+++ b/RELEASE-NOTES.txt
@@ -16,9 +16,11 @@ Changes/New Features:
 
 Bug Fixes:
 
+CAY-2436 NPE in CayenneRuntimeException constructor
+
 ----------------------------------
 Release: 4.0.RC1
-Date:
+Date: April 25, 2018
 ----------------------------------
 
 Changes/New Features:

http://git-wip-us.apache.org/repos/asf/cayenne/blob/4944e863/cayenne-server/src/main/java/org/apache/cayenne/CayenneRuntimeException.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/main/java/org/apache/cayenne/CayenneRuntimeException.java b/cayenne-server/src/main/java/org/apache/cayenne/CayenneRuntimeException.java
index 29fc6c0..135b50c 100644
--- a/cayenne-server/src/main/java/org/apache/cayenne/CayenneRuntimeException.java
+++ b/cayenne-server/src/main/java/org/apache/cayenne/CayenneRuntimeException.java
@@ -37,7 +37,7 @@ public class CayenneRuntimeException extends RuntimeException {
      * conventions.
      */
     public CayenneRuntimeException(String messageFormat, Object... messageArgs) {
-        super(String.format(messageFormat, messageArgs));
+        super(messageFormat == null ? null : String.format(messageFormat, messageArgs));
     }
 
     /**
@@ -53,9 +53,8 @@ public class CayenneRuntimeException extends RuntimeException {
      * optional list of message formatting arguments. Message formatting rules follow
      * "String.format(..)" conventions.
      */
-    public CayenneRuntimeException(String messageFormat, Throwable cause,
-            Object... messageArgs) {
-        super(String.format(messageFormat, messageArgs), cause);
+    public CayenneRuntimeException(String messageFormat, Throwable cause, Object... messageArgs) {
+        super(messageFormat == null ? null : String.format(messageFormat, messageArgs), cause);
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/cayenne/blob/4944e863/cayenne-server/src/test/java/org/apache/cayenne/CayenneRuntimeExceptionTest.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/CayenneRuntimeExceptionTest.java b/cayenne-server/src/test/java/org/apache/cayenne/CayenneRuntimeExceptionTest.java
index d9019c2..0e60ecf 100644
--- a/cayenne-server/src/test/java/org/apache/cayenne/CayenneRuntimeExceptionTest.java
+++ b/cayenne-server/src/test/java/org/apache/cayenne/CayenneRuntimeExceptionTest.java
@@ -29,26 +29,24 @@ import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertSame;
 import static org.junit.Assert.assertTrue;
 
-/**
- */
 public class CayenneRuntimeExceptionTest {
 
     @Test
-    public void testConstructor1() throws Exception {
+    public void testConstructor1() {
         CayenneRuntimeException ex = new CayenneRuntimeException();
         assertNull(ex.getCause());
         assertTrue(ex.getMessage().startsWith(CayenneException.getExceptionLabel()));
     }
 
     @Test
-    public void testConstructor2() throws Exception {
+    public void testConstructor2() {
         CayenneRuntimeException ex = new CayenneRuntimeException("abc");
         assertNull(ex.getCause());
         assertEquals(CayenneException.getExceptionLabel() + "abc", ex.getMessage());
     }
 
     @Test
-    public void testConstructor3() throws Exception {
+    public void testConstructor3() {
         Throwable cause = new Throwable();
         CayenneRuntimeException ex = new CayenneRuntimeException(cause);
         assertSame(cause, ex.getCause());
@@ -58,7 +56,7 @@ public class CayenneRuntimeExceptionTest {
     }
 
     @Test
-    public void testConstructor4() throws Exception {
+    public void testConstructor4() {
         Throwable cause = new Throwable();
         CayenneRuntimeException ex = new CayenneRuntimeException("abc", cause);
         assertSame(cause, ex.getCause());
@@ -66,7 +64,22 @@ public class CayenneRuntimeExceptionTest {
     }
 
     @Test
-    public void testThrow1() throws Exception {
+    public void testConstructorNullMessage() {
+        Throwable cause = new Throwable();
+
+        CayenneRuntimeException ex = new CayenneRuntimeException(null, cause);
+        assertSame(cause, ex.getCause());
+        assertEquals(CayenneException.getExceptionLabel() + "(no message)", ex.getMessage());
+        assertNull(ex.getUnlabeledMessage());
+
+        CayenneRuntimeException ex2 = new CayenneRuntimeException((String)null);
+        assertNull(ex2.getCause());
+        assertEquals(CayenneException.getExceptionLabel() + "(no message)", ex2.getMessage());
+        assertNull(ex2.getUnlabeledMessage());
+    }
+
+    @Test
+    public void testThrow1() {
         try {
             throw new CayenneRuntimeException();
         }
@@ -77,7 +90,7 @@ public class CayenneRuntimeExceptionTest {
     }
 
     @Test
-    public void testThrow2() throws Exception {
+    public void testThrow2() {
         try {
             try {
                 throw new Throwable("Test Cause");
@@ -93,13 +106,13 @@ public class CayenneRuntimeExceptionTest {
     }
 
     @Test
-    public void testMessageFormatting1() throws Exception {
+    public void testMessageFormatting1() {
         CayenneRuntimeException ex = new CayenneRuntimeException("x%sx%sx", "a", "b");
         assertEquals("xaxbx", ex.getUnlabeledMessage());
     }
 
     @Test
-    public void testMessageFormatting2() throws Exception {
+    public void testMessageFormatting2() {
         Throwable cause = new Throwable();
         CayenneRuntimeException ex = new CayenneRuntimeException("x%sx%sx", cause, "a", "b");
         assertEquals("xaxbx", ex.getUnlabeledMessage());