public static Character containsInvalidCharacters(String s) {
        try {
            Paths.get(s);
        }
        catch (InvalidPathException e) {
            if (e.getInput() != null && !e.getInput().isEmpty() && e.getIndex() >= 0) {
                return s.toCharArray()[e.getIndex()];
            }
        }
        return null;
    }
Check the file path to ensure its valid and prevent directory traversal security issues.

@param filePath the file path to test
@param mustExist true if the directory must exist on disk, false if not
@return the updated file path
primefaces/src/main/java/org/primefaces/util/FileUploadUtils.java