From eee38f618c275c2deab96a4f18590c69e959fd30 Mon Sep 17 00:00:00 2001 From: Knut Wannheden Date: Thu, 4 Jul 2019 20:37:49 +0200 Subject: [PATCH] [jOOQ/jOOQ#8900] Extract MiniJAXB common exception handling logic `marshal()` and `unmarshal()` now share the same exception handling. --- .../src/main/java/org/jooq/conf/MiniJAXB.java | 46 ++++++++----------- 1 file changed, 20 insertions(+), 26 deletions(-) diff --git a/jOOQ/src/main/java/org/jooq/conf/MiniJAXB.java b/jOOQ/src/main/java/org/jooq/conf/MiniJAXB.java index 7cbab2b703..93775b4a09 100644 --- a/jOOQ/src/main/java/org/jooq/conf/MiniJAXB.java +++ b/jOOQ/src/main/java/org/jooq/conf/MiniJAXB.java @@ -113,19 +113,7 @@ public class MiniJAXB { return; } catch (Throwable t) { - if (t instanceof Error) { - ExceptionTools.sneakyThrow(t); - } - else if (ExceptionTools.getCause(t, ClassNotFoundException.class) != null || - ExceptionTools.getCause(t, Error.class) != null) { - jaxbAvailable = false; - log.debug("JAXB is not available from the classpath / module path"); - } - else { - jaxbAvailable = true; - log.debug("JAXB is available from the classpath / module path"); - throw new ConfigurationException("Error while reading xml", t); - } + handleJaxbException(t); } } @@ -144,6 +132,24 @@ public class MiniJAXB { } } + private static void handleJaxbException(Throwable t) { + if (t instanceof Error) { + jaxbAvailable = true; + log.debug("JAXB is available from the classpath / module path"); + ExceptionTools.sneakyThrow(t); + } + else if (ExceptionTools.getCause(t, ClassNotFoundException.class) != null || + ExceptionTools.getCause(t, Error.class) != null) { + jaxbAvailable = false; + log.debug("JAXB is not available from the classpath / module path"); + } + else { + jaxbAvailable = true; + log.debug("JAXB is available from the classpath / module path"); + throw new ConfigurationException("Error while reading xml", t); + } + } + public static T unmarshal(InputStream in, Class type) { return unmarshal0(new InputSource(in), type); } @@ -174,19 +180,7 @@ public class MiniJAXB { return result; } catch (Throwable t) { - if (t instanceof Error) { - ExceptionTools.sneakyThrow(t); - } - if (ExceptionTools.getCause(t, ClassNotFoundException.class) != null || - ExceptionTools.getCause(t, Error.class) != null) { - jaxbAvailable = false; - log.debug("JAXB is not available from the classpath / module path"); - } - else { - jaxbAvailable = true; - log.debug("JAXB is available from the classpath / module path"); - throw new ConfigurationException("Error while reading xml", t); - } + handleJaxbException(t); } }