July 10, 2008

Class file '...' is broken

Nope. Nothing is broken. Just missing. Scala 2.7.1 emits this slightly misleading error message when a dependency is missing. I suppose this then "breaks" the dependent class, but only from the point-of-view of the compiler, not from the point-of-view of the developer.

For example, I'm using net.spy.memcached, but I only placed memcached-2.1.jar in my classpath, and not the sub-dependency spy-2.4.jar. The error returned is:

error: error while loading MemcachedClient, class file '../third-party/java/memcached-2.1.jar(net/spy/memcached/MemcachedClient.class)' is broken
(class net.spy.SpyThread not found.)
SomeClass.scala:13: error: net.spy.memcached.MemcachedClient does not have a constructor
val c = new MemcachedClient(AddrUtil.getAddresses(h, p));

The actual problem is described sotto voce: "(class net.spy.SpyThread not found.)". But, instead I foolishly focused on "class file '...' is broken". Broken is much stronger than not found, and these jars were new to my repository. So, I went around verifying the integrity of the .jar file, missing the main point of the message.

This has been a common theme in my experience thus far: Scala compiler errors need a bit more honing. They sometimes lead my Java and gcc eyes astray. I have to slow down more and re-read the compiler output.

4 comments:

Robey said...

Scala errors often remind me of jikes errors from the early days of jikes: excessively wordy in the cases where they don't need to be; maddeningly terse in the confusing cases.

Unknown said...

You may be happy to know that I have just checked in a fix for this awful error.

Before: class file 'Foo' is broken

After: Missing dependency 'class javax.transaction.Synchronization', required by Foo

Stephan.Schmidt said...

Using not the latest Scala because of Maven using 2.7.3, I got the same error and it took me some hours to find the reason (yesterday).

Cheers
Stephan

Shikhar said...

Ahhh... thank you! Wouldn't have figured this out without your post.