Announcement Announcement Module
Collapse
No announcement yet.
MultiResourceItemReader throws java.lang.ArrayIndexOutOfBoundsException: -1 Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • MultiResourceItemReader throws java.lang.ArrayIndexOutOfBoundsException: -1

    The bug is detailed on https://jira.springsource.org/browse/BATCH-1798

    Before restarting some JobInstance, one should look for MultiResourceItemReader.resourceIndex=-1 on StepExecutionContext.

    I am using the following utility class to solve the bug on 2.1.8 release:

    Code:
    @Component
    public class Emergencial_1798_BugSolver {
    
        private static final String RESOURCE_INDEX = "MultiResourceItemReader.resourceIndex";
    
        @Autowired
        JobExplorer jobExplorer;
        
        @Autowired
        JobRepository jobRepository;
    
        public void solve(long jobExecutionId) {
            JobExecution jobExecution = jobExplorer.getJobExecution(jobExecutionId);
    
            for (StepExecution stepExecution : jobExecution.getStepExecutions()) {
                BatchStatus status = stepExecution.getStatus();
                
                if (status == BatchStatus.STOPPED || status == BatchStatus.FAILED) {
                    if (stepExecution.getExecutionContext().containsKey(RESOURCE_INDEX)) {
                        int value = stepExecution.getExecutionContext().getInt(RESOURCE_INDEX);
                        if (value == -1) {
                            // Solving....
                            stepExecution.getExecutionContext().put(RESOURCE_INDEX, 0);
                            jobRepository.updateExecutionContext(stepExecution);
                        }
                    }
                }
            }        
        }    
    }
    Last edited by sonwar; Oct 7th, 2011, 09:10 PM.
Working...
X