As I mentioned I copied and adapted the code from document-upload-protection sanitizer. Focused on the issue at hand I did not take care much about the style. Finally (pun intended ;)) I prefer to use a try-with-ressource for fos. Thanks: Wiebke for proposing another solution at https://github.com/apache/ofbiz-framework/pull/267/commits/51e82c66989b093392a06cb800fc84a7e413fe45