Tuesday, March 4, 2008

Feb 29, A bad day for apache ftpclient users

The below post was written on February 29 and I forgot to post this after writing it ! hence posting little late.

I am writing this blog after being severely hit by apache ftpclient bug on February 29.
Unsurprisingly the bug has hit the whole world of apache ftpclient users and there were number blogs immediately started popping up.

By abstract this is the bug all about. When the ftpclient parses the files one by one, it validates the file timestamp. In Unix system it gets the file properties and the date will have the MMM HH:mm if the file is less than 6 months old. Since there is no year in the time stamp string, ftpclient parses it with year 1970 (Well done !) which of course is not a leap year. So Feb 29 is not a valid date in 1970 hence this code segment in class UnixFTPEntryParser returns null.

try{
file.setTimestamp(super.parseTimestamp(datestr));
}catch (ParseException e){
return null; // this is a parsing failure too.
}

There are many temporary ugly fixes based on your requirements ;) For me , I just needed the files to be downloaded, so I catch the exception and if the date string has "Feb 29" and the current year is leap, I just set a Feb 29 time and return the File instead of NULL.

But people who needs correct time stamp will have to a bit of extra work. This link discusses about possible fixes and implications.

The good thing is we have another four year time to fix this problem !!!