Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve Error Messages in JobParametersBuilder methods #4581

Closed
GirirajSinghRathore opened this issue Apr 22, 2024 · 0 comments
Closed

Improve Error Messages in JobParametersBuilder methods #4581

GirirajSinghRathore opened this issue Apr 22, 2024 · 0 comments
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

Comments

@GirirajSinghRathore
Copy link

GirirajSinghRathore commented Apr 22, 2024

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

@GirirajSinghRathore GirirajSinghRathore added the status: waiting-for-triage Issues that we did not analyse yet label Apr 22, 2024
@fmbenhassine fmbenhassine added in: core type: enhancement and removed status: waiting-for-triage Issues that we did not analyse yet labels Apr 29, 2024
@fmbenhassine fmbenhassine added this to the 5.2.0-M1 milestone Apr 29, 2024
fmbenhassine added a commit that referenced this issue Apr 30, 2024
fmbenhassine added a commit that referenced this issue Apr 30, 2024
This was referenced Apr 30, 2024
@fmbenhassine fmbenhassine changed the title Improve Error Message in JobParametersBuilder.addString Method Improve Error Messages in JobParametersBuilder methods Apr 30, 2024
@fmbenhassine fmbenhassine added 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 labels Apr 30, 2024
natedanner pushed a commit to natedanner/spring-projects__spring-batch that referenced this issue May 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
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
Projects
None yet
Development

No branches or pull requests

2 participants