jmrozanec / jmrozanec/cron-utils

Exception swallowed in "AndFieldValueGenerator"

Open
#423 5 comments 0 reactions 0 assignees View on GitHub
bug hacktoberfest help wanted
Dominant language
Java
Stars
1.2k
Forks
272
PR merge metrics
No merged PRs in 30d

Description

In `AndFieldValueGenerator`, in the function
```
protected List generateCandidatesNotIncludingIntervalExtremes(int start, int end)
```
there is a try/catch which just logs the exception and returns an empty list.

```
Catched expected exception while generating candidates
com.cronutils.model.time.generator.NoSuchValueException: null
at com.cronutils.model.time.generator.AndFieldValueGenerator.generateNextValue(AndFieldValueGenerator.java:52)
at com.cronutils.model.time.generator.AndFieldValueGenerator.generateCandidatesNotIncludingIntervalExtremes(AndFieldValueGenerator.java:84)
at com.cronutils.model.time.generator.FieldValueGenerator.generateCandidates(FieldValueGenerator.java:61)
at com.cronutils.model.time.ExecutionTimeBuilder.forHoursMatching(ExecutionTimeBuilder.java:64)
at com.cronutils.model.time.ExecutionTime.forCron(ExecutionTime.java:53)
```

So I have a situation where a client generates cron expressions interactively using the parser, and expressions which are "valid" then generate completely unexpected results when used with the `ExecutionTime` class.

The exception is printed, but there is no way to guard against this behaviour because the exception is not propagated.

An example expression is `0 0 0-07,17-0 ? * SAT` which is parsed as `every hour between 0 and 7 and every hour between 17 and 0 at Saturday day`.

If this is expression is not usable, it should not be accepted by the parser. If that's too hard, at least when an `ExecutionTime` is created using a Cron which it can't use, an exception should be generated so it is possible to validate against that, and keep junk out of the system.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.