Skip to content

The constructor of JsonItemReader should call setExecutionContextName() #3681

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

Closed
benelog opened this issue Mar 18, 2020 · 1 comment · Fixed by #3682
Closed

The constructor of JsonItemReader should call setExecutionContextName() #3681

benelog opened this issue Mar 18, 2020 · 1 comment · Fixed by #3682
Labels
has: backports Legacy label from JIRA. Superseded by "for: backport-to-x.x.x" in: infrastructure type: bug
Milestone

Comments

@benelog
Copy link
Contributor

benelog commented Mar 18, 2020

When the constructor of JsonItemReader is called directly and open(ExectionConext) is called, it makes exceptions at ExecutionContextUserSupport.getKey(..)

    JsonItemReader<AccessLog> reader = new JsonItemReader<AccessLog>(resource, jsonObjectReader);
    reader.open(new ExecutionContext());
    AccessLog item = reader.read();
    reader.close();
java.lang.IllegalArgumentException: Name must be assigned for the sake of defining the execution context keys prefix.

	at org.springframework.util.Assert.hasText(Assert.java:284)
	at org.springframework.batch.item.util.ExecutionContextUserSupport.getKey(ExecutionContextUserSupport.java:62)
	at org.springframework.batch.item.ItemStreamSupport.getExecutionContextKey(ItemStreamSupport.java:71)
	at org.springframework.batch.item.support.AbstractItemCountingItemStreamItemReader.open(AbstractItemCountingItemStreamItemReader.java:159)

The constructor of JsonItemReader should call setExecutionContextName(String) similar to JsonFileItemWriter.java#L71

@fmbenhassine
Copy link
Contributor

Good catch. This is indeed enforced in the builder but not in the constructor. Thank you for raising this issue and for opening a PR! I will take a look asap.

@fmbenhassine fmbenhassine added this to the 4.3.0 milestone Mar 19, 2020
@fmbenhassine fmbenhassine added has: backports Legacy label from JIRA. Superseded by "for: backport-to-x.x.x" in: infrastructure labels Mar 19, 2020
fmbenhassine pushed a commit to fmbenhassine/spring-batch that referenced this issue Mar 24, 2020
fmbenhassine pushed a commit to fmbenhassine/spring-batch that referenced this issue Mar 24, 2020
This was referenced Mar 24, 2020
dimitrisli pushed a commit to dimitrisli/spring-batch that referenced this issue Apr 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
has: backports Legacy label from JIRA. Superseded by "for: backport-to-x.x.x" in: infrastructure type: bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants