[java] CloseResource: ignore java.io.CharArrayWriter by default

Refs #1928
This commit is contained in:
Andreas Dangel
2019-07-27 10:27:18 +02:00
parent 49d2a58556
commit aa55a0108c
3 changed files with 28 additions and 3 deletions

View File

@ -88,7 +88,8 @@ public class CloseResourceRule extends AbstractJavaRule {
private static final PropertyDescriptor<List<String>> ALLOWED_RESOURCE_TYPES =
stringListProperty("allowedResourceTypes")
.desc("Exact class names that do not need to be closed")
.defaultValues("java.io.ByteArrayOutputStream", "java.io.ByteArrayInputStream", "java.io.StringWriter")
.defaultValues("java.io.ByteArrayOutputStream", "java.io.ByteArrayInputStream", "java.io.StringWriter",
"java.io.CharArrayWriter")
.build();

View File

@ -876,6 +876,30 @@ public class CloseResourceWithExceptions {
]]></code>
</test-code>
<test-code>
<description>CharArrayWriter does not need closing</description>
<expected-problems>0</expected-problems>
<code><![CDATA[
import java.io.Writer;
import java.io.CharArrayWriter;
import java.io.IOException;
public class CloseResourceWithExceptions {
public char[] bar() {
/*CharArray*/Writer buffer = new CharArrayWriter();
try {
buffer.append("foo");
return buffer.toCharArray();
} catch (IOException e) {
throw new RuntimeException(e);
}
return null;
}
}
]]></code>
</test-code>
<test-code>
<description>A custom StringWriter does need closing</description>
<expected-problems>1</expected-problems>