Skip to content

Improve Error Messages in JobParametersBuilder methods #4581

Closed
@GirirajSinghRathore

Description

@GirirajSinghRathore

Description

Currently, when the addString method in the JobParametersBuilder class is called with a 'null' value for the parameter value, it throws an IllegalArgumentException with the error message "value must not be null". This message does not provide any information about which parameter is causing the issue, making it challenging for developers to identify and resolve the problem, especially when dealing with multiple parameters.

Proposal

Improve the error message in the 'addString' method to include the key for which the value is 'null'. This will provide more context to developers, making it easier to identify and address the problem.

Current Behavior

When the 'addString' method is called with a null value for the parameter value, the exception message is as follows:

java.lang.IllegalArgumentException: value must not be null
at org.springframework.util.Assert.notNull(Assert.java:172) ~[spring-core-6.1.2.jar:6.1.2]
at org.springframework.batch.core.JobParameter.(JobParameter.java:52) ~[spring-batch-core-5.1.0.jar:5.1.0]
at org.springframework.batch.core.JobParametersBuilder.addString(JobParametersBuilder.java:108) ~[spring-batch-core-5.1.0.jar:5.1.0]

Expected Behavior

The exception message should include the key for which the value is null, providing more context to developers:

java.lang.IllegalArgumentException: Value for key 'param' cannot be null. Please ensure that the value provided for key 'param' is not null.
at org.springframework.util.Assert.notNull(Assert.java:172) ~[spring-core-6.1.2.jar:6.1.2]
at org.springframework.batch.core.JobParameter.(JobParameter.java:52) ~[spring-batch-core-5.1.0.jar:5.1.0]
at org.springframework.batch.core.JobParametersBuilder.addString(JobParametersBuilder.java:108) ~[spring-batch-core-5.1.0.jar:5.1.0]

Steps to Reproduce

  1. Call the addString method with a null value for the parameter value.
  2. Catch the resulting IllegalArgumentException and observe the exception message.

Related Issue

This issue is related to the fix implemented in issue #3913. The fix for issue #3913 introduced a change that caused the issue described here.

As asked in comment by mbenhassine , created the issue

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions