Java

Java

Made by DeepSource

Stream does not appear to be closed after use JAVA-S0268

Anti-pattern
Critical

The method creates an IO stream object, does not assign it to any fields, pass it to other methods that might close it, or return it, and does not appear to close the stream on all paths out of the method.

While the stream could possibly be closed when it is garbage collected, it is not guaranteed, and relying on the garbage collector to dispose of used resources is an exceptionally bad habit.

Ensure that the stream is closed, preferably through constructs such as try-with-resources or finally blocks, or manually call close() on the resource at the end of the method.

See this discussion for more perspective on the behavior of java streams.