AutoCloseable when not available
On his blog, Brian Oxley shows a neat way in JDK 8 to use non AutoCloseable object having a close-like method in a try with resources construct, using the new method references. For those of us who are...
View ArticleGet Simple Class Name
You probably heard of one method of Class that give the simple name of the class, without all the packages. Even if you hadn't, you probably know a simple way to get the sub-String following the last...
View ArticleFIFO Stack and LIFO Queue
Recently, I found this class in one of our applications:publicclass FIFOStack extends Vector {publicsynchronized Object push(Object o) { add(o);return o; } publicsynchronized Object pop() {if...
View ArticleWhy don't I know my disk is full?
We had this interesting problem lately, that an application had a corrupted file after a disk got full. The strange thing was that the app did not know that the disk was full. We were expecting an...
View ArticleCapital Date Mistake
Here is a small piece of code. Can you tell what it prints? SimpleDateFormat sdf = new SimpleDateFormat("YYYY-MM-dd"); Calendar cal = Calendar.getInstance(); cal.set(Calendar.YEAR, 2014);...
View ArticleJava 8 Compilation Strangeness
A colleague of mine (thanks Clement) showed me some strange issues his team met when they decided to move their project to Java 8. These issues did not appear while compiling with Eclipse, but showed...
View ArticleAutoclose Lock
I was just wondering if there is a difference between the classic: lock.lock();try { //I have the lock! } finally { lock.unlock(); } And the Autocloseable version: lock.lock();try (AutoCloseable auto =...
View ArticleThou Shall Close Thy Streams
You should always close your IO streams. Said like this, it sounds obvious. But in the light of some new Java 8 features, it took me some time to get around it.I needed to write a small method for...
View ArticleBoolean Parsing Fest
A small gem I found the other day: String value = ...boolean booleanValue = Boolean.valueOf(value.toLowerCase()).booleanValue(); A lot of useless stuff: toLowerCase is useless because the Boolean class...
View ArticleLambda Before Switch
We had this method that was doing the same thing several times in a row. Here is a simplified version:void resolveAll() { a = resolveA();if (a == null) states.remove(State.A);else states.add(State.A);...
View ArticleCollectors.toMap does not like null
Some map accept null values, some don't. How do you know? You usually take a look in the javadoc. But what about maps created by streams through the Collectors.toMap? The javadoc does not say. So I...
View ArticleSee you at Devoxx Paris
I'm in! The quickie I proposed to the Devoxx Paris comitee was accepted. It is called "The Thread Awakens". Maybe there were some Star Wars fan in the decision process?
View ArticleLog content of SOAP message
It's probably all over StackOverflow, but lately I had to log the XML content of SOAP messages for debugging. I did it this way:publicvoid connect() { Service service = ... List<Handler>...
View ArticleJava 8 might kill doclint
Since Java 8, javadoc doclint became a lot stricter. Up to now, we had some warnings here and there. But since we moved to Java 8, our Jenkins releases are failing because doclint would throw HTML...
View ArticleRocket Anti-Pattern
At my presentation at Devoxx Paris this year, The Thread Awakens, I introduced several Patterns related to multithreading. Since it was a quickie, I had only 15 minutes to talk about 15 Patterns. That...
View ArticleParatrooper Model
In my previous entry, I was describing the Rocket Anti-Pattern, where one thread would handle too much work across several application layers, leading to communication buffer overflow and message...
View ArticleMarsupilami Pattern
In my previous entry, I described the Paratrooper Model, where each application layer would have its own thread pool for handling data. And the way to implement that is to use the Marsupilami...
View ArticleIndian Train Anti-Pattern
Last time, I talked about the Marsupilami Pattern, where we introduced queues to transport data between application layers.Now you’ve been using these queues for some time, conveying all sorts of data,...
View ArticleIndiana Jones Pattern
In my previous entry, I presented the Indian Train Anti-Pattern, where we added without discrimination data to be handled on our queues, leading to overcrowded queues.One possibility to alleviate the...
View ArticleHamburger Pattern
Last time, I introduced the Indiana Jones Pattern, where you would filter your messages in order to send less data on your overcrowded queue.Another way to reduce the number of messages is to use the...
View Article