From 537be7df0d9463236806ef8ffc73fc4447d66e2e Mon Sep 17 00:00:00 2001 From: Andrew Gaul Date: Mon, 20 Jan 2025 18:09:23 -0800 Subject: [PATCH] Add violations for Apache commons-io References #21. --- .../src/main/resources/modernizer.xml | 68 ++++++++++++++++++- .../ModernizerTest.java | 19 +++++- 2 files changed, 85 insertions(+), 2 deletions(-) diff --git a/modernizer-maven-plugin/src/main/resources/modernizer.xml b/modernizer-maven-plugin/src/main/resources/modernizer.xml index d349bfb..3231d43 100644 --- a/modernizer-maven-plugin/src/main/resources/modernizer.xml +++ b/modernizer-maven-plugin/src/main/resources/modernizer.xml @@ -272,7 +272,7 @@ violation names use the same format that javap emits. com/google/common/io/ByteStreams.copy:(Ljava/io/InputStream;Ljava/io/OutputStream;)J 9 - Prefer java.io.InputStream.transferTo + Prefer java.io.InputStream.transferTo(InputStream, OutputStream) @@ -713,6 +713,66 @@ violation names use the same format that javap emits. Prefer java.nio.file.Files.readAllLines(java.nio.file.Path, java.nio.charset.Charset) + + org/apache/commons/io/IOUtils.copy:(Ljava/io/InputStream;Ljava/io/OutputStream;)I + 9 + Prefer java.io.InputStream.transferTo(InputStream, OutputStream) + + + + org/apache/commons/io/IOUtils.copyLarge:(Ljava/io/InputStream;Ljava/io/OutputStream;)J + 9 + Prefer java.io.InputStream.transferTo(InputStream, OutputStream) + + + + org/apache/commons/io/IOUtils.copy:(Ljava/io/Reader;Ljava/io/Writer;)I + 9 + Prefer java.io.InputStream.transferTo(Reader, Writer) + + + + org/apache/commons/io/IOUtils.copyLarge:(Ljava/io/Reader;Ljava/io/Writer;)J + 9 + Prefer java.io.InputStream.transferTo(Reader, Writer) + + + + org/apache/commons/io/IOUtils.skipFully:(Ljava/io/InputStream;J)V + 12 + Prefer java.io.InputStream.skipNBytes(long) + + + + org/apache/commons/io/IOUtils.toByteArray:(Ljava/io/InputStream;)[B + 9 + Prefer java.io.InputStream.readAllBytes(InputStream) + + + + org/apache/commons/io/output/NullOutputStream.NULL_OUTPUT_STREAM:Lorg/apache/commons/io/output/NullOutputStream; + 11 + Prefer java.io.OutputStream.nullOutputStream() + + + + org/apache/commons/io/output/NullOutputStream."<init>":()V + 11 + Prefer java.io.OutputStream.nullOutputStream() + + + + org/apache/commons/io/output/NullWriter.NULL_WRITER:Lorg/apache/commons/io/output/NullWriter; + 11 + Prefer java.io.Writer.nullWriter() + + + + org/apache/commons/io/output/NullWriter."<init>":()V + 11 + Prefer java.io.Writer.nullWriter() + + sun/misc/BASE64Decoder.decodeBuffer:(Ljava/lang/String;)[B 8 @@ -1193,6 +1253,12 @@ violation names use the same format that javap emits. Prefer java.io.Writer.nullWriter() + + com/google/common/io/CharStreams.skipFully:(Ljava/io/Reader;J)V + 12 + Prefer java.io.InputStream.skipNBytes(long) + + com/google/common/io/Files.toString:(Ljava/io/File;Ljava/nio/charset/Charset;)Ljava/lang/String; 11 diff --git a/modernizer-maven-plugin/src/test/java/org/gaul/modernizer_maven_plugin/ModernizerTest.java b/modernizer-maven-plugin/src/test/java/org/gaul/modernizer_maven_plugin/ModernizerTest.java index bded0ca..06b1d71 100644 --- a/modernizer-maven-plugin/src/test/java/org/gaul/modernizer_maven_plugin/ModernizerTest.java +++ b/modernizer-maven-plugin/src/test/java/org/gaul/modernizer_maven_plugin/ModernizerTest.java @@ -30,7 +30,9 @@ import java.io.OutputStreamWriter; import java.io.PrintStream; import java.io.PrintWriter; +import java.io.Reader; import java.io.StringReader; +import java.io.Writer; import java.net.HttpURLConnection; import java.net.NetworkInterface; import java.net.URI; @@ -95,6 +97,9 @@ import org.apache.commons.codec.binary.Base64; import org.apache.commons.codec.binary.Hex; import org.apache.commons.io.FileUtils; +import org.apache.commons.io.IOUtils; +import org.apache.commons.io.output.NullOutputStream; +import org.apache.commons.io.output.NullWriter; import org.apache.commons.lang3.StringUtils; import org.gaul.modernizer_maven_plugin .SuppressModernizerTestClasses.SuppressedOnClass; @@ -628,7 +633,6 @@ private static void method() throws Exception { Sets.unmodifiableNavigableSet(new TreeSet()); Sets.synchronizedNavigableSet(new TreeSet()); BaseEncoding.base64(); - ByteStreams.copy((InputStream) null, (OutputStream) null); Files.toByteArray((File) null); Chars.compare((char) 0, (char) 0); Ints.compare(0, 0); @@ -771,6 +775,12 @@ private static class Java9Violations { @SuppressWarnings("deprecation") private static void method() throws Exception { ByteStreams.toByteArray((InputStream) null); + ByteStreams.copy((InputStream) null, (OutputStream) null); + IOUtils.copy((InputStream) null, (OutputStream) null); + IOUtils.copyLarge((InputStream) null, (OutputStream) null); + IOUtils.copy((Reader) null, (Writer) null); + IOUtils.copyLarge((Reader) null, (Writer) null); + IOUtils.toByteArray((InputStream) null); new Byte((String) null); new Double((String) null); new Short((String) null); @@ -822,8 +832,13 @@ private static void method() throws Exception { private static class Java11Violations { @SuppressWarnings("deprecation") private static void method() throws Exception { + Object object; ByteStreams.nullOutputStream(); CharStreams.nullWriter(); + object = NullOutputStream.NULL_OUTPUT_STREAM; + new NullOutputStream(); + object = NullWriter.NULL_WRITER; + new NullWriter(); Files.toString((File) null, (Charset) null); Files.write("", (File) null, (Charset) null); new FileReader((File) null, (Charset) null); @@ -840,6 +855,8 @@ private static void method() throws Exception { private static class Java12Violations { private static void method() throws Exception { ByteStreams.skipFully(null, 0L); + CharStreams.skipFully(null, 0L); + IOUtils.skipFully((InputStream) null, 0L); } }