diff --git a/src/main/java/org/codehaus/mojo/extraenforcer/dependencies/EnforceBytecodeVersion.java b/src/main/java/org/codehaus/mojo/extraenforcer/dependencies/EnforceBytecodeVersion.java index 251152a..bb32baa 100644 --- a/src/main/java/org/codehaus/mojo/extraenforcer/dependencies/EnforceBytecodeVersion.java +++ b/src/main/java/org/codehaus/mojo/extraenforcer/dependencies/EnforceBytecodeVersion.java @@ -48,7 +48,6 @@ import org.apache.maven.shared.artifact.filter.StrictPatternExcludesArtifactFilter; import org.apache.maven.shared.artifact.filter.StrictPatternIncludesArtifactFilter; import org.apache.maven.shared.dependency.graph.DependencyGraphBuilder; -import org.codehaus.plexus.util.IOUtil; import org.eclipse.aether.RepositorySystem; /** @@ -157,7 +156,7 @@ static String renderVersion(int major, int minor) { private String message; /** - * JDK version as used for example in the maven-compiler-plugin: 1.5, 1.6 and so on. If in need of more precise + * JDK version as used for example in the maven-compiler-plugin: 8, 11 and so on. If in need of more precise * configuration please see {@link #maxJavaMajorVersionNumber} and {@link #maxJavaMinorVersionNumber} Mandatory if * {@link #maxJavaMajorVersionNumber} not specified. */ @@ -246,14 +245,13 @@ private void computeParameters() throws EnforcerRuleException { } if (maxJdkVersion == null && maxJavaMajorVersionNumber == -1) { throw new IllegalArgumentException( - "Exactly one of maxJdkVersion or " + "maxJavaMajorVersionNumber options should be set."); + "Exactly one of maxJdkVersion or maxJavaMajorVersionNumber options should be set."); } if (maxJdkVersion != null) { Integer needle = JDK_TO_MAJOR_VERSION_NUMBER_MAPPING.get(maxJdkVersion); if (needle == null) { throw new IllegalArgumentException( - "Unknown JDK version given. Should be something like " - + "\"1.7\", \"8\", \"11\", \"12\", \"13\", \"14\", \"15\", \"16\", \"17\", \"18\", \"19\", \"20\""); + "Unknown JDK version given. Should be something like \"8\", \"11\", \"17\", \"21\" .."); } maxJavaMajorVersionNumber = needle; if (!strict && needle < 53) { @@ -313,25 +311,16 @@ private String isBadArtifact(Artifact a) throws EnforcerRuleException { } } - InputStream is = null; - try { - is = jarFile.getInputStream(entry); + try (InputStream is = jarFile.getInputStream(entry)) { int total = magicAndClassFileVersion.length; while (total > 0) { int read = is.read(magicAndClassFileVersion, magicAndClassFileVersion.length - total, total); - if (read == -1) { throw new EOFException(f.toString()); } - total -= read; } - - is.close(); - is = null; - } finally { - IOUtil.close(is); } int minor = (magicAndClassFileVersion[4] << 8) + magicAndClassFileVersion[5];