Hang-Man Bug

If your system inexplicably hangs …..

one reason might be you are trying to initialize a java.awt class on a server that does not run X.

Fun fact: I just read about this the other day on the forum for the library I am using and for which I need these awt-classes for!

*Added* and another problem I was having: it the programm is producing load the reason is probably not deadlocked threads. Think infinite loop!

Exception Handling

When I started working one and a half years ago, I knew a lot less about software development than I know now. This does not necessarily imply that I know everything now. But I think in the meantime I have learned a lot.

The latest acquisition in the field I made through my second code review where the reviewer came back and said “You need to look over your exception handling, you should not ….” he was absolutely right. Up to that point I had basically ignored exception handling and had seen exceptions as a necessary evil that came with the language. So I had done all kinds of funny things with exceptions, except one thing: handle them in a consistent way throughout my application and make them visible when they occurred.

The first changes with my attitude came about when I learned about assertions.


So that I will not have to search for a fix for this again.

The xsession must be started as a client of the ssh-agent. For this a file .xsession (plus ln -s .xsession .xinitrc) is needed with the following contents:

ssh-agent $HOME/.xsession.ssh

Secondly I copied the global /etc/X11/xinit/xinitrc to /home/yashima/.xsession.ssh. Then I added the command ssh-add to my gnome-session with the normal gnome config utility. Works. Done. Don’t need to do it again!

Addendum: some of the problems I was having with ssh seem to come from the “-i” flag … when I created new keys with default names and simply tried without specifying a key all of a sudden I was able to run stuff with “-2” that would not work before. Don’t forget to use “-a” when you test things on a remote computer otherwise your agent will screw up everything.

The “Keywords for Better Code” Initiative

The Do’s of programming. My favorite “code” improving keywords are:

# final: makes sure I don’t do stupid assignments, in combination with the compiler warnings “this variable may not have been assigned” a very valuable tool
# finally: close files, connections and clean up despite errors happening!
# throw (note: not throws!): exception handling, my last code review put me onto improving that
# assert: to keep myself from the most stupid things that could have happened
# else: if there is an if there should also be an else, just as with switch there should be a default.

in no particular order. When I am forcing myself to use those frequently the code becomes a lot safer and these are easily remembered. Any others?

Next: the Don’t’s of Programming 😉 (or whenever I get to that).

Unknown Java

A fact on java that many people do not realize: it is not trivial to actually “stop” a thread. All the methods like “destroy()” and the likes are depcrecated and have been for a long time because these methods are NOT safe to use.

I am currently in the process of finding out how to stop java from doing something like continuing an infinite loop nested deeply within a method call of a library. I’ll post my solution or the reason why it won’t work.

Addition: must correct myself “destroy” is not deprecated: it was never implemented. But “stop, resume and suspend” are deprecated. For those who think that by assigning “null” to the variable that you kept the reference to the thread in: go back to learning basic java principles. No not really: there is always a reference in some ThreadGroup object to all threads running. But everybody should know that assigning “null” to something is code smell or rather stink!