tutorials
tutorials copied to clipboard
Update JavaDirectoryDeleteUnitTest.java
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.
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.