POTD: ExceptionInInitializerError logger

It’s been a while I’ve done a project of the day, but here it is, the fruit of my yak-shaving today. The problem I was trying to solve today was java.lang.NoClassDefFoundError: Could not initialize class Xyz. When a Java class fails to initialize, the first attempt to do that causes ExceptionInInitializerError, but subsequent attempts to…

POTD: random but meaningful name generator

I’m working on the automated blackbox acceptance tests for Jenkins, where I often need to generate random unique names. The code has been using random number generator to generate such names, but as I was debugging test failures, it became painful to remember those random names. For example, a test might create two new jenkins…

POTD: Application configuration via Guice binding + Groovy

Often I write my applications with Guice. I also often want to make those applications configurable externally. For example I might inject username and password for that app to talk to another app, I might configure some timeout value, and so on. I make these configuration values available in Guice, so that I can access…

POTD: cucumber annotation indexer

Cucumber for Java requires that you specify the packages in which your step definitions exist. At runtime, cucumber uses some hack to try to list all the classes in this package (it’s a hack because class loaders never really support the listing operation), loads them one by one, and finds those that have step definition…

POTD: no more tears

In a modular Java program or in a large Java project that has lots of dependencies, you often end up a version of library that’s different from the version used to compile the code. This often results in LinkageError, where a method/field that was present when the code was compiled do not exist any more…

JavaFX needs to be a new edition of Java

Lately, there has been a number of security vulnerabilities reported in Java. The latest one is reported just after a few days of JavaSE 7u11, which by itself a response to another vulnerability. It’s so bad to the point that people are being asked to uninstall Java (yes, just in the browser, but let’s face…

COM4J updates

It’s been a while, but I’ve posted a new version of COM4J. COM4J is a library that lets you talk to Windows COM components. Unlike similar libraries lika jacob, which makes you feel like you are working with reflection, COM4J is designed to work with type-safe annotated interfaces, which makes you feel like you are…

Debian and Maven, a crash of culture

Tim O’Brien posted his frustration about the state of Java packaging in Debian. While I’m not affiliated with Debian nor Ubuntu, I wanted to post something in defense. I completely understand where Tim is coming from. To the eyes of Java developers, the Java packaging in Debian looks completely Sisyphean. We got all the binaries…

@Override and interface

Jim Leary, my colleague at CloudBees, got me into digging into this. The question is around putting the @Override annoation on a method that implements an interface method, like this: public class Foo implements Runnable { @Override public void run() {} } As you can see in the javadoc, when @Override was originally introduced, such…

Quiz answer: memory leak in Java

I posted a little quiz yesterday, and here is the answer. The short answer is that InputStream needs to be closed. It’s easy to see why if it’s FileInputStream because you know the file handle needs to be released. But in this case, it’s just ByteArrayInputStream. We can just let GC recycle all the memory,…

Quiz time: memory leak in Java

Today I had an interesting debugging exercise, and I felt like I learned a new lesson that’s worth sharing with the rest of the world. I had the following code, which takes a small-ish byte array and deserializes it into an object (let’s say someNotTooBigData is something like new byte[]{1,5,4, … some data… }.) Seems…