Exploring Thoughtz..

Change in behavior in Timestamp.valueOf() in JDK 6

Posted by: Vijay Dev on: October 21, 2009

Recently, when looking at a bug related to Timestamp, I found out that the valueOf() method in java.sql.Timestamp works differently in JDK 6 than the earlier versions.

Timestamp.valueOf(), when provided with a timestamp which contains a date or a month with a single digit. eg. 2009-9-20, 2009-9-3, 2009-12-4 etc., behaves differently in JDK 6 – it throws an IllegalArgumentException saying that the timestamp is not properly formatted. Whereas JDK 5 (and earlier versions) works just fine providing the proper values with ‘0′ prefixed to those single digit numbers. However JDK 6 is fine with hours, minutes, seconds being single digits. As usual, got curious and started exploring why this happens by looking at the source code for the Timestamp class in JDK 5 and 6.

Here’s the JDK 6 Timestamp.valueOf() snippet:

int counterD = 0;
int intDate[] = {4,2,2};

int counterT = 0;
int intTime[] = {2,2,12};

while(stringTokeninzerDate.hasMoreTokens()) {
String tokenDate = stringTokeninzerDate.nextToken();
if(tokenDate.length() != intDate[counterD] ) {
throw new java.lang.IllegalArgumentException(formatError);
}
counterD++;
}

/*
//Commenting this portion out for checking of time

while(stringTokeninzerTime.hasMoreTokens()) {
String tokenTime = stringTokeninzerTime.nextToken();

if (counterT < 2 && tokenTime.length() != intTime[counterT] ) {
throw new java.lang.IllegalArgumentException(formatError);
}
counterT++;
}
*/

The code in bold shows that there is a strict check on the length of the digits that constitute the datepart of the timestamp. The commented out source is the reason why the format of the digits in the time part is not strictly enforced.

I thought it’s good to dig more into this and asked in Stack Overflow and people helped out in identifying more details: The behaviour is already filed as a bug and more info about the bug was found here. A workaround for this problem is available here.

What is debian-sys-maint?

Posted by: Vijay Dev on: October 11, 2009

Recently, when we were moving our staging applications and databases to a different server (from Win 2003 to Ubuntu 9.04), we had two problems with the MySQL server.

One, easy to fix, was the case-sensitive nature of table names. Using lower_case_table_names=1 in /etc/mysql/my.cnf fixed the problem.

The other problem riddled the server startup and shutdown (even server status) with errors, even while keeping the server functional. When looking into the error messages, I found out that there is a special MySQL user named ‘debian-sys-maint’ which has admin privileges. This account is used to shut down the server gracefully, to check for corrupt tables etc. The password for this account is stored in plaintext in the file /etc/mysql/debian.cnf.

Error message obtained:

/usr/bin/mysqladmin: connect to server at ‘localhost’ failed
error: ‘Access denied for user ‘debian-sys-maint’@'localhost’ (using password: YES)’

Fix:

GRANT ALL PRIVILEGES ON *.* TO ‘debian-sys-maint’@'localhost’ IDENTIFIED BY ‘<password>’ WITH GRANT OPTION;

where <password> is the plain text password found in /etc/mysql/debian.cnf. Found the fix here.

Two Months

Posted by: Vijay Dev on: September 13, 2009

Been inexplicably away from blogging for a long time (except for the birthday post) – it had been a tough month and a half in various aspects. Meanwhile, Ananth went to SA for a project implementation and those two weeks were boring without him to chit-chat with. He returned to India on my birth day and we had good fun that day with a late lunch at Woodlands, watching “Up” and what not !

On the technical side, I have got bitten by the Flex bug which is quite dangerously spreading in my team!! I am also starting to learn Ruby on Rails. I like Rails more than Flex and I might work on both these technologies in the coming months. Top Secret :P

Work is otherwise monotone for sometime now with nothing interesting/challenging coming on the way. Anyway, enjoying what I do and trying to learn something out of whatever I do.

Last two months also saw an Increase (note the caps) in watching movies. Watched several films for the first time in life – Matrix, Lord of the Rings, Enemy at the Gates, Up, Dark Knight, Shrek to name a few.. Thanks to Manu and Karan.

Lord of the Rings – I must write about this magnum opus. Manu told me that it’s the best movie adaptation of a book ever and refused to give me the movies until I read the book and he bought me one (thanks dude!). By the time I finished the book, I was already blown away at the fantasy and the imagination. And the movies did not fail the expectations. All three were magnificent, especially the last one – Return of the King !!

I have been searching for a book for long (which I read in a local library at the age of 10 or 11) and finally got it yesterday at a book shop in T Nagar. “Thiruvarangan Ula” – a fascinating historical novel – is one of my most favourites and glad that I got hold of a copy of this 4-part book and have already finished the first part :)

As always, would love to get back soon :)

It’s XXIII !

Posted by: Vijay Dev on: August 29, 2009

Having got curious about the mathematical properties of the number 23, I started exploring and here’s what I found interesting from what I have seen on the web:

  • 23 is the smallest prime number with consecutive digits.
  • 23! is 23 digits long.
  • 23 = 14 + 23 + 32 + 41 + 50
  • 1023 – 23 = 99,999,999,999,999,999,999,977 is the largest 23 digit prime.
  • According to the birthday paradox, in a group of 23 (or more) randomly chosen people, the probability is more than 50% that some pair of them will have the same birthday (are we not coming to the topic now ?!!)

Oh by the way, Happy XXIIIrd to me :-)

Tags:

Easy Bookmark of Hacker News Links

Posted by: Vijay Dev on: August 2, 2009

It took me five months to get my hands on GreaseMonkey again. This time again, it’s a pretty simple script – In Hacker News, provide a bookmark link near each news item. I needed this one badly since I always open certain items only to bookmark them for future reading. The script can be found here.

Another Super Saturday!

Posted by: Vijay Dev on: August 1, 2009

A well spent Saturday and a refreshing break from the work madness :-) Enjoyed bowling with the team at Blur and then had some nice time at Manu’s home (the mushrooms he cooked are really good :P ). Played some games in Wii for the first time, saw LOTR – Fellowship of the Ring and much more !

HDFC Mobile Recharge – An Experience

Posted by: Vijay Dev on: July 21, 2009

Recently, I found a service that HDFC Bank provides to recharge prepaid mobile phones in India. The service, listed here, is available for use via NetBanking or an ATM. Super cool, eh? Yeah, if only it works fine without any glitches !

The interface is quite simple and intuitive to use. Users just need to enter their mobile number and the amount and confirm the transaction. The next page informs the users that their request is being processed and that the server may take about 1 to 5 seconds to process. There is also a point informing users not to submit again and not to use the Back or Refresh buttons in the browser. Well, that’s pretty good so far.

Now starts the excitement! The form never gets submitted. Wow! I can see a JavaScript error in Firebug console.

Being a developer is so much fun :P Looking at the source, I found that this JS function gets called after a timeout of 5 seconds.

function go_now ()
{
form1.action="https://netbanking.hdfcbank.com/netbanking/merchant" ;
//form1.action="https://flexatsup.hdfcbank.com/netbanking/merchant";
form1.method="post" ;
form1.submit() ;
}

And nowhere is form1 defined and Firebug faithfully reports this error.

form1 is not defined
form1.action=”https://netbanking.hdfcbank.com/netbanking/merchant” ;

So what do I do? Well, I write a few lines in the FB console to submit the form myself. The variable form1 happened to be document.getElementById(‘form1′) and got submitted without any further errors. After this submission, the redirection happens to the NetBanking page properly and from thereon, there are no problems and the mobile recharge happened successfully !!

Personally, the errors apart, I like this facility as it saves me a lot of time and hassle. And I can always write a GreaseMonkey script to automate this submission :-) But how on earth are these errors still not detected and fixed by concerned people? Is it proof that not many are using such facilities in India?

UPDATE: I have never checked this feature in any browser other than Firefox. The error does not occur in IE, since it is not mandatory to get the reference to the element by calling getElementById() in IE. The elementName.property will work just fine. This is one more glorious example of IE not following proper standards! Thanks Manu..

Blog Stats

  • 22,081 Visitors

  • Yann: Hello! Could you expand your example for the a bit not-so-hapy java users like me, and describe how to compile and run your code? That would be awesom
  • Anuraj Pandey: Some one is mis-using my id..i got the notification of the above comment..however i havent posted the comment :(
  • Anuraj Pandey: if u have some kind of pdf/text of the material u removed..it will be highly appreciable if u help me..i have my first google intern telephonic interv

My Tweets

About Me

Journey so far…