XFCE all up in your face

After being in beta and release candidates for several months, XFCE 4.4 is finally released. Not only that, but ebuilds for them are willing and ready to go. woot.

All the extra panel plugins and extra utilities have been updated as well. In addition, there have been some new additions for 4.4. Use xfce-base/xfce4-extras to get them all, or choose them piece meal out of xfce-extra/.

We’re also in the process of establishing an XFCE project for reals, instead of just being having a herd. With the creation of a project, you need a project lead. Who will it be? Well, the consensus seems seems to be your truly.

Dealing with libraries that like breaking their APIs

I’m currently working on making use of a Groovy on a project of mine which uses Hibernate and Spring among other things.

My code wasn’t particularly well tested in terms of unit tests. By this, of course, I mean there were no unit tests.

So like a good code monkey, I decided to get some unit tests going, verify they work, then move code over to use Groovy. The benefit here being that by having these tests, I can verify that things still work as expected after the migration.

I figured on trying out rMock, one of the many mocking libraries out there for Java. I get my first test case written, cross my fingers, and hit the run button (this is in Eclipse)… and what do I get, but the infamous red bar. NoClassDefFound… WTFBBQ?!? For whatever reason, it wasn’t finding certain classes from dev-java/asm.

I won’t go into further detail about how I found this problem, and found the cause, but here are my findings (versions here refer to slots):

  • dev-java/groovy uses dev-java/asm-2.2
  • dev-java/hibernate uses dev-java/cglib-2.1
  • dev-java/rmock uses dev-java/cglib-2.1
  • dev-java/cglib-2.1 uses dev-java/asm-1.5

The issue here is that asm apparently changed it’s API quite a bit between 1.x and 2.x. This problem seems to have cropped up a few times at least according to google (search for ‘NoClassDefFoundError: org/objectweb/asm/CodeVisitor’).

The asm tutorial even goes so far as to the changes… kind of. See here under the “Changes in the ASM 2.0 API Since ASM 1.x” section. A few things bother me about this.

  • I don’t see why the major changes, like renamed classes, and changed method signatures, couldn’t have been deprecated at first, and do some twiddling to proxy calls to deprecated things to the newer ones.
  • The line that goes like “In general, it would be a good idea to run tool like JDiff and review the differences between the ASM 1.x and 2.0 APIs.” Maybe it’s just me, but this seems a bit presumptious. I mean, while such a tool is probably useful, it is far from thorough. It might point out where the API changed, but would have no clue as to the significance of those changes, or how you would account for them.

A question that might come out is why would rmock expose this problem, when hibernate is using the same version of asm? Presumably it is because hibernate isn’t exercising the parts of the cglib API that use the offending parts of asm, so I must have lucked out before now.

Regretfully, this seems somewhat common in the Java world. Maybe not very common, or even common, but common enough that they stick out in my mind, causing a handful of angst and frustration.

There is some good news though. cglib-2.2_beta1 seems to have been updated to use the asm-2.x’s API. Another bit of fortune is that it’s unlikely that anything in the tree will run into this particular snaggle, just code monkeys like me using these various libraries.

For the record, I don’t get the ClassDefNotFound anymore, but instead I get a lovely NullPointerException from down in Groovy. Oh well, one step forward, one step back.

Java gets Groovier

This news is a bit belated by a few days but…. over the weekend, I spent some time getting the recently released Groovy 1.0 into the tree.

In case you hadn’t heard about it, Groovy is, among other things, a dynamic language that runs on the the Java VM. Some interesting data points about it:

  • It’s dynamic, for reals.
  • It’s about 98% syntax compatible with Java code (I made that number up, but really, it’s pretty durn close).
  • Java bytecode gets generated at runtime, no need to compile.
  • Groovy can generate Java bytecode to your typical .class files

A consequence of these points is that you can easily migrate from Java to Groovy, and have your project running exactly as it was. Then slowly, you can get into the swing of things, and take advantage of everything that Groovy has to offer as you get the hang of it.

One fear I’ve noticed of Java developers of jumping into a more dynamic language like python or ruby is late binding. You can’t really be sure the type of your objects until runtime. Sure, you can read the documentation (assuming it’s up to date) or peek at the code to be sure. With Java, binding occurs at compile time, so you can be sure that foo method expects a Bar, or that Bar has the aieeeee() method. I suspect some of this comes from defensive coding, where you become concerned about how your code will be (ab)used by others.

To combat this, a coworker and I have this idea… You use Java to define interfaces for the, uh, interfaces you care about. You can then use Groovy to implement these interfaces. By doing this, you get the best of both worlds: clients of your code get their strongly typed interface, and you get to do implementations with a more expressive syntax.

Overall, I’ve been pretty impressed with Groovy so far. Granted, I haven’t used it as deeply as possible yet, but it certainly has a lot of potential.

In case any of this sounds interesting, here’s some resources:

And in other Java dynamicism news, I’ve added the freshly minted JRuby 0.9.2 to the tree this past weekend as well. I haven’t played with it yet, so I can’t speak much on its behalf other than it’s an implementation of Ruby written on the Java VM. Perhaps that can be the topic for a future blog post.