Details
Description
FontCache.getDefaultCacheFile(boolean forWriting) tries to choose and (if necessary) create a .fop directory. It checks to make sure that is writable, and if not, users a temporary directory instead. Finally, it then returns a File pointing inside the .fop directory.
This all works, but only when FontCache.getUserHome() returns non-null.
getUserHome() returns null if a user is configured with a non-existent home directory (which just happens to be the default when installing Apache Tomcat 9 on Ubuntu, where the home directory is /var/lib/tomcat but it doesn't exist, whereas /var/lib/tomcat9 does).
In this case, it simply returns a new file called ".fop". This means the default cache file will be called ".fop" in the current working directory. This avoids the check to see whether the directory is writable, and it uses a file called .fop instead of a directory called .fop.
If (as can be the case in Tomcat) the current working directory is not writable, then the default cache file cannot be written to leading to an exception.
I think this can be fixed with simple change from this:
File userHome = getUserHome(); if (userHome != null) { File fopUserDir = new File(userHome, FOP_USER_DIR);
to this:
File userHome = getUserHome(); File fopUserDir = userHome == null ? new File(FOP_USER_DIR) : new File(userHome, FOP_USER_DIR);