Spring Batch
  1. Spring Batch
  2. BATCH-1798

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

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major 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);
      }

        Activity

        Hide
        sonwar added a comment -

        I forgotten to say... The fix is on ItemStream's open() method. No need for checking "resources.length != 0", since that check is made before.

        So, the currentResource=0 code solves the bug.

        Show
        sonwar added a comment - I forgotten to say... The fix is on ItemStream's open() method. No need for checking "resources.length != 0", since that check is made before. So, the currentResource=0 code solves the bug.
        Hide
        Robert Kasanicky added a comment -

        Fixed as suggested. Note the bug is not triggered by crashing on the 1st commit, rather by crashing without calling read() on the reader. I guess you must be calling the reader from an ItemProcessor or so.

        Show
        Robert Kasanicky added a comment - Fixed as suggested. Note the bug is not triggered by crashing on the 1st commit, rather by crashing without calling read() on the reader. I guess you must be calling the reader from an ItemProcessor or so.

          People

          • Assignee:
            Robert Kasanicky
            Reporter:
            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