Skip to content

Commit

Permalink
[java] MissingOverrideRule exception when analyzing PMD under Java 9
Browse files Browse the repository at this point in the history
Adds a workaround, that fixes pmd#1074
  • Loading branch information
adangel committed Jun 18, 2018
1 parent e1066fe commit d6dbfa6
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
2 changes: 2 additions & 0 deletions docs/pages/release_notes.md
Expand Up @@ -34,6 +34,8 @@ This is a minor release.
* [#1193](https://github.com/pmd/pmd/issues/1193): \[core] Designer doesn't start with run.sh
* ecmascript
* [#861](https://github.com/pmd/pmd/issues/861): \[ecmascript] InnaccurateNumericLiteral false positive with hex literals
* java
* [#1074](https://github.com/pmd/pmd/issues/1074): \[java] MissingOverrideRule exception when analyzing PMD under Java 9
* java-bestpractices
* [#651](https://github.com/pmd/pmd/issues/651): \[java] SwitchStmtsShouldHaveDefault should be aware of enum types
* [#869](https://github.com/pmd/pmd/issues/869): \[java] GuardLogStatement false positive on return statements and Math.log
Expand Down
Expand Up @@ -102,13 +102,30 @@ public String toString() {
.append(StringUtils.join(getURLs(), ":"))
.append("] parent: ").append(getParent()).append(']').toString();
}


/**
* Tries to load the given class. Note: This classloader first tries to load the class
* itself and if that fails, delegates to the parent class loader.
* This is needed, if the project being analyzed by PMD uses the same dependencies as PMD itself
* (e.g. apache commons) but in a different version. Trying to resolve the class first
* within this classloader makes sure, to use the correct version for type resolution.
*/
@Override
protected Class<?> loadClass(final String name, final boolean resolve) throws ClassNotFoundException {
synchronized (getClassLoadingLock(name)) {
// First, check if the class has already been loaded
Class<?> c = findLoadedClass(name);
if (c == null) {

// exception for org.w3c.dom.UserDataHandler, which is on the JDK classpath
// and on jaxen
// see https://github.com/pmd/pmd/issues/1074
// we can directly return here, since PMD needs to run with java 7+, which
// for sure has this interface on the JDK classpath
if ("org.w3c.dom.UserDataHandler".equals(name)) {
return super.loadClass(name, resolve);
}

try {
// checking local
c = findClass(name);
Expand All @@ -118,7 +135,7 @@ protected Class<?> loadClass(final String name, final boolean resolve) throws Cl
c = super.loadClass(name, resolve);
}
}

if (resolve) {
resolveClass(c);
}
Expand Down

0 comments on commit d6dbfa6

Please sign in to comment.