Skip to content

Commit 2e098f0

Browse files
committed
Java: Ignore char array based closeables for CloseReader.ql and CloseWriter.ql
1 parent 5016c64 commit 2e098f0

File tree

4 files changed

+6
-13
lines changed

4 files changed

+6
-13
lines changed

java/ql/src/Likely Bugs/Resource Leaks/CloseReader.qhelp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ but not closed may cause a resource leak.
1414

1515
<p>Ensure that the resource is always closed to avoid a resource leak. Note that, because of exceptions,
1616
it is safest to close a resource in a <code>finally</code> block. (However, this is unnecessary for
17-
subclasses of <code>StringReader</code> and <code>ByteArrayInputStream</code>.)
17+
subclasses of <code>CharArrayReader</code>, <code>StringReader</code> and <code>ByteArrayInputStream</code>.)
1818
</p>
1919

2020
<p>For Java 7 or later, the recommended way to close resources that implement <code>java.lang.AutoCloseable</code>

java/ql/src/Likely Bugs/Resource Leaks/CloseReader.ql

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,14 @@ import CloseType
1717

1818
predicate readerType(RefType t) {
1919
exists(RefType sup | sup = t.getASupertype*() |
20-
sup.hasName("Reader") or
21-
sup.hasName("InputStream") or
20+
sup.hasName(["Reader", "InputStream"]) or
2221
sup.hasQualifiedName("java.util.zip", "ZipFile")
2322
)
2423
}
2524

2625
predicate safeReaderType(RefType t) {
2726
exists(RefType sup | sup = t.getASupertype*() |
28-
sup.hasName("StringReader") or
29-
sup.hasName("ByteArrayInputStream") or
30-
sup.hasName("StringInputStream")
27+
sup.hasName(["CharArrayReader", "StringReader", "ByteArrayInputStream"])
3128
)
3229
}
3330

java/ql/src/Likely Bugs/Resource Leaks/CloseWriter.qhelp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ but not properly closed later may cause a resource leak.
1414

1515
<p>Ensure that the resource is always closed to avoid a resource leak. Note that, because of exceptions,
1616
it is safest to close a resource properly in a <code>finally</code> block. (However, this is unnecessary for
17-
subclasses of <code>StringWriter</code> and <code>ByteArrayOutputStream</code>.)</p>
17+
subclasses of <code>CharArrayWriter</code>, <code>StringWriter</code> and <code>ByteArrayOutputStream</code>.)</p>
1818

1919
<p>For Java 7 or later, the recommended way to close resources that implement <code>java.lang.AutoCloseable</code>
2020
is to declare them within a <code>try-with-resources</code> statement, so that they are closed implicitly.</p>

java/ql/src/Likely Bugs/Resource Leaks/CloseWriter.ql

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,12 @@
1616
import CloseType
1717

1818
predicate writerType(RefType t) {
19-
exists(RefType sup | sup = t.getASupertype*() |
20-
sup.hasName("Writer") or
21-
sup.hasName("OutputStream")
22-
)
19+
exists(RefType sup | sup = t.getASupertype*() | sup.hasName(["Writer", "OutputStream"]))
2320
}
2421

2522
predicate safeWriterType(RefType t) {
2623
exists(RefType sup | sup = t.getASupertype*() |
27-
sup.hasName("StringWriter") or
28-
sup.hasName("ByteArrayOutputStream")
24+
sup.hasName(["CharArrayWriter", "StringWriter", "ByteArrayOutputStream"])
2925
)
3026
}
3127

0 commit comments

Comments
 (0)