File tree Expand file tree Collapse file tree
java/ql/src/Likely Bugs/Resource Leaks Expand file tree Collapse file tree Original file line number Diff line number Diff 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,
1616it 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 >
Original file line number Diff line number Diff line change @@ -17,17 +17,14 @@ import CloseType
1717
1818predicate 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
2625predicate 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
Original file line number Diff line number Diff 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,
1616it 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 >
2020is 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 1616import CloseType
1717
1818predicate 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
2522predicate 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
You can’t perform that action at this time.
0 commit comments