Skip to content

Conversation

@KMGeon
Copy link

@KMGeon KMGeon commented Oct 24, 2025

Summary

Fixed validation bug in JobParameter compact constructor that validated value parameter twice instead of validating both name and value parameters.

Fixes gh-5049

Problem Description

The compact constructor in JobParameter.java had a typo:

// Before (Bug)
Assert.notNull(value, "name must not be null");  // ❌ validates 'value' but message says 'name'
Assert.notNull(value, "value must not be null"); // ❌ validates 'value' twice

This allowed creating JobParameter objects with null name, which could cause:

  • NullPointerException in equals() and hashCode() methods
  • Contract violation (name should never be null)
  • Misleading error messages

Changes Made

File: org.springframework.batch.core.job.parameters.JobParameter

  • Changed to validate name instead of value
// After (Fixed)
Assert.notNull(name, "name must not be null");   // ✅ now validates 'name'
Assert.notNull(value, "value must not be null"); // ✅ validates 'value'

Testing

  • Added new test case for validation
  • All existing tests pass
  • Code formatting applied (spring-javaformat:apply)
  • Full build completed successfully

- Fixed line 41 to validate 'name' parameter instead of 'value'
- The 'name' parameter was previously not validated, allowing null values
- This caused potential NullPointerException in equals() and hashCode() methods
- Added test case 'testAddingNullJobParameters' to verify the fix

Fixes spring-projectsgh-5049

Signed-off-by: mugeon <[email protected]>
- Removed testAddingNullJobParameters (indirect test via JobParametersBuilder)
- Added testConstructorNameNotNull to directly test name validation
- Added testConstructorValueNotNull to directly test value validation
- Added testConstructorTypeNotNull to directly test type validation
- These tests directly validate the constructor fix

Signed-off-by: mugeon <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

JobParameter constructor validates wrong parameter (value instead of name)

1 participant