[java] CloseResource: ignore java.io.CharArrayWriter by default
Refs #1928
This commit is contained in:
@ -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();
|
||||
|
||||
|
||||
|
@ -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>
|
||||
|
Reference in New Issue
Block a user