IIOException can’t create cache file
Tomcat + ImageIO
What do you get? Trouble! Who would guess that doing PNG conversion with JDK APIs requires you to have a temp folder off of $CATALINA_BASE? After being labeled the build master unofficially, I took the initiative (if you can call totally screwing up a quasi-production deployment initiative) to prune what looked like cruft from a template tarball. Among this cruft was our precious temp folder. Let me explain better.
We use a deployment template for production builds. You know how this stuff goes when one developer gets something working and management says something like, “can you make yours work like his?” Thus begins the binary hand-off. A binary archive of the stuff he did bequeathed unto you to bring identical magic to your project. You then hand it down to the next developer that needs to do something similar. And so on and so forth. The entire idea is crazy but it’s the stuff major companies run on. by the time it gets handed to the 5th or 12th person down the line nobody remembers or understands anything from the original project only that this thing is what’s supposed to make everything else work just like it.
So I get this tarball, and I’ve got plenty others that look sorta like it that I tried creating from scratch. Some of mine half work while others just flop. I loose track because all correspondences with the deployment team and myself happens in a loosely coupled chain of random emails and secure copies to locked down servers that I have no business touching. I finally get something working that I can actually automate but I feel dirty because this binary template is checked into our version control system. So I begin cleaning the cruft, extracting the true thing that our project needs… structure not binary data. Everything begins to work. Everything except for a few execution paths that I have not had time to QA due to my tight schedule. I ask for QA from the QA team but I’ve been so tied up in performance tests that I can’t let the team anywhere near the deployment. I find other issues due to my not following certain design patterns. I fix issues. But the entire thing takes sooo much effort because I work in a highly secured environment. I work with one guy that’s been a blessing giving me higher than usual access rights as if I truly knew what I was doing on a Linux box. (Wasn’t I losing my Linux touch just days ago?)
The end of my plight is today. After hitting the “IIOException can’t create cache file” thing I Googled and found some info hinting to some more detailed discussion that only hints that you need a temp folder configured for Tomcat. I examined the startup script and plugged in the missing temp folder and voila! Everything worked as it should.
Moral to story
If you get: IIOException: can’t create cache file!
And you’re running in Tomcat
Then you need to make sure $CATALINA_BASE/temp actually exists and is writable.
By default Tomcat’s startup scripts set java.io.tmpdir to $CATALINA_BASE/temp but this could be overriden by a number of different ways. It is the java.io.tmpdir that is used by ImageIO and possibly numerous of other 3rd party APIs and open source components for cache files and other temporary stuff.