This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
The moose likes Java in General and the fly likes Simple Date Formatter Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Simple Date Formatter" Watch "Simple Date Formatter" New topic
Author

Simple Date Formatter

Rimjhim Ray
Greenhorn

Joined: Jan 11, 2005
Posts: 9
The following piece of code

newValue = formatter.parse(new String("").trim(), new Pa
rsePosition(0));

returns null in java 1.4 but returns unix epoch time in java 1.3. Can any of you confirm if there has been such a major change in implementation of SDF from 1.3 to 1.4? If it has where can I find the documentation?

Cheers
Rimjhim
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24166
    
  30

First, note that

new String("").trim()

is the same as

new String("")

which is the same as

""

Second: I don't see anywhere in the Javadocs where it says that "" will be handled specially; it's not a valid date, so I'd expect null to be returned, regardless of JDK version. I think this code was relying on undefined behavior.


[Jess in Action][AskingGoodQuestions]
Steve Morrow
Ranch Hand

Joined: May 22, 2003
Posts: 657

There seems to be a resurgence of "new String("blah")"...

From the API:

public String(String original)

Initializes a newly created String object so that it represents the same sequence of characters as the argument; in other words, the newly created string is a copy of the argument string. Unless an explicit copy of original is needed, use of this constructor is unnecessary since Strings are immutable.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Simple Date Formatter
 
Similar Threads
Error while calling beans in jsp
WSAD 5 Question....Help..
int[] x = {1, }
SCBCD for EJB3
I'm terribly confused