File tree Expand file tree Collapse file tree 4 files changed +6
-13
lines changed
java/ql/src/Likely Bugs/Resource Leaks Expand file tree Collapse file tree 4 files changed +6
-13
lines changed Original file line number Diff line number Diff line change @@ -14,7 +14,7 @@ but not closed may cause a resource leak.
14
14
15
15
<p >Ensure that the resource is always closed to avoid a resource leak. Note that, because of exceptions,
16
16
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 >.)
18
18
</p >
19
19
20
20
<p >For Java 7 or later, the recommended way to close resources that implement <code >java.lang.AutoCloseable</code >
Original file line number Diff line number Diff line change @@ -17,17 +17,14 @@ import CloseType
17
17
18
18
predicate readerType ( RefType t ) {
19
19
exists ( RefType sup | sup = t .getASupertype * ( ) |
20
- sup .hasName ( "Reader" ) or
21
- sup .hasName ( "InputStream" ) or
20
+ sup .hasName ( [ "Reader" , "InputStream" ] ) or
22
21
sup .hasQualifiedName ( "java.util.zip" , "ZipFile" )
23
22
)
24
23
}
25
24
26
25
predicate safeReaderType ( RefType t ) {
27
26
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" ] )
31
28
)
32
29
}
33
30
Original file line number Diff line number Diff line change @@ -14,7 +14,7 @@ but not properly closed later may cause a resource leak.
14
14
15
15
<p >Ensure that the resource is always closed to avoid a resource leak. Note that, because of exceptions,
16
16
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 >
18
18
19
19
<p >For Java 7 or later, the recommended way to close resources that implement <code >java.lang.AutoCloseable</code >
20
20
is to declare them within a <code >try-with-resources</code > statement, so that they are closed implicitly.</p >
Original file line number Diff line number Diff line change 16
16
import CloseType
17
17
18
18
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" ] ) )
23
20
}
24
21
25
22
predicate safeWriterType ( RefType t ) {
26
23
exists ( RefType sup | sup = t .getASupertype * ( ) |
27
- sup .hasName ( "StringWriter" ) or
28
- sup .hasName ( "ByteArrayOutputStream" )
24
+ sup .hasName ( [ "CharArrayWriter" , "StringWriter" , "ByteArrayOutputStream" ] )
29
25
)
30
26
}
31
27
You can’t perform that action at this time.
0 commit comments