Tuesday, May 20, 2008

com.sun.rowset.CachedRowSet pains

Yesterday I came across a nasty NullPointerException in the com.sun.rowset.CachedRowSetImpl class. The application has used rowset.jar for over a year now when using Spring JdbcTemplate, and it has been working as it should. Suddenly when deploying to WebSphere 6.1 we got

java.lang.NullPointerException
at java.util.Properties$LineReader.readLine(Properties.java:404)
at java.util.Properties.load(Properties.java:332)
at java.util.PropertyResourceBundle.(PropertyResourceBundle.java:110)
at com.sun.rowset.JdbcRowSetResourceBundle.(Unknown Source)
at com.sun.rowset.JdbcRowSetResourceBundle.getJdbcRowSetResourceBundle(Unknown Source)
at com.sun.rowset.CachedRowSetImpl.(Unknown Source)
at org.springframework.jdbc.core.SqlRowSetResultSetExtractor.newCachedRowSet(SqlRowSetResultSetExtractor.java:83)
at org.springframework.jdbc.core.SqlRowSetResultSetExtractor.createSqlRowSet(SqlRowSetResultSetExtractor.java:65)
at org.springframework.jdbc.core.SqlRowSetResultSetExtractor.extractData(SqlRowSetResultSetExtractor.java:49)
at org.springframework.jdbc.core.JdbcTemplate$1QueryStatementCallback.doInStatement(JdbcTemplate.java:393)
at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:342)
at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:403)
at org.springframework.jdbc.core.JdbcTemplate.queryForRowSet(JdbcTemplate.java:446)


A year ago the project was using Sun JDK 1.4, which does not include the com.sun.rowset package. Sometime last year we upgraded to Sun JDK 1.5, and no one thought of removing the rowset.jar from the runtime classpath. Each developer runs the application on JBoss, and the rowset.jar has not caused any trouble here. The application is deployed as an exploded EAR in development.

When packaging for WebSphere the rowset.jar was put in /lib directory in the EAR, and the developers assumed that the IBM JDK 1.5 did not contain the com.sun.rowset package. Shmack, there the NullPointerException reared its ugly head.

Inside rowset.jar, there is a property file called com.sun.rowset.RowSetResourceBundle.properties that is loaded through this little nasty piece of code in com.sun.rowset.JdbcRowSetResourceBundle:

private JdbcRowSetResourceBundle()
throws IOException
{
Locale locale = Locale.getDefault();
String s = locale.getCountry();
if(!s.equals("") && !s.equals("US"))
propResBundle = new PropertyResourceBundle(Thread.currentThread().getContextClassLoader().getResourceAsStream("com/sun/rowset/RowSetResourceBundle_" + s + "." + "properties"));
else
propResBundle = new PropertyResourceBundle(Thread.currentThread().getContextClassLoader().getResourceAsStream("com/sun/rowset/RowSetResourceBundle.properties"));
}


I am living in Norway, so the code will actually be trying to load com.sun.rowset.RowSetResourceBundle_NO.properties which of course is not provided in the rowset.jar file. I really hope the developer at Sun who made this has a real good explanation for writing this.

Well, today we discovered that the IBM JDK 1.5 does provide the com.sun.rowset package, and the whole problem was resolved by removing the whole jar from the project. There is nothing like the good feeling when getting rid of som crappy code!

One of my peer project developers found this post that sat me off in the right direction. Especially the link to Ted Newards excellent ClassForName.pdf

BTW: http://del.icio.us/dagblakstad proved invaluable while resolving the problem and writing this post.

Wednesday, May 7, 2008

I'm now a Nokia Sportstracker Fan

The Nokia Sportstracker is one of the coolest thing around of you have Nokia GPS enabled phone.

Have a look at the combining with the Sports Tracker widget everyone can see that i'm not in very good shape.

In order to view the Nseries Widget you need JavaScript and Flash Player 9+ support