A bug inside CronExpression

114 views
Skip to first unread message

Grafit

unread,
Jul 20, 2007, 8:29:55 AM7/20/07
to Quartz.NET
The following test fails

string expr = string.Format(" * * * * * {0}",
DateTime.Now.Year);
CronCalendar calendar = new CronCalendar(expr);
string fault = "дата исключена календарем";

Assert.IsFalse(calendar.IsTimeIncluded(DateTime.Now.AddMinutes(2)),
fault);
calendar.SetCronExpressionString("0 15 13 01 1980");
fault = "дата включена в календарь";

Assert.IsTrue(calendar.IsTimeIncluded(DateTime.Now.AddMinutes(2)),
fault);

The exception (index outside array bounds) is inside
CronExpression.GetTimeAfter() and TreeSet.First(). Part of faulty code
is as follows:

// get
second.................................................
st = seconds.TailSet(sec);
if (st != null && st.Count != 0)
{
sec = (int) st.First();
}
else
{
//exception here since both st.Count == 0 and
seconds.Count == 0
// I inserted if (seconds.Count > 0) to fix
sec = ((int) seconds.First());
<..>

Marko Lahma

unread,
Jul 23, 2007, 8:16:32 AM7/23/07
to quar...@googlegroups.com
I was unable to reproduce. I did a fix to CronExpression to trim input
expression before parsing (now in trunk). This will reveal that your
example has problems with the input, you have 6 parameters and the
year should be 7th.

-Marko

Grafit

unread,
Jul 24, 2007, 3:59:31 AM7/24/07
to Quartz.NET
Well, if I try to add an asterisk (expression " * * * * * * {0}") , I
get the following exception

System.Exception: Support for specifying both a day-of-week AND a day-
of-month parameter is not implemented

That looks a bit strange - I don't specify a day-of-week, I specify
that day-of-week can be anything it can. And, besides,
System.Exception is not a good class to throw, I suppose. Maybe
ArgumentException or even some kind of Quartz exception would be
better.
I get the same exception when specifying 7 asterisks only as well and
specifying "30 * * * * TUE" and "0/30 * * * * * ?" and only when I
specify just "30" - I get "unexpected end of expression" (as I know,
cron expression is to be filled with all right asterisks when data is
ommitted, but I see it's not implemented)

And, besides, here are the lines from CronExpressionExample included
in Quartz

// job 1 will run every 20 seconds
JobDetail job = new JobDetail("job1", "group1", typeof(SimpleJob));
CronTrigger trigger = new CronTrigger("trigger1", "group1", "job1",
"group1", "0/20 * * * * ?");
Here, they think specifying only six figures in CronExpression is
quite legal.

When I specify "0/20 * * * * ?" instead of "0/20 * * * * ?" (one
extra whitespace) I get
System.FormatException: '?' can only be specfied for Day-of-Month or
Day-of-Week - maybe that is the trim you fixed?

In several hours I'll try to figure out actions to reproduce "index
out of bounds"

Grafit

unread,
Jul 24, 2007, 5:01:24 AM7/24/07
to Quartz.NET
Reproduced. It is all due to leading whitespaces.

Marko Lahma

unread,
Jul 24, 2007, 11:08:01 AM7/24/07
to quar...@googlegroups.com
OK, so we are good with this I think when using latest from
Subversion. I need to keep in mind the auto-fill feature, basically it
would fill with "*" and "?" when needed and probably would work only
on simple cases. Though I'm not sure whether this is really a big
thing.

You can always open JIRA issue(s) when you find something inconvenient
or other bugs.

Thanks for all your detailed feedback on this.

-Marko

Reply all
Reply to author
Forward
0 new messages