All Work and No Play

All work and no play makes Jack a dull programmer. And I just felt the dull pain of another stack trace from hell from my Java EE app server. There has to be a better way. So I ported the troublesome code to run on the Play framework, and it was all play. No stack trace from hell, just a few screens with clear error messages, and then sweet success.

I started blogging on the now-defunct site almost ten years ago. In my very first blog, I complained about the Stack Trace from Hell that you get from Tomcat, GlassFish, WildFly, and its ilk whenever you didn't do some fiddly-poo just so. And then you are condemned to hours or days of googling, checking stackoverflow, comparing each and every one of the dozens of little detail thingys against the spec, the online docs, and random blog posts, and eventually screaming at the top of your lungs, until finally, a trivial change makes it all work.

A couple of days ago, I got another one:

[2015-11-19T15:56:33.472-0800] [glassfish 4.1] [WARNING] [] [javax.enterprise.web] [tid: _ThreadID=26 _ThreadName=http-listener-1(1)] [timeMillis: 1447977393472] [levelValue: 900] 
  StandardWrapperValve[Application]: Servlet.service() for servlet Application threw exception
	at org.glassfish.jersey.message.internal.WriterInterceptorExecutor$TerminalWriterInterceptor.invokeWriteTo(
	at org.glassfish.jersey.message.internal.WriterInterceptorExecutor$TerminalWriterInterceptor.aroundWriteTo(
 etc. etc. etc.

In this case, I was trying to produce a JSON response, which should not, in theory, be a big deal. But Java EE uses JAXB for that purpose, which was designed for XML, not JSON. There is a way of using Jackson, by adding some obscure class in some obscure app config procedure. But apparently I didn't do the fiddly-poo just right, and the wet its pants with a NullPointerException. Did I get any clue where I messed up? No sir.

At Java One, where we Java Champions are invited for a breakfast meeting with Oracle execs, I grabbed the mike to ask the exec in charge of Java EE what he was going to do to vanquish the Stack Trace from Hell. He had never heard of it as being a problem. Later I asked Adam Bien, who really, really knows his stuff around Java EE, and he said, yes, that's an issue for beginners, but he is now telling people to use Payara instead of GlassFish, and it gives better error messages. I tried installing it, and I got exactly the same error message.

That isn't surprising. There are all these subprojects like Moxy and Weld, and they all are great when everything is just so, but they just don't see it as their job to tell programmers when they didn't cross their t's or dot their i's. And the Java EE spec isn't making them do it.

Imagine if the compiler worked like that. As long as your program is syntactically correct, it would emit correct bytecodes. But if you made any mistake at all, it would be ok for the compiler to throw a NullPointerException and die. You'd never get any work done.

So, I am a beginner whenever I need to try out something new. I work with beginners whenever I introduce them to Java EE. In my opinion, Java EE, and that means, every Java EE compliant app server, should be responsible for telling me the file name and line number of the artifact where some fiddly-poo was wrong. Otherwise, I am sorry to say, Java EE is going to have a hard time finding new adoptees.

I could have toughed this one out, like I did for the preceding ten years. But I decided to tough it out and port the stuff to Play instead. Did it work perfectly? Of course not. But every error message that I got showed me the file name and line number of the artifact where some fiddly-poo was wrong. And in a few hours I had something working that, at least for me, defies ten years of Java EE-fu.

I don't want to give the impression that everything about Play is wonderful. In particular, the Eclipse integration is quite terrible. (Sadly, that seems to be the new normal for Eclipse integrations.) But overall, so far, so good. I'll keep pushing it forward, and I'll blog about how it goes.