mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-15 09:46:16 +01:00
fix duplicate ClassLoader logic
This commit is contained in:
@@ -67,25 +67,15 @@ final class TypedStoreContext<T> {
|
|||||||
|
|
||||||
void withMarshaller(ThrowingConsumer<Marshaller> consumer) {
|
void withMarshaller(ThrowingConsumer<Marshaller> consumer) {
|
||||||
Marshaller marshaller = createMarshaller();
|
Marshaller marshaller = createMarshaller();
|
||||||
ClassLoader contextClassLoader = null;
|
withClassLoader(consumer, marshaller);
|
||||||
Optional<ClassLoader> 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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void withUnmarshaller(ThrowingConsumer<Unmarshaller> consumer) {
|
void withUnmarshaller(ThrowingConsumer<Unmarshaller> consumer) {
|
||||||
Unmarshaller unmarshaller = createUnmarshaller();
|
Unmarshaller unmarshaller = createUnmarshaller();
|
||||||
|
withClassLoader(consumer, unmarshaller);
|
||||||
|
}
|
||||||
|
|
||||||
|
private <C> void withClassLoader(ThrowingConsumer<C> consumer, C consume) {
|
||||||
ClassLoader contextClassLoader = null;
|
ClassLoader contextClassLoader = null;
|
||||||
Optional<ClassLoader> classLoader = parameters.getClassLoader();
|
Optional<ClassLoader> classLoader = parameters.getClassLoader();
|
||||||
if (classLoader.isPresent()) {
|
if (classLoader.isPresent()) {
|
||||||
@@ -93,9 +83,9 @@ final class TypedStoreContext<T> {
|
|||||||
Thread.currentThread().setContextClassLoader(classLoader.get());
|
Thread.currentThread().setContextClassLoader(classLoader.get());
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
consumer.consume(unmarshaller);
|
consumer.consume(consume);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new StoreException("failure during work with unmarshaller", e);
|
throw new StoreException("failure during marshalling/unmarshalling", e);
|
||||||
} finally {
|
} finally {
|
||||||
if (contextClassLoader != null) {
|
if (contextClassLoader != null) {
|
||||||
Thread.currentThread().setContextClassLoader(contextClassLoader);
|
Thread.currentThread().setContextClassLoader(contextClassLoader);
|
||||||
|
|||||||
Reference in New Issue
Block a user