directoryDelete() can throw NPE


I noticed an error that only happened once, in a scenario were a directory was being deleted twice. Even though I couldn't reproduce it right off, I reviewed the Lucee source code and there are some issues there that need resolved where I can see how this error isn't accounted for correctly.

The version of Lucee is 5.3.6-RC. The CFML code in question was:

And the relevant part of the exception was:

Inspecting the Java source of the FileResource class shows the failing Java code was:

the failing line was the "for" loop so the "children" variable must have been null. Checking the implementation of the "listResources()" method, it explicitly returns null in some cases. The remove() method does not correctly account for the possibility of the listResource() method returning null. This is probably a tough error to hit since it would require some sort of race condition on the hard drive where the folder disappears in the middle of the operation, but one can see from the code how null needs to be handled a little better.




Michael Offner
April 23, 2020, 5:20 PM

Michael Offner
April 23, 2020, 5:24 PM

it returns null in case the file listed is not an existing directory.

Michael Offner
April 23, 2020, 5:41 PM

checked the complete code for this issue

Brad Wood
April 23, 2020, 6:28 PM

I just tried for the last hour to create a reproducible case for this. I was able to create the error a couple times, but not reliably at all. It seems related to how busy my hard drives are at the time. In fact, there's a lot of interesting errors I've found you can get while creating and deleting large directories that probably depends on a lot of factors. The NPE above however is at least something we know can be solved with a bit of defensive programming.

Brad Wood
April 23, 2020, 6:30 PM

Thanks for taking a look so quickly Your commits above look like they will certainly prevent the NPE from happening again.



Michael Offner


Brad Wood




Fix versions



Affects versions