MULE-8054: Adding check to make sure the folder is open before closing it.
(cherry picked from commit dc0dd0c3fa4c2433d90263cec154bd4c389a7a61)