Skip to content

Repository/DAO-level count methods cannot soundly validate job/step existence #5544

Closed

Description

@fmbenhassine

JobRepository/JobExplorer/JobInstanceDao/StepExecutionDao expose count methods that are documented (or expected, per #5252) to throw NoSuchJobException / NoSuchStepException when the given identifier is unknown. None of these layers has access to the registry of known jobs (JobRegistry) or to a job's declared step topology. They can only see persisted execution history. That makes "is this identifier unknown" unanswerable at this layer without producing false positives on the very common case of "valid identifier, simply never executed yet".

The existing JobInstanceDao implementations already get this wrong as they all infer "unknown job" purely from prior instances. A job that is fully configured but has never been launched would incorrectly throw a NoSuchJobException . JobInstanceDao#getJobInstanceCount has no internal callers at all in the codebase besides the DAO/JobExplorer delegation chain and tests.

For StepExecutionDao#getStepExecutionCount, no real caller needs the identifier-existence distinction. Both internal callers treat "unknown" and "zero" identically:

The only place that can validate existence correctly needs a registry (which is at the job operator level), which this layer doesn't have. This confirms that existence validation is a JobOperator (start/restart-time) concern, not a JobRepository/DAO concern.

The current design also reveals a package dependency cycle. NoSuchJobException is defined in org.springframework.batch.core.launch, yet is imported and thrown from org.springframework.batch.core.repository (JobRepository, JobInstanceDao, etc). Meanwhile org.springframework.batch.core.launch.support correctly depends on repository (operators sit on top of persistence). The result is a repository ↔ launch package cycle. The same pattern exists for NoSuchStepException (defined in org.springframework.batch.core.step package, used in repository package, while step depends on repository).

The goal here is to remove the throws NoSuchJobException / throws NoSuchStepException contract from these repository/DAO-level count methods and keep existence validation exclusively at the JobOperator layer where the registry is available. This should be done in a deprecate-then-remove cycle:

  • introduce parallel methods without the checked exception (countJobInstances, countStepExecutions, same naming as the DAOs)
  • deprecate the current ones in 6.1 for removal in 7.0
  • migrate internal call sites to use the new methods (no functional breaking changes)

Related issues:

Activity

  1. self-assigned this
    on Sep 17, 2026
  2. added
    status: for-internal-team
    api: deprecation
    on Sep 17, 2026
  3. added this to the 6.1.0-M2 milestone on Sep 17, 2026
  4. added a commit that references this issue on Sep 17, 2026
    db57cf5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

api: deprecationin: corestatus: for-internal-teamtype: bug

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions