Repository: cayenne Updated Branches: refs/heads/master 57361b635 -> 26dc6a268
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/872f231a Tree: http://git-wip-us.apache.org/repos/asf/cayenne/tree/872f231a Diff: http://git-wip-us.apache.org/repos/asf/cayenne/diff/872f231a Branch: refs/heads/master Commit: 872f231a1984033771867628b1e4f660dfec2b28 Parents: 57361b6 Author: Nikita Timofeev <stari...@gmail.com> Authored: Wed May 23 10:14:23 2018 +0300 Committer: Nikita Timofeev <stari...@gmail.com> Committed: Wed May 23 10:17:32 2018 +0300 ---------------------------------------------------------------------- RELEASE-NOTES.txt | 1 + .../apache/cayenne/CayenneRuntimeException.java | 2 +- .../cayenne/CayenneRuntimeExceptionTest.java | 33 ++++++++++++++------ 3 files changed, 25 insertions(+), 11 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cayenne/blob/872f231a/RELEASE-NOTES.txt ---------------------------------------------------------------------- diff --git a/RELEASE-NOTES.txt b/RELEASE-NOTES.txt index 1df3b48..3806615 100644 --- a/RELEASE-NOTES.txt +++ b/RELEASE-NOTES.txt @@ -59,6 +59,7 @@ CAY-2425 Modeler: Migrate DB Direction field is locked if no option was selected CAY-2427 Modeler: Undo throws exception CAY-2429 Generate classes: Invalid template type: EMBEDDABLE_SINGLE_CLASS CAY-2430 Modeler: Redo throws NPE +CAY-2436 NPE in CayenneRuntimeException constructor ---------------------------------- Release: 4.1.M1 http://git-wip-us.apache.org/repos/asf/cayenne/blob/872f231a/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 bb922bc..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)); } /** http://git-wip-us.apache.org/repos/asf/cayenne/blob/872f231a/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());