Even the jvm gets synchronization wrong sometimes

May 11, 2009 14:06

The JVM has the following code in DeleteOnExit.

static void add(String file) {
synchronized(files) {
if(files == null)
throw new IllegalStateException("Shutdown in progress");

files.add(file);
}
}

What would you expect to happen if files was null?


Sadly, it's not the useful error message telling you that a shutdown is in progress.

Instead you get a NullPointerException because you can't synchronize on null, it just doesn't work.

I suspect someone has just gone about adding synchronized blocks to all the methods in the object without looking at what they do.

Update: Ah, there's a bug about it, and it's fixed with newer JVMs, jolly good. http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6526376

Previous post Next post
Up