Index: lucene/tools/src/java/org/apache/lucene/validation/ForbiddenApisCheckTask.java =================================================================== --- lucene/tools/src/java/org/apache/lucene/validation/ForbiddenApisCheckTask.java (revision 1416062) +++ lucene/tools/src/java/org/apache/lucene/validation/ForbiddenApisCheckTask.java (working copy) @@ -70,6 +70,8 @@ private final Resources apiSignatures = new Resources(); private Path classpath = null; + private boolean failOnUnsupportedJava = false; + ClassLoader loader = null; final Map classesToCheck = new HashMap(); @@ -315,16 +317,6 @@ @Override public void execute() throws BuildException { - // the checker is not compatible with JDK 1.8+ (changed class format: 52.0), don't fail just report warning: - try { - Collections.class.getMethod("emptySortedSet"); - // this is Java 8 :( - log("Java 8 or later is currently not supported by this checker. Please run the checks with a previous JDK!", Project.MSG_WARN); - return; - } catch (NoSuchMethodException nsme) { - // ignore, we are fine! - } - AntClassLoader antLoader = null; try { if (classpath != null) { @@ -340,6 +332,22 @@ apiSignatures.setProject(getProject()); final long start = System.currentTimeMillis(); + + // check if we can load runtime classes (e.g. java.lang.String). + // If this fails, we have a newer Java version than ASM supports: + try { + getClassFromClassLoader(String.class.getName()); + } catch (IllegalArgumentException iae) { + final String msg = String.format(Locale.ROOT, + "Your Java version (%s) is not supported by <%s/>. Please run the checks with a supported JDK!", + System.getProperty("java.version"), getTaskName()); + if (failOnUnsupportedJava) { + throw new BuildException(msg); + } else { + log("WARNING: " + msg, Project.MSG_WARN); + return; + } + } try { @SuppressWarnings("unchecked") @@ -454,6 +462,10 @@ } return this.classpath.createPath(); } + + public void setFailOnUnsupportedJava(boolean failOnUnsupportedJava) { + this.failOnUnsupportedJava = failOnUnsupportedJava; + } static final class ClassSignatureLookup { public final ClassReader reader;