Never throw a NullPointerException. Ever.
Submitted by struppi on Tue, 2009-08-25 15:28. JavaNullPointerExceptions (NPEs) happen in Java. They indicate that the VM tried to de-reference a null - value. And that's OK. But it is not OK to write code like this:
if(someVariable == null) {
throw new NullPointerException("The value of \"someVariable" must not be null");
}
It is not OK to write code like this for 3 reasons:
- As I said before, the NPE indicates that some part of the program tried to de-reference a null value. This did not happen here.
- The exception class you use should indicate what happened. Otherwise we would have only 2 Exception classes in Java: Exception and RuntimeException.
- NPEs indicate a programming error and are quite useful to find bugs. You compromise this when you throw them for "normal" errors.
As for the second point: I can think of two reasons why the null value is not allowed here. The first would be that null is an illegal value for an argument of your method. Use "IllegalArgumentException" in this case. The other reason is that a null value would cause an illegal program state. In this case you can use "IllegalStateException". If both scenarios do not feel right for you, create your own exception class.
(Just another rant. Everything IMHO. This post is somewhat related to Exception Abuse. And yes, there is a reason why I wrote this.)
JSXP 0.3 Released
Submitted by struppi on Wed, 2009-06-24 08:02. JavaWe have just released Version 0.3 of the JSXP web framework for java. The main improvement is the new validation architecture, and some minor bug fixes.
JSXP Community Pages
Submitted by struppi on Tue, 2009-06-16 16:08. JavaWe have just created a new JSXP community website: jsxpcommunity.org. So far it hosts several JSXP-related forums and the project mailing lists. There might be more content in the future.
JSXP 0.2 Released
Submitted by struppi on Tue, 2009-06-09 12:20. JavaWe have just released version 0.2 of JSXP - the simple web framework for Java. This release contains great improvements in the view flows implementations, and some minor bug fixes.
JSXP 0.1
Submitted by struppi on Wed, 2009-06-03 18:01. JavaOliver Szymanski and I released JSXP 0.1 today. JSXP is a web application framework for Java. It's main features are: Compile-time safety when accessing elements of the pages, simple XHTML design, component orientation, human readable URLs, automatic server side state, and more.
AndroHUD - A heads up display for Android
Submitted by struppi on Thu, 2009-05-28 13:04.I have just published my first little Android application: AndroHUD - A heads up display (HUD). It's really just playing around with the sensors a little bit, but the application also has some useful features:
AndroHUD is a simple heads up display (HUD) which displays your speed, heading, altitude, pitch, roll and the current g-Forces. You can activate a mirror mode if you want to put it at the dashboard of your car. You can also configure speed warnings: The HUD will warn you when you exceed certain speeds.
Openbakery Translation 0.3
Submitted by struppi on Tue, 2009-03-17 16:49.There is a new version of openbakery translation. The changes include:
- All properties files for a given locale are now grouped in a folder for the locale.
- All translations have a context now, the default context is the class where the "translate" statement was written.
- The java file parser is more sophisticated now.
- Singular/Plural translations are now supported.
- Lists of stuff can now be translated and the translation checker can recognize it.
- Re-Written documentation with shorter, simple examples.
You can get the newest version and documentation from the project page at openbakery.org.
Apple Bugfixing
Submitted by struppi on Fri, 2009-03-06 10:11. AppleI filed this bug on 11-Apr-2007 (almost two years ago):
Title: Safari doesn't handle HTTP Content-Type header 11-Apr-2007 07:18 AM David Tanzer: Summary: A HTML page which has the extension ".tar.gz" is automatically downloaded, even if the HTTP Content-Type header is "text/html". For example, the HTTP Headers for the page http://www.apache.org/dyn/closer.cgi/geronimo/2.0-M3/geronimo-tomcat6-jee5-2.0-M3-bin.tar.gz (which is a HTML page with the mirror list for the file) is automatically downloaded and NOT displayed as it should. The content type for this page is: Content-Type: text/html; charset=iso-8859-1 Steps to Reproduce: 1. Open the page http://www.apache.org/dyn/closer.cgi/geronimo/2.0-M3/geronimo-tomcat6-jee5-2.0-M3-bin.tar.gz Expected Results: The mirror list for geronimo 2.0-M3 is displayed Actual Results: The html file is downloaded and saved to the Desktop Regression: N/A
It is still open, and the problem still exists in Safari 3.2.1 (5525.27.1). Good job, Apple.
Openbakery Translation Engine 0.2 released
Submitted by struppi on Wed, 2009-02-11 09:31. JavaI have just released the second version of the openbakery translation engine, which contains major feature enhancements:
- Added support for multiple properties files: Now all properties files for the given locale are searched for translations (important for larger projects).
- Better support for hierarchical locales: TranslationChecker now creates a list of indirectly defined translations.
- Multiple calls to initialize are now allowed: All translations from all referenced properties files are searched when translating a string.
- Enhanced output of TranslationChecker: It now tells you where it found a translation (the class or the properties file).
You can find a detailed example at the project page of openbakery translation.
Openbakery Translation Engine 0.1 released
Submitted by struppi on Mon, 2009-02-09 15:46. JavaYesterday and today I created a translation engine for java which has several advantages over the default i18n using resource bundles:
- The text in the default locale is the key for the translation
- There is no properties file for the default locale, only for translations
- There is a tool which analyzes a source tree and finds all translations which are missing in a certain properties file
- This tool also finds entries in the properties file which are not used anymore and can be removed
Usage is really simple, you just call a static "translate" - method:
translate("This string should be translated"); //Simple translation
translate("This string has parameters: {0} and {1}", "Foo", "Bar"); //Translations can be parameterized
translate(File.class, "Open"); //Translations can have a context, which is the name of a Java class
You can find a complete example, download links, the bug tracker, and other information on the project page at openbakery.org. There is also a freshmeat project page for the project which should be available soon.





