tutorials icon indicating copy to clipboard operation
tutorials copied to clipboard

Update JavaDirectoryDeleteUnitTest.java

Open jvandervyver opened this issue 7 months ago • 0 comments

Description

File.walk is a common source of memory leaks in my corporate job. So much so that it has caused outages a few times now.

The returned stream encapsulates one or more DirectoryStreams. If timely disposal of file system resources is required, the try-with-resources construct should be used to ensure that the stream's close method is invoked after the stream operations are completed. Operating on a closed stream will result in an IllegalStateException.

source

Ideally you'd update your article too 😅 I suspect that is where most folks are going to grab this code.

I realize this is just a unit-test, so who cares but realistically your example will be used in critical sections that aren't just once-off unit tests.

jvandervyver avatar Jul 17 '24 09:07 jvandervyver