Improve Error Messages in JobParametersBuilder methods #4581
Labels
for: backport-to-5.0.x
Issues that will be back-ported to the 5.0.x line
for: backport-to-5.1.x
Issues that will be back-ported to the 5.1.x line
in: core
type: enhancement
Milestone
Description
Currently, when the
addString
method in theJobParametersBuilder
class is called with a 'null' value for the parameter value, it throws anIllegalArgumentException
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
addString
method with anull
value for the parameter value.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
The text was updated successfully, but these errors were encountered: