The Mute Design Pattern

Have you been writing a lot of code following the Mute-Design-Pattern™ lately? E.g. try { complex(); logic(); here(); } catch (Exception ignore) { // Will never happen hehe System.exit(-1); } There's an easier way with Java 8! Just add this very useful tool to your Utilities or Helper class: public class Helper { // 18395 … Continue reading The Mute Design Pattern

Let’s Review How to Insert Clob or Blob via JDBC

LOBs are a PITA in all databases, as well as in JDBC. Handling them correctly takes a couple of lines of code, and you can be sure that you'll get it wrong eventually. Because you have to think of a couple of things: Foremost, LOBs are heavy resources that need special lifecycle management. Once you've … Continue reading Let’s Review How to Insert Clob or Blob via JDBC

Inadvertent Recursion Protection with Java ThreadLocals

Now here's a little trick for those of you hacking around with third-party tools, trying to extend them without fully understanding them (yet!). Assume the following situation: You want to extend a library that exposes a hierarchical data model (let's assume you want to extend Apache Jackrabbit) That library internally checks access rights before accessing … Continue reading Inadvertent Recursion Protection with Java ThreadLocals

How to Execute Something Multiple Times in Java

When writing unit / integration tests, you often want to execute something multiple times, with different configurations / parameters / arguments every time. For instance, if you want to pass a "limit" or "timeout" or any other argument value of 1, 10, and 100, you could do this: @Test public void test() { runCode(1); runCode(10); … Continue reading How to Execute Something Multiple Times in Java