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.

17 thoughts on “IIOException can’t create cache file

  1. Great article (saved me hours I guess) – encountered the same problem after switching to ImageIO / RenderedImage in some classes. The temp-dir pointed to /var/tmp which is not writable for tomcat(-user) by default. Changed it to {catalina.home}/temp and surprise: works as designed. Thanks!

  2. You’re very welcome! It’s the little nuances that suck the majority of development cycles. Once in a while I actually fall on top of something that can help another developer and I try to keep a running list of issues here but with lack of time, other commitments, and the fact that Heroes is now airing on NBC I don’t always post everything. I’m supposed to post my Maven Blackberry plug in source… I just haven’t found time to dig the earlier working copy out of my svn history.

  3. Cliff,

    Found your blog when googling about this exact problem. Your post really helped save us some time.

    …slight correction the variable is “java.io.tmpdir” not “java.io.tmp.dir”

    Thanks for the help!

  4. Good catch Wells! Thanx! I sometimes post the details from memory rather than during actual crunch time so I’m prone to these mistakes. I’ve updated the post for accuracy. Thanx again!

  5. Love it! Been there, done that! In my case, it was just the permission issue with tmp – poor tomcat service couldn’t write to its temp dir. Things worked surprisingly well (in production!) until I started using ImageIO.

  6. Don’t you just love permissions issues? try/catch blocks can sometimes reveal these problems but you have to be judicious and diligent in your use of them.

  7. Thanks very much for that information. I’d removed that suspicious “temp” directory that I hadn’t seen in a decade+ of running Tomcat the other night, and found today that some of my webapps that generate graphics weren’t working. I was stumped by the “Can’t create cache file!” exception message – in the best traditions of programmers acting like they hate other programmers, whoever wrote that exception message omitted any information about what cache file it was trying to create and where it was trying to create, thus externalizing their laziness onto the Java community.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s