Skip to content

Commit

Permalink
[JENKINS-63808] cppcheck is not compatible with Java 11 (#64)
Browse files Browse the repository at this point in the history
  • Loading branch information
basil committed May 20, 2022
1 parent 0189123 commit 86581fb
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,18 @@ public CppcheckReport parse(final File file) throws IOException {
CppcheckReport report;
AtomicReference<JAXBContext> jc = new AtomicReference<JAXBContext>();
try {
jc.set(JAXBContext.newInstance(
org.jenkinsci.plugins.cppcheck.model.Error.class,
org.jenkinsci.plugins.cppcheck.model.Errors.class,
org.jenkinsci.plugins.cppcheck.model.Cppcheck.class,
org.jenkinsci.plugins.cppcheck.model.Results.class));
Thread t = Thread.currentThread();
ClassLoader orig = t.getContextClassLoader();
t.setContextClassLoader(CppcheckParser.class.getClassLoader());
try {
jc.set(JAXBContext.newInstance(
org.jenkinsci.plugins.cppcheck.model.Error.class,
org.jenkinsci.plugins.cppcheck.model.Errors.class,
org.jenkinsci.plugins.cppcheck.model.Cppcheck.class,
org.jenkinsci.plugins.cppcheck.model.Results.class));
} finally {
t.setContextClassLoader(orig);
}
Unmarshaller unmarshaller = jc.get().createUnmarshaller();
org.jenkinsci.plugins.cppcheck.model.Results results = (org.jenkinsci.plugins.cppcheck.model.Results) unmarshaller.unmarshal(file);
if (results.getCppcheck() == null) {
Expand All @@ -69,7 +76,14 @@ public CppcheckReport parse(final File file) throws IOException {
report = getReportVersion2(results);
} catch (JAXBException jxe) {
try {
jc.set(JAXBContext.newInstance(com.thalesgroup.jenkinsci.plugins.cppcheck.model.Error.class, com.thalesgroup.jenkinsci.plugins.cppcheck.model.Results.class));
Thread t = Thread.currentThread();
ClassLoader orig = t.getContextClassLoader();
t.setContextClassLoader(CppcheckParser.class.getClassLoader());
try {
jc.set(JAXBContext.newInstance(com.thalesgroup.jenkinsci.plugins.cppcheck.model.Error.class, com.thalesgroup.jenkinsci.plugins.cppcheck.model.Results.class));
} finally {
t.setContextClassLoader(orig);
}
Unmarshaller unmarshaller = jc.get().createUnmarshaller();
com.thalesgroup.jenkinsci.plugins.cppcheck.model.Results results = (com.thalesgroup.jenkinsci.plugins.cppcheck.model.Results) unmarshaller.unmarshal(file);
report = getReportVersion1(results);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,18 @@ public CppcheckReport parse(final File file, TaskListener listener) throws IOExc
CppcheckReport report;
AtomicReference<JAXBContext> jc = new AtomicReference<JAXBContext>();
try {
jc.set(JAXBContext.newInstance(
org.jenkinsci.plugins.cppcheck.model.Error.class,
org.jenkinsci.plugins.cppcheck.model.Errors.class,
org.jenkinsci.plugins.cppcheck.model.Cppcheck.class,
org.jenkinsci.plugins.cppcheck.model.Results.class));
Thread t = Thread.currentThread();
ClassLoader orig = t.getContextClassLoader();
t.setContextClassLoader(CppcheckParser.class.getClassLoader());
try {
jc.set(JAXBContext.newInstance(
org.jenkinsci.plugins.cppcheck.model.Error.class,
org.jenkinsci.plugins.cppcheck.model.Errors.class,
org.jenkinsci.plugins.cppcheck.model.Cppcheck.class,
org.jenkinsci.plugins.cppcheck.model.Results.class));
} finally {
t.setContextClassLoader(orig);
}
Unmarshaller unmarshaller = jc.get().createUnmarshaller();
org.jenkinsci.plugins.cppcheck.model.Results results = (org.jenkinsci.plugins.cppcheck.model.Results) unmarshaller.unmarshal(file);
if (results.getCppcheck() == null) {
Expand All @@ -50,7 +57,14 @@ public CppcheckReport parse(final File file, TaskListener listener) throws IOExc
report = getReportVersion2(results);
} catch (JAXBException jxe) {
try {
jc.set(JAXBContext.newInstance(com.thalesgroup.jenkinsci.plugins.cppcheck.model.Error.class, com.thalesgroup.jenkinsci.plugins.cppcheck.model.Results.class));
Thread t = Thread.currentThread();
ClassLoader orig = t.getContextClassLoader();
t.setContextClassLoader(CppcheckParser.class.getClassLoader());
try {
jc.set(JAXBContext.newInstance(com.thalesgroup.jenkinsci.plugins.cppcheck.model.Error.class, com.thalesgroup.jenkinsci.plugins.cppcheck.model.Results.class));
} finally {
t.setContextClassLoader(orig);
}
Unmarshaller unmarshaller = jc.get().createUnmarshaller();
com.thalesgroup.jenkinsci.plugins.cppcheck.model.Results results = (com.thalesgroup.jenkinsci.plugins.cppcheck.model.Results) unmarshaller.unmarshal(file);
report = getReportVersion1(results);
Expand All @@ -60,11 +74,7 @@ public CppcheckReport parse(final File file, TaskListener listener) throws IOExc
+ "It often detects and reports more issues with the new format, "
+ "so its usage is highly recommended.");
} catch (JAXBException jxe1) {
// Since Java 1.6
// throw new IOException(jxe1);

// Legacy constructor for compatibility with Java 1.5
throw (IOException) new IOException(jxe1.toString()).initCause(jxe1);
throw new IOException(jxe1);
}
}
return report;
Expand Down

0 comments on commit 86581fb

Please sign in to comment.