This is an automated email from the ASF dual-hosted git repository. andy pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/jena.git
commit ceb45c7895ec77a2414fbba9b2852c01d9c816d4 Author: Andy Seaborne <[email protected]> AuthorDate: Wed Apr 24 21:54:21 2024 +0100 Common place to turn checked exceptions into unchecked exceptions --- jena-base/src/main/java/org/apache/jena/atlas/io/IOX.java | 3 +-- jena-base/src/main/java/org/apache/jena/atlas/lib/Lib.java | 12 ++++++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/jena-base/src/main/java/org/apache/jena/atlas/io/IOX.java b/jena-base/src/main/java/org/apache/jena/atlas/io/IOX.java index a25fe6bf0c..ed78dbbb92 100644 --- a/jena-base/src/main/java/org/apache/jena/atlas/io/IOX.java +++ b/jena-base/src/main/java/org/apache/jena/atlas/io/IOX.java @@ -39,11 +39,11 @@ public class IOX { void actionEx(X arg) throws IOException; } + // Maybe change to java.io.UncheckedIOException /** * Convert an {@link IOException} into a {@link RuntimeIOException}. * <p> * Idiom: - * * <pre> * catch(IOException ex) { throw new exception(ex); } * </pre> @@ -59,7 +59,6 @@ public class IOX { * Convert an {@link IOException} into a {@link RuntimeIOException}. * <p> * Idiom: - * * <pre> * catch(IOException ex) { throw new exception("Oh dear", ex); } * </pre> diff --git a/jena-base/src/main/java/org/apache/jena/atlas/lib/Lib.java b/jena-base/src/main/java/org/apache/jena/atlas/lib/Lib.java index e77ab46c92..bbc2b43b1a 100644 --- a/jena-base/src/main/java/org/apache/jena/atlas/lib/Lib.java +++ b/jena-base/src/main/java/org/apache/jena/atlas/lib/Lib.java @@ -110,6 +110,18 @@ public class Lib return new UnsupportedOperationException(Lib.className(object) + "." + method); } + /** + * Return a {@linkplain RuntimeException}. If the argument is already + * {@code RuntimeException}, return the argument. Otherwise, wrap in + * {@code RuntimeException}, with the same message, and return the + * {@code RuntimeException} + */ + public static RuntimeException runtimeException(Exception ex) { + if ( ex instanceof RuntimeException ex2) + throw ex2; + return new RuntimeException(ex.getMessage(), ex); + } + /** Do two lists have the same elements without considering the order of the lists nor duplicates? */ public static <T> boolean equalsListAsSet(List<T> list1, List<T> list2) { if ( list1 == null && list2 == null )
