Skip to content

Commit

Permalink
[JENKINS-68509] Specify class loader context to use JAXBContext
Browse files Browse the repository at this point in the history
  • Loading branch information
alecharp committed May 23, 2022
1 parent f1e0acc commit 9850472
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,16 @@ List<String> parseVersions(final String pResponse) throws VersionReaderException
}

private static final ThreadLocal<JAXBContext> JAXBCONTEXT = ThreadLocal.withInitial(() -> {
Thread currentThread = Thread.currentThread();
ClassLoader originalContext = currentThread.getContextClassLoader();
try {
currentThread.setContextClassLoader(MavenMetadataSearchService.class.getClassLoader());
return (JAXBContext.newInstance(MavenMetaData.class));
} catch (JAXBException e) {
LOGGER.log(Level.SEVERE, "failed to init JAXB context", e);
return null;
} finally {
currentThread.setContextClassLoader(originalContext);
}
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,16 @@ public class NexusLuceneSearchService extends AbstractRESTfulVersionReader imple
private boolean mUseRESTfulAPI;

private static final ThreadLocal<JAXBContext> JAXBCONTEXT = ThreadLocal.withInitial(() -> {
Thread currentThread = Thread.currentThread();
ClassLoader originalContext = currentThread.getContextClassLoader();
try {
currentThread.setContextClassLoader(NexusLuceneSearchService.class.getClassLoader());
return (JAXBContext.newInstance(PatchedSearchNGResponse.class));
} catch (JAXBException e) {
LOGGER.log(Level.SEVERE, "failed to init JAXB context", e);
return null;
} finally {
currentThread.setContextClassLoader(originalContext);
}
});

Expand Down

0 comments on commit 9850472

Please sign in to comment.