Oops Null Pointer

Java programming related

Monthly Archives: May 2011

Ehcache Error: Could not create cache directory

I recently updated ehcache from 2.3.0 to 2.4.2. Everything seemed to work fine, but one cache was throwing the error “Could not create cache directory” and the location was in the bin directory of my app server. Suspiciously, this is the default path when an empty path is given as the disk store location. This cache is a little unusual in it’s configuration as it loads an xml config file for the cache manager settings and then programmatically adds a cache to this cache manager. The xml file has the disk store path and the cache constructor sets the disk store parameter to “”.

In 2.3.0 this would allow the cache to inherit the disk sore in the xml cache manager config, but in 2.4.2 you must set the disk store parameter in null to have the same effect. I couldn’t find this noted anywhere so I though I’d post it here in case you hit the same pot hole on the road to cache happiness.

This upgrade was part of heading towards using Terracotta to cluster application (via the caches) and while everything is hanging together so far, the cluster’s performance needs some tuning.

Sending PDF files in the response

To send PDF files so that most browsers will display them I’ve found the following headers work:

  • Content-Disposition: inline; filename=sample.pdf or Content-Disposition: attachment; filename=sample.pdf
  • Expires: 0
  • Cache-Control: must-revalidate, post-check=0, pre-check=0
  • Pragma: public
  • Content-Type: application/pdf
  • Content-Length: <number of bytes>

Here is some rough Java to stream an input stream to the HttpServletResponse.

public static void streamInputToResponse(HttpServletResponse resp, boolean isInline, String contentType, String filename,
		InputStream in, int length) throws IOException {
	ServletOutputStream outstr = null;
	try {
		if (length > Integer.MAX_VALUE) {
			throw new IOException("File to large to stream");
		outstr = resp.getOutputStream();
		// Setting required headers
		String inlineOrAttachment = isInline ? "inline;" : "attachment;";
		resp.setHeader("Content-Disposition", inlineOrAttachment + " filename=" + filename);
		// setting some extra response headers to sooth browser issues
		resp.setHeader("Expires", "0");
		resp.setHeader("Cache-Control", "must-revalidate, post-check=0, pre-check=0");
		resp.setHeader("Pragma", "public");

		IOUtils.copy(in, outstr);
	catch (IOException e) {
		String errorStr = "Error Streaming data to servlet output stream" + ": " + e.getMessage();

		try {
			if (outstr != null) {
		catch (IOException e1) {
			logger.warn("Error flushing servlet output stream: " + e1.getMessage());
		throw e;
	finally {

The Restlet framework has some issues with PDFs when used in JBoss / Tomcat. Tomcat is appending a charset=UTF8 that appears to stop chrome’s built in PDF reader from loading (Chrome 11). Not setting the content length appeared to help while surprisingly not breaking IE.
Also with JBoss and authentication a no-cache header is added and the Restlet framework doesn’t remove it (even if you add your own Cache-Control header). See here for a way to disable this behaviour.

Macbook Pro intermittent black screen

I have an old Macbook Pro (2008) running Leopard that was having intermittent black screens during operation that wouldn’t go away (not ever after a reboot). The external DVI port would still work, and I passed the GPU tests related to the Apple Nvida GPU issues (TS2377).

My fix was to change the screen resolution via an app called cscreen. It’s hard to find the .dmg file, but not too hard. I wrote some apple script that changes the resolution and colour depth, compiled it as an application and put it in my applications directory. This way I could find it in the “dark” with spotlight by pressing command-space then typing my app name and pressing enter. Interestingly enough sometimes just pressing command-space would bring the screen back to life (but nothing else seemed to).

Glad to have a work around, but it still seems a weird issue.

The link to the article that go me on to cscreen is here.

Update:┬áThis solution didn’t last long and the laptop died – I suspect it was the known GPU issue with this model, but Apple denied it (Sydney Apple store) and can’t run the tests as the laptop is dead. Sniff.

Determining GWT Version from jar sizes

I ran into a few cases trying to build a GWT project that does not clearly state which GWT version it uses. AFAICT the gwt-servlet.jar doesn’t give any clues in the manifest or else where.

Here’s a list of versions of gwt-servlet.jar and file sizes (KB):

  • 2.0.0 – 1,524 KB
  • 2.0.1 – 1,535 KB
  • 2.0.2 – 1,538 KB* see below – 1,574,024 Kb,
  • 2.0.3 – 1,558 KB* see above – 1,574,034 Kb
  • 2.0.4 – 1,538 KB
  • 2.1.0 – 2,776 KB
  • 2.1.1 – 2,906 KB
  • 2.2.0 – 4,280 KB
  • 2.3.0 – 4,889 KB

Prior to 2.0.0 there is a separate version for Win/Mac/Linux

Got any others to add?

Selenium pressing or sending End and Home Keys

Quick one: To enumlate the end and home key presses you can use:

selenium.keyPress("somelocator...", "35"); // end
selenium.keyPress("somelocator...", "36"); // home

I need this for a GXT 2.2.3 TreePanel that has nodes that are off the screen (overflow) as GXT nodes are not rendered until they are scrolled into view. This workaround renders all the nodes in the tree.