Return-Path: Delivered-To: apmail-incubator-abdera-user-archive@locus.apache.org Received: (qmail 7538 invoked from network); 2 Dec 2007 23:54:51 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 2 Dec 2007 23:54:51 -0000 Received: (qmail 37001 invoked by uid 500); 2 Dec 2007 23:54:39 -0000 Delivered-To: apmail-incubator-abdera-user-archive@incubator.apache.org Received: (qmail 36976 invoked by uid 500); 2 Dec 2007 23:54:39 -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 36967 invoked by uid 99); 2 Dec 2007 23:54:39 -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 15:54:39 -0800 X-ASF-Spam-Status: No, hits=2.6 required=10.0 tests=HTML_FONT_FACE_BAD,HTML_MESSAGE,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of chriswberry@gmail.com designates 209.85.132.245 as permitted sender) Received: from [209.85.132.245] (HELO an-out-0708.google.com) (209.85.132.245) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 02 Dec 2007 23:54:18 +0000 Received: by an-out-0708.google.com with SMTP id b33so578475ana for ; Sun, 02 Dec 2007 15:54:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:mime-version:to:message-id:content-type:from:subject:date:x-mailer; bh=oPWlqAjk3SbBZ7EwrQn4ykrYsJH12bSyz+/HqGyioKM=; b=Wr1RYc+wbO4caA/jLUEW+kfjT7bxBhl/36aTJQnAJwYQVg+3gbLs+4KcTSYetwnFJeKQXJ7eKNSp1tMiRNLyEMYZwcSkuEETDvOo5PxaK67++MuQ+xSCEQq5w19tOvoUV2Cn9UXlIKJXENaBTDLc3DNLYuKGzkg5dBaEAE5x04U= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=received:mime-version:to:message-id:content-type:from:subject:date:x-mailer; b=YXayy7FBMJy1x+JiqlVs/qWujiwRGbD469r17ahuDjbIz4Ahgb2HIBSOTRZn+CBDALKBzMmn7leoMVro5WYtFVj1vBESeb/Le8f+93VjISjy7LUq4Quso0sCtCiKDDF6s7dQBwCrNTDdO6AOm9JzaDExrnwkBa1lobllXqqF0vs= Received: by 10.100.135.16 with SMTP id i16mr621593and.1196639657934; Sun, 02 Dec 2007 15:54:17 -0800 (PST) Received: from ?192.168.1.3? ( [72.179.45.126]) by mx.google.com with ESMTPS id 66sm9358905wra.2007.12.02.15.54.15 (version=TLSv1/SSLv3 cipher=OTHER); Sun, 02 Dec 2007 15:54:16 -0800 (PST) Mime-Version: 1.0 (Apple Message framework v752.3) To: Abdera User Message-Id: <30DFA387-25CC-439F-83C4-5D7AB27000C3@gmail.com> Content-Type: multipart/alternative; boundary=Apple-Mail-18--710980289 From: Chris Berry Subject: AtomDate bug Date: Sun, 2 Dec 2007 17:52:31 -0600 X-Mailer: Apple Mail (2.752.3) X-Virus-Checked: Checked by ClamAV on apache.org --Apple-Mail-18--710980289 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=US-ASCII; delsp=yes; format=flowed 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 --Apple-Mail-18--710980289--