Announcement Announcement Module
Collapse
No announcement yet.
Critical defect in SpringBatch core 2.1.9 ? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Critical defect in SpringBatch core 2.1.9 ?

    Hello,

    Please consider the following scenario and suggest if it's a defect in SpringBatch core (GA Release 2.1.9)

    Code:
    <job id="test1">
            <step id="step1" >
                <tasklet>
                    <chunk commit-interval="10" skip-policy="always" processor-transactional="false">
                        <reader>
                            <beans:bean class="ItemReaderTest">
                                <beans:constructor-arg ref="list" />
                            </beans:bean>
                        </reader>
                        <processor>
                            <beans:bean class="ItemProcessorTest" />
                        </processor>
                        <writer>
                            <beans:bean class="ItemWriterTest" />
                        </writer>
                    </chunk>
                </tasklet>
            </step>
        </job>
    
        <bean id="always" class="org.springframework.batch.core.step.skip.AlwaysSkipItemSkipPolicy" />
    
        <util:list id="list">
            <beans:value>1</beans:value>
            <beans:value>2</beans:value>
            <beans:value>3</beans:value>
            <beans:value>4</beans:value>
            <beans:value>5</beans:value>
            <beans:value>6</beans:value>
        </util:list>
    Code:
    public class ItemReaderTest extends ListItemReader {
    
        public ItemReaderTest (List list) {
            super(list);
        }
    
        @Override
        public Object read(){
            Object item = super.read();
            System.out.println("reading item ---> " + item);
            return item;
        }
    }
    Code:
    public class ItemProcessorTest implements ItemProcessor {
    
        public Object process(Object item) throws Exception{
    
            if (item.equals("2")){
                System.out.println("returning null from processor for item ---> " + item);
                return null;
            }
    
            if (item.equals("5")){
                System.out.println("exception in processing item --> " + item);
                throw new RuntimeException(item.toString());
            }
    
            System.out.println("processing item ---> " + item);
            return item;
        }
    }

    Code:
    public class ItemWriterTest implements ItemWriter {
    
        public void write(List items) throws Exception{
    
            System.out.println("writing items ---> " + items);
            for(Object o : items){
                System.out.println("   writing item ---> " + o);
            }
    
            System.out.println("writing done for chunk");
        }
    }
    Generates the following output:
    Code:
    reading item ---> 1
    reading item ---> 2
    reading item ---> 3
    reading item ---> 4
    reading item ---> 5
    reading item ---> 6
    reading item ---> null
    processing item ---> 1
    returning null from processor for item ---> 2
    processing item ---> 3
    processing item ---> 4
    exception in processing item --> 5
    processing item ---> 3
    writing items ---> [1, 3, 3, 4]
       writing item ---> 1
       writing item ---> 3   
       writing item ---> 3
       writing item ---> 4
    writing done for chunk
    I see here following issues:
    a) item 3 has been processed twice..
    b) item 6 lost..
    c) item3 written twice..

    Bug ?

  • #2
    I'd have to dig a bit further but it seems like there may be an issue when using a non-transactional ItemProcessor in conjunction with skips. I've created an issue in Jira to track it here: https://jira.springsource.org/browse/BATCH-2036

    Comment

    Working...
    X