Return-Path: Delivered-To: apmail-incubator-abdera-user-archive@locus.apache.org Received: (qmail 9766 invoked from network); 3 Dec 2007 00:08:40 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 3 Dec 2007 00:08:40 -0000 Received: (qmail 39715 invoked by uid 500); 3 Dec 2007 00:08:28 -0000 Delivered-To: apmail-incubator-abdera-user-archive@incubator.apache.org Received: (qmail 39698 invoked by uid 500); 3 Dec 2007 00:08:28 -0000 Mailing-List: contact abdera-user-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: abdera-user@incubator.apache.org Delivered-To: mailing list abdera-user@incubator.apache.org Received: (qmail 39689 invoked by uid 99); 3 Dec 2007 00:08:28 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 02 Dec 2007 16:08:28 -0800 X-ASF-Spam-Status: No, hits=-0.0 required=10.0 tests=SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of jasnell@gmail.com designates 209.85.198.191 as permitted sender) Received: from [209.85.198.191] (HELO rv-out-0910.google.com) (209.85.198.191) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 03 Dec 2007 00:08:07 +0000 Received: by rv-out-0910.google.com with SMTP id k20so2676713rvb for ; Sun, 02 Dec 2007 16:08:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:user-agent:mime-version:to:subject:references:in-reply-to:x-enigmail-version:content-type:content-transfer-encoding; bh=3Rt0uCSsXzrmcnLMFBw+t/vMl4Jj7WCRFSygeNtPFIY=; b=HijN5T+odSu4o3I+uGzoFowgON/O/IedkQqohBDcouTiIKRP+lHYMJp3HobMIbbF31ymKq879Ka0qTCyTZS1doKGLCjGbY6q5QMY1ywj5t9qFPd5mLXVnFUWVaUiJvw7iNKEUbTUFztfPQ2ucL0+A/7J+hYZO4iutOOyy9JGqVs= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=received:message-id:date:from:user-agent:mime-version:to:subject:references:in-reply-to:x-enigmail-version:content-type:content-transfer-encoding; b=rzsjoLTFIXvjsezwrNuVGz4BMqTlJhznRa4o/IkPqpw64OyqXdw4YAgrR73Jc64/IIXJqKjHT84UloOABNEI2TNjdqZ3n+vFblH26pdvB3cTd0ua6qYST6mgfjEpPCqhycJX4La1qPAXjUinIqLjP8QvJlX9dfFZHOXxe2QG+mY= Received: by 10.140.135.20 with SMTP id i20mr5298089rvd.1196640489824; Sun, 02 Dec 2007 16:08:09 -0800 (PST) Received: from ?192.168.1.2? ( [67.181.218.96]) by mx.google.com with ESMTPS id g39sm9698423rvb.2007.12.02.16.08.08 (version=TLSv1/SSLv3 cipher=RC4-MD5); Sun, 02 Dec 2007 16:08:09 -0800 (PST) Message-ID: <475348DF.3070805@gmail.com> Date: Sun, 02 Dec 2007 16:07:59 -0800 From: James M Snell User-Agent: Thunderbird 2.0.0.6 (X11/20071022) MIME-Version: 1.0 To: abdera-user@incubator.apache.org Subject: Re: AtomDate bug References: <30DFA387-25CC-439F-83C4-5D7AB27000C3@gmail.com> In-Reply-To: <30DFA387-25CC-439F-83C4-5D7AB27000C3@gmail.com> X-Enigmail-Version: 0.95.5 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Virus-Checked: Checked by ClamAV on apache.org In the trunk, AtomDate has been changed to use a regex pattern to parse dates in order to improve performance. If you would, please try your tests with the trunk and let me know what problems you're seeing. We can tweak the regex accordingly. - James Chris Berry wrote: > Greetings, > I have found a subtle but dangerous bug in AtomDate (v0.3.0) > AtomDate walks thru a series of masks, trying each, until it either > finds a match, or, if not, throws an Exception. > The problem is that, when a date string with a bad "time section" is > used, SimpleDateFormat will go on to match the "date section" > And thus, give the user something entirely different from what they > wanted, rather than throw an Exception > > Here is an example: > > String ddd = "2007-11-30T23:59:59:000Z"; > Date upmin = AtomDate.parse( ddd ); > log.debug( "********************* ddd= " + ddd ); > log.debug( "********************* upmin= " + upmin ); > log.debug( "********************* upmin GMT= " + > upmin.toGMTString() ); > > NOTE: The correct string should be "2007-11-30T23:59:59.000Z"; <=== > 59dot000 (59.000) instead of 59colon000 (59:000) -- a pretty easy > mistake, and hard to see > > AtomDate then sees this as:: > > AtomDate: parsing:: 2007-11-30T23:59:59:000Z > trying mask= yyyy-MM-dd'T'HH:mm:ss.SSSz > trying mask= yyyy-MM-dd't'HH:mm:ss.SSSz > trying mask= yyyy-MM-dd'T'HH:mm:ss.SSS'Z' > trying mask= yyyy-MM-dd't'HH:mm:ss.SSS'z' > trying mask= yyyy-MM-dd'T'HH:mm:ssz > trying mask= yyyy-MM-dd't'HH:mm:ssz > trying mask= yyyy-MM-dd'T'HH:mm:ss'Z' > trying mask= yyyy-MM-dd't'HH:mm:ss'z' > trying mask= yyyy-MM-dd'T'HH:mmz > trying mask= yyyy-MM-dd't'HH:mmz > trying mask= yyyy-MM-dd'T'HH:mm'Z' > trying mask= yyyy-MM-dd't'HH:mm'z' > trying mask= yyyy-MM-dd > [12/02/07 17:11:48:683] DEBUG - EntryURIHelperTest - > ********************* ddd= 2007-11-30T23:59:59:000Z > [12/02/07 17:11:48:684] DEBUG - EntryURIHelperTest - > ********************* upmin= Thu Nov 29 18:00:00 CST 2007 > [12/02/07 17:11:48:685] DEBUG - EntryURIHelperTest - > ********************* upmin GMT= 30 Nov 2007 00:00:00 GMT > > NOTE: AtomDate has matched "yyyy-MM-dd" > And thus, changed the value from "30 Nov 2007 23:59:59 GMT" to "30 > Nov 2007 00:00:00 GMT" -- 24 hrs earlier !!! > > I'm not too sure how this should be fixed?? (Using setLenient(false) > will NOT fix it) > I think just checking String length before switching to "date only" will > result in the correct behavior. > > Something like this works (but isn't too pretty ;-) > > private static final int checkLengthStartingIndex = 12; > > /** > * Parse the serialized string form into a java.util.Date > * @param date The serialized string form of the date > * @return The created java.util.Date > */ > public static Date parse(String date) { > > ..... > > Date d = null; > SimpleDateFormat sdf = new SimpleDateFormat(); > for (int n = 0; n < masks.length; n++) { > try { > sdf.applyPattern(masks[n]); > sdf.setTimeZone(TimeZone.getTimeZone("GMT")); > > //sdf.setLenient(true); > // cwb >>> > sdf.setLenient(false); > if ( n >= checkLengthStartingIndex ) { > if ( date.length() != masks[n].length() ) > continue; > } > // cwb <<< > > Cheers, > -- Chris > S'all good --- chriswberry at gmail dot com > > > >