jmrozanec / cron-utils

Cron utils for parsing, validations and human readable descriptions as well as date/time interoperability.
http://cron-utils.com
Apache License 2.0
1.15k stars 262 forks source link

Buggy Descriptor: Throwing ArrayIndexOutOfBoundsException and UnknownFormatConversionExceptions #32

Closed rkkoszewski closed 9 years ago

rkkoszewski commented 9 years ago

Hello, is it a known issue that the descriptor is throwing weird formatting and array exceptions?

This is my code:

try{
String cronExpr = "% HERE CRON EXPRESSION %";
  CronDefinition cronDefinition =  CronDefinitionBuilder.instanceDefinitionFor(CronType.CRON4J);
  CronParser parser = new CronParser(cronDefinition);
  CronDescriptor descriptor = CronDescriptor.instance(Locale.UK);
  descriptor.describe(parser.parse(cronExpr)
}catch(Exception e){
        e.printStackTrace();
}

When I use: * 1,2,3,4,5,6 * 1,2,3 * I get: java.lang.ArrayIndexOutOfBoundsException: 1

When I use: * 1 1,2 * 4 I get: java.util.UnknownFormatConversionException: Conversion = 'p'

Both examples return TRUE while validation.

More info: CronType.CRON4J and CronType.UNIX has the same bug. CronUtils 3.0 and 2.0 has the same bug.

I have htime-1.0, joda-time-2.4, guava-18.0, commons-lang3-3.4 in the classpath.

Could somebody try to replicate the issue?

jmrozanec commented 9 years ago

@rkkoszewski thank you for reporting this. I was able to reproduce the issue. Will upload the corresponding tests soon. You are welcome to contribute a fix!

jmrozanec commented 9 years ago

@rkkoszewski Issue fixed. Thank you for reporting this!

jmrozanec commented 9 years ago

@rkkoszewski Version 3.1.0 was released including this fix.