Uploaded image for project: 'Spring Batch'
  1. Spring Batch
  2. BATCH-1798

MultiResourceItemReader fails on Restart if read() method was not called.

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 2.1.8
    • Fix Version/s: 2.1.9
    • Component/s: Infrastructure
    • Labels:
    • Environment:
      Windows/Linux

      Description

      The MultiResourceItemReader starts with -1 as currentResource. If the ItemProcessor fails on first commit (I tested with a "throw new RuntimeException()"), this index remains -1 on ExecutionContext. Then, on restart, we get:

      java.lang.ArrayIndexOutOfBoundsException: -1
      at org.springframework.batch.item.file.MultiResourceItemReader.open(MultiResourceItemReader.java:171)

      The fix is something like:

      if (executionContext.containsKey(executionContextUserSupport.getKey(RESOURCE_KEY))) {
      currentResource = executionContext.getInt(executionContextUserSupport.getKey(RESOURCE_KEY));

      // begin fix block
      if (currentResource == -1)

      { currentResource = 0; }

      // end fix block

      delegate.setResource(resources[currentResource]);
      delegate.open(executionContext);
      }

        Attachments

          Activity

            People

            • Assignee:
              robert.kasanicky Robert Kasanicky
              Reporter:
              sonwar sonwar
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Time Tracking

                Estimated:
                Original Estimate - 1h
                1h
                Remaining:
                Remaining Estimate - 0d
                0d
                Logged:
                Time Spent - 1h
                1h