Skip to content

Commit

Permalink
Add violation for StringReader
Browse files Browse the repository at this point in the history
  • Loading branch information
mkarg authored and gaul committed Dec 1, 2024
1 parent 41f7f5a commit 6f5a64f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
6 changes: 6 additions & 0 deletions modernizer-maven-plugin/src/main/resources/modernizer.xml
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,12 @@ violation names use the same format that javap emits.
<comment>Prefer java.io.OutputStreamWriter(java.io.OutputStream, java.nio.charset.Charset)</comment>
</violation>

<violation>
<name>java/io/StringReader."&lt;init&gt;":(Ljava/lang/String;)V</name>
<version>24</version>
<comment>Prefer java.io.Reader.of(java.lang.CharSequence)</comment>
</violation>

<violation>
<name>java/lang/Byte."&lt;init&gt;":(B)V</name>
<version>5</version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import java.io.OutputStreamWriter;
import java.io.PrintStream;
import java.io.PrintWriter;
import java.io.StringReader;
import java.net.HttpURLConnection;
import java.net.NetworkInterface;
import java.net.URLDecoder;
Expand Down Expand Up @@ -399,7 +400,7 @@ public void testAnnotationViolation() throws Exception {

@Test
public void testAllViolations() throws Exception {
Modernizer modernizer = createModernizer("19");
Modernizer modernizer = createModernizer("24");
Collection<ViolationOccurrence> occurrences = modernizer.check(
new ClassReader(AllViolations.class.getName()));
occurrences.addAll(modernizer.check(
Expand All @@ -418,6 +419,8 @@ public void testAllViolations() throws Exception {
new ClassReader(Java18Violations.class.getName())));
occurrences.addAll(modernizer.check(
new ClassReader(Java19Violations.class.getName())));
occurrences.addAll(modernizer.check(
new ClassReader(Java24Violations.class.getName())));
// must visit inner classes manually
occurrences.addAll(modernizer.check(
new ClassReader(EnumerationTestClass.class.getName())));
Expand Down Expand Up @@ -847,6 +850,12 @@ private static void method() throws Exception {
}
}

private static class Java24Violations {
private static void method() throws Exception {
new StringReader("");
}
}

private enum EnumClass {
}
}

0 comments on commit 6f5a64f

Please sign in to comment.