diff --git a/scm-dao-xml/src/main/java/sonia/scm/store/TypedStoreContext.java b/scm-dao-xml/src/main/java/sonia/scm/store/TypedStoreContext.java index 2664444e55..b5627c1b06 100644 --- a/scm-dao-xml/src/main/java/sonia/scm/store/TypedStoreContext.java +++ b/scm-dao-xml/src/main/java/sonia/scm/store/TypedStoreContext.java @@ -67,25 +67,15 @@ final class TypedStoreContext { void withMarshaller(ThrowingConsumer consumer) { Marshaller marshaller = createMarshaller(); - ClassLoader contextClassLoader = null; - Optional classLoader = parameters.getClassLoader(); - if (classLoader.isPresent()) { - contextClassLoader = Thread.currentThread().getContextClassLoader(); - Thread.currentThread().setContextClassLoader(classLoader.get()); - } - try { - consumer.consume(marshaller); - } catch (Exception e) { - throw new StoreException("failure during work with marshaller", e); - } finally { - if (contextClassLoader != null) { - Thread.currentThread().setContextClassLoader(contextClassLoader); - } - } + withClassLoader(consumer, marshaller); } void withUnmarshaller(ThrowingConsumer consumer) { Unmarshaller unmarshaller = createUnmarshaller(); + withClassLoader(consumer, unmarshaller); + } + + private void withClassLoader(ThrowingConsumer consumer, C consume) { ClassLoader contextClassLoader = null; Optional classLoader = parameters.getClassLoader(); if (classLoader.isPresent()) { @@ -93,9 +83,9 @@ final class TypedStoreContext { Thread.currentThread().setContextClassLoader(classLoader.get()); } try { - consumer.consume(unmarshaller); + consumer.consume(consume); } catch (Exception e) { - throw new StoreException("failure during work with unmarshaller", e); + throw new StoreException("failure during marshalling/unmarshalling", e); } finally { if (contextClassLoader != null) { Thread.currentThread().setContextClassLoader(contextClassLoader);