The following might be totally obvious, but to me it was a revelation, so why not publish it. :-)

There are situations when you have methods returning a collection.
A Java collection can be a set (no sorting, no duplicates), a list (sorting, duplicates) or a map (association key/value).

In some cases, the method might fail.
To have robust code, you would still like to return an empty set, list or collection instead of null.

Read more…

Strings in the D programming language (and in many other languages too) are stored as an array of characters. Sometimes you might forget that you are still working with an array. The following code for example might result in unexpected behaviour.

char[] a = “foo”;
char[] b = “foo”;
a[0] = ‘x’;                    // access violation (Linux)
Stdout(a ~ ” “ ~ b).newline(); // outputs “xoo xoo” (WinXP)

Read more…

I’ve had an interesting problem with FileOutputChannel and RandomAccessFile from Java NIO.

If I understand the API correctly, it is enough to position(pos) on a FileOutputChannel and then use transferFrom

However transferFrom always returned 0. Then I used setLength on the RandomAccessFile where the FileOutputChannel was derived from and then it worked.

This was for Java 1.6 developer preview on OS X 10.4, maybe it is not even a Problem on other systems.

Maybe you know the situation: you are developing a web application using the Maven build system along with an application server like Tomcat or Jetty and a corresponding plugin (e.g. the all famous jetty-maven-plugin).

One of the coolest features of these containers is the hot-deployment.

However, every second time a hot deployment is executed, it crashes due to a PermGen space Exception or a similar OutOfMemoryException.

Read more…

When playing around with the positions of Windows in Java, I have found a nice Java function: setLocationByPlatform of the Window class enables you to let your JVM choose the position of a new Window. This means that all windows won’t be placed at x=0 and y=0 but will be overlapped according to what your platform thinks is nice.

Recently I stumbled across a problem with the rich:modalPanel component of the JBoss RichFaces component library, which didn’t want to show the data of a backing been.

Let’s assume the following scenario:
You have a DataTable with several rows. Each row contains a “See details…” button. This button will popup a modal panel using rich:componentControl and the panel is populated with data of a backing bean. This backing bean is filled with actual data by clicking our “See details…” button using a4j:actionparam

Read more…

For p300, I am currently using a Selector to check if I can read from or write to a socket.

However, this has lead me to a weird problem: select is called for at most 30 seconds and I get a timeout for writing even though this can’t really be and only happens with some OS combinations. I’ve found this thread in the Sun Forums and adapted my internal logic to the information from this forum thread:

Instead of always selecting for OP_WRITE when I want to write, I just try to write. If I was not able to write everything (that is, buffer.remaining () is bigger than 0) I select for OP_WRITE.

This seems to work fine.

I sometimes get this error in the J2EE (or JEE) module settings in the project options when changing modules. The settings will not even show what modules are chosen.

Read more…

I think I have spent at least 5 hours to get a selectManyCheckbox working properly in JSF. I was getting validation errors and other trouble.

However I have found a great source of information. Also, on some other websites you can read that you should use an array instead of a List for the getter/setter of the backing bean.

Maybe this helps…

I’ve recently spent some hours to track down a mysterious bug and I just couldn’t find it. Since my application is using a lot of Threads/Workers it came to my mind that a RuntimeException I did not catch could be the cause. I wrote a global handler for it and found where the problem was :)

Read more…