S2095 (Resources should be closed) should not mark Java 8 Stream

209 views
Skip to first unread message

kuba.bo...@gmail.com

unread,
Mar 2, 2016, 5:23:05 AM3/2/16
to SonarQube
Hi,
 this rule has a default severity of "blocker" and it flags uses of java.util.Stream if it's not closed.

However the javadoc for Stream states:
Streams have a close() method and implement AutoCloseable, but nearly all stream instances do not actually need to be closed after use. Generally, only streams whose source is an IO channel (such as those returned by Files.lines(Path, Charset)) will require closing. Most streams are backed by collections, arrays, or generating functions, which require no special resource management. (If a stream does require closing, it can be declared as a resource in a try-with-resources statement.)
I think this rule needs a way to add exceptions (so that Stream can be excluded), or maybe there should be a separate rule for java.util.Stream with a lower default severity.

Nicolas Peru

unread,
Mar 2, 2016, 5:30:26 AM3/2/16
to kuba.bo...@gmail.com, SonarQube
Hi, 

This is indeed an issue and we already know about it:  https://jira.sonarsource.com/browse/SONARJAVA-1478 
Thanks for reporting it. 

Cheers, 


--
You received this message because you are subscribed to the Google Groups "SonarQube" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sonarqube+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sonarqube/a1d869ed-e532-45ae-8f46-6fb1e1c1c45e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
Nicolas PERU | SonarSource
Senior Developer
http://sonarsource.com
Reply all
Reply to author
Forward
0 new messages