Skip to content

JobInstanceDao#getJobInstanceCount throws NoSuchJobException instead of returning zero #5124

@kzander91

Description

@kzander91

This is a breaking behaviour change without any benefit imho. While this behaviour has been documented in the method's Javadoc, I don't see the reason behind it: Counting the number of invocations for a job that has never run should return 0, not throw an exception.

This change makes the JobInstanceDao/JobRepository classes more cumbersome to use.
With Batch 5:

int count = jobExplorer.getJobInstanceCount("myJob");
// do stuff with count, `0` is a possibility

// or in tests
assertThat(jobExplorer.getJobInstanceCount("myJob")).isZero();
// run job, then assert again
assertThat(jobExplorer.getJobInstanceCount("myJob")).isOne();

With Batch 6:

int count;
try {
  count = jobExplorer.getJobInstanceCount("myJob");
} catch (NoSuchJobException _) {
  count = 0;
}

// or in tests
assertThatExceptionOfType(NoSuchJobException.class)
  .isThrownBy(() -> jobExplorer.getJobInstanceCount("myJob"));
// run job, then assert again
assertThat(jobExplorer.getJobInstanceCount("myJob")).isOne();

Please consider reverting this change.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions