From dd4b13dd502130376408cc65b8a8cfa64e687967 Mon Sep 17 00:00:00 2001 From: Mark Raynsford Date: Sun, 22 Dec 2019 12:06:48 +0000 Subject: [PATCH 1/2] Avoid a null pointer exception if an exception lacks a message --- com.io7m.blackthorne.api/pom.xml | 2 +- .../io7m/blackthorne/api/BTContentHandler.java | 18 +++++++++++++++--- com.io7m.blackthorne.tests/pom.xml | 2 +- pom.xml | 2 +- 4 files changed, 18 insertions(+), 6 deletions(-) diff --git a/com.io7m.blackthorne.api/pom.xml b/com.io7m.blackthorne.api/pom.xml index bb0055a..aef871c 100644 --- a/com.io7m.blackthorne.api/pom.xml +++ b/com.io7m.blackthorne.api/pom.xml @@ -8,7 +8,7 @@ com.io7m.blackthorne com.io7m.blackthorne - 0.0.4 + 0.0.5-SNAPSHOT com.io7m.blackthorne.api diff --git a/com.io7m.blackthorne.api/src/main/java/com/io7m/blackthorne/api/BTContentHandler.java b/com.io7m.blackthorne.api/src/main/java/com/io7m/blackthorne/api/BTContentHandler.java index 882cef8..fcb99f5 100644 --- a/com.io7m.blackthorne.api/src/main/java/com/io7m/blackthorne/api/BTContentHandler.java +++ b/com.io7m.blackthorne.api/src/main/java/com/io7m/blackthorne/api/BTContentHandler.java @@ -154,7 +154,7 @@ public void warning( BTParseError.builder() .setException(e) .setSeverity(BTParseErrorType.Severity.WARNING) - .setMessage(e.getMessage()) + .setMessage(messageOrException(e)) .setLexical(this.currentLexical()) .build()); } @@ -168,7 +168,7 @@ public void error( BTParseError.builder() .setException(e) .setSeverity(BTParseErrorType.Severity.ERROR) - .setMessage(e.getMessage()) + .setMessage(messageOrException(e)) .setLexical(this.currentLexical()) .build()); } @@ -183,12 +183,24 @@ public void fatalError( BTParseError.builder() .setException(e) .setSeverity(BTParseErrorType.Severity.ERROR) - .setMessage(e.getMessage()) + .setMessage(messageOrException(e)) .setLexical(this.currentLexical()) .build()); throw e; } + private static String messageOrException( + final Exception e) + { + final var messageOrNull = e.getMessage(); + if (messageOrNull == null) { + return String.format( + "No error message provided for exception %s", + e.getClass().getName()); + } + return messageOrNull; + } + private LexicalPosition currentLexical() { final LexicalPosition lexicalPosition; diff --git a/com.io7m.blackthorne.tests/pom.xml b/com.io7m.blackthorne.tests/pom.xml index 8452e7c..d79cbd8 100644 --- a/com.io7m.blackthorne.tests/pom.xml +++ b/com.io7m.blackthorne.tests/pom.xml @@ -8,7 +8,7 @@ com.io7m.blackthorne com.io7m.blackthorne - 0.0.4 + 0.0.5-SNAPSHOT com.io7m.blackthorne.tests diff --git a/pom.xml b/pom.xml index ed8ef09..6a9d0f1 100644 --- a/pom.xml +++ b/pom.xml @@ -13,7 +13,7 @@ com.io7m.blackthorne com.io7m.blackthorne - 0.0.4 + 0.0.5-SNAPSHOT pom com.io7m.blackthorne From c53df6fe1145dff8a88e8ca4fd30ad2cdf50f879 Mon Sep 17 00:00:00 2001 From: Mark Raynsford Date: Sun, 22 Dec 2019 12:35:49 +0000 Subject: [PATCH 2/2] Mark 0.0.5 --- com.io7m.blackthorne.api/pom.xml | 2 +- com.io7m.blackthorne.tests/pom.xml | 2 +- pom.xml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/com.io7m.blackthorne.api/pom.xml b/com.io7m.blackthorne.api/pom.xml index aef871c..5500a73 100644 --- a/com.io7m.blackthorne.api/pom.xml +++ b/com.io7m.blackthorne.api/pom.xml @@ -8,7 +8,7 @@ com.io7m.blackthorne com.io7m.blackthorne - 0.0.5-SNAPSHOT + 0.0.5 com.io7m.blackthorne.api diff --git a/com.io7m.blackthorne.tests/pom.xml b/com.io7m.blackthorne.tests/pom.xml index d79cbd8..800706d 100644 --- a/com.io7m.blackthorne.tests/pom.xml +++ b/com.io7m.blackthorne.tests/pom.xml @@ -8,7 +8,7 @@ com.io7m.blackthorne com.io7m.blackthorne - 0.0.5-SNAPSHOT + 0.0.5 com.io7m.blackthorne.tests diff --git a/pom.xml b/pom.xml index 6a9d0f1..e39954f 100644 --- a/pom.xml +++ b/pom.xml @@ -13,7 +13,7 @@ com.io7m.blackthorne com.io7m.blackthorne - 0.0.5-SNAPSHOT + 0.0.5 pom com.io7m.blackthorne