I think there might be a bug in Date.diff - it looks like if the number of days are the same, it attempts to directly cast the incoming Item to a Date in order to compare seconds. However, if the incoming Item is actually a string or something else a cast failure will occur. My fix is below:
Old code: @Override public int diff(final InputInfo ii, final Item it) throws QueryException { final long d1 = days(); final Date d = (Date) (it.date() ? it : type.e(it, null, ii)); final long d2 = d.days(); if(d1 != d2) return (int) (d1 - d2); return seconds().subtract(((Date) it).seconds()).signum(); }
New code: @Override public int diff(final InputInfo ii, final Item it) throws QueryException { final long d1 = days(); final Date d = (Date) (it.date() ? it : type.e(it, null, ii)); final long d2 = d.days(); if(d1 != d2) return (int) (d1 - d2); return seconds().subtract(d.seconds()).signum(); }
Dave
Thanks, Dave, for the patch! We'll fix the code snippet with the commit. Do you have a query that helps us to reproduce the bug? Christian
On Tue, Oct 5, 2010 at 10:18 PM, Dave Glick dglick@dracorp.com wrote:
I think there might be a bug in Date.diff – it looks like if the number of days are the same, it attempts to directly cast the incoming Item to a Date in order to compare seconds. However, if the incoming Item is actually a string or something else a cast failure will occur. My fix is below:
Old code:
@Override
public int diff(final InputInfo ii, final Item it) throws QueryException {
final long d1 = days();
final Date d = (Date) (it.date() ? it : type.e(it, null, ii));
final long d2 = d.days();
if(d1 != d2) return (int) (d1 - d2);
return seconds().subtract(((Date) it).seconds()).signum();
}
New code:
@Override
public int diff(final InputInfo ii, final Item it) throws QueryException {
final long d1 = days();
final Date d = (Date) (it.date() ? it : type.e(it, null, ii));
final long d2 = d.days();
if(d1 != d2) return (int) (d1 - d2);
return seconds().subtract(d.seconds()).signum();
}
Dave
BaseX-Talk mailing list BaseX-Talk@mailman.uni-konstanz.de https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk
Unfortunately not. The problem showed up in some complex queries driven by code. I didn't create a test case in the BaseX GUI, but I don't think it'll be too hard. I should be able to work one up if it would help. I did test the fix below with our situation and it appears to have resolved the issue.
Dave
-----Original Message----- From: Christian Grün [mailto:christian.gruen@gmail.com] Sent: Tuesday, October 05, 2010 4:36 PM To: Dave Glick Cc: basex-talk@mailman.uni-konstanz.de Subject: Re: [basex-talk] Bug in Date.diff
Thanks, Dave, for the patch! We'll fix the code snippet with the commit. Do you have a query that helps us to reproduce the bug? Christian
On Tue, Oct 5, 2010 at 10:18 PM, Dave Glick dglick@dracorp.com wrote:
I think there might be a bug in Date.diff - it looks like if the number of days are the same, it attempts to directly cast the incoming Item to a Date in order to compare seconds. However, if the incoming Item is actually a string or something else a cast failure will occur. My fix is below:
Old code:
@Override
public int diff(final InputInfo ii, final Item it) throws QueryException {
final long d1 = days();
final Date d = (Date) (it.date() ? it : type.e(it, null, ii));
final long d2 = d.days();
if(d1 != d2) return (int) (d1 - d2);
return seconds().subtract(((Date) it).seconds()).signum();
}
New code:
@Override
public int diff(final InputInfo ii, final Item it) throws QueryException {
final long d1 = days();
final Date d = (Date) (it.date() ? it : type.e(it, null, ii));
final long d2 = d.days();
if(d1 != d2) return (int) (d1 - d2);
return seconds().subtract(d.seconds()).signum();
}
Dave
BaseX-Talk mailing list BaseX-Talk@mailman.uni-konstanz.de https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk
basex-talk@mailman.uni-konstanz.de