Uploaded image for project: 'JBeret'
  1. JBeret
  2. JBERET-169

JdbcItemWriter#open() produces ArrayIndexOutOfBoundsException with complex SQL

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • Major
    • None
    • 1.1.0.Final
    • jberet-support
    • None

    Description

      When parameterNames is not explicitly supplied, JdbcItemWriter tries to parse following SQL and failed:

      INSERT INTO forex (symbol, ts, bid_open, bid_high, bid_low, bid_close, volume) values ('USDJPY', parsedatetime('yyyyMMdd HHmmss', ?), ?, ?, ?, ?, ?)
      

      Exception:

      May 27, 2015 11:09:10 AM org.jberet.support.io.CsvItemReader open
      INFO: JBERET060501: Opening resource usdjpy.csv in class org.jberet.support.io.CsvItemReader
      May 27, 2015 11:09:10 AM org.jberet.support.io.CsvItemReader close
      INFO: JBERET060502: Closing resource usdjpy.csv in class org.jberet.support.io.CsvItemReader
      May 27, 2015 11:09:10 AM org.jberet.runtime.runner.ChunkRunner run
      ERROR: item-count=10, time-limit=0, skip-limit=-1, skipCount=0, retry-limit=-1, retryCount=0
      May 27, 2015 11:09:10 AM org.jberet.runtime.runner.ChunkRunner run
      ERROR: JBERET000007: Failed to run job myjob, test, org.jberet.job.model.Chunk@3f85394a
      java.lang.ArrayIndexOutOfBoundsException: 7
      	at org.jberet.support.io.JdbcItemWriter.open(JdbcItemWriter.java:145)
      	at org.jberet.runtime.runner.ChunkRunner.run(ChunkRunner.java:183)
      	at org.jberet.runtime.runner.StepExecutionRunner.runBatchletOrChunk(StepExecutionRunner.java:217)
      	at org.jberet.runtime.runner.StepExecutionRunner.run(StepExecutionRunner.java:139)
      	at org.jberet.runtime.runner.CompositeExecutionRunner.runStep(CompositeExecutionRunner.java:164)
      	at org.jberet.runtime.runner.CompositeExecutionRunner.runJobElement(CompositeExecutionRunner.java:128)
      	at org.jberet.runtime.runner.StepExecutionRunner.run(StepExecutionRunner.java:194)
      	at org.jberet.runtime.runner.CompositeExecutionRunner.runStep(CompositeExecutionRunner.java:164)
      	at org.jberet.runtime.runner.CompositeExecutionRunner.runFromHeadOrRestartPoint(CompositeExecutionRunner.java:88)
      	at org.jberet.runtime.runner.JobExecutionRunner.run(JobExecutionRunner.java:55)
      	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
      	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
      	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
      	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
      	at java.lang.Thread.run(Thread.java:745)
      

      I suggest following fixes:

      • If user supplied java.util.List as beanType, stop to try parsing SQL in open() and use itemAsList.size() as the loop limit in mapParameters() instead of parameterNames.length because parameterNames looks like not make sense for java.util.List.
      • If beanType is not java.util.List and a complex SQL which has extra commas is supplied, throw a BatchRuntimeException to notify user that we can't automatically map parameters so user must specify parameterNames explicitly.

      Attachments

        Issue Links

          Activity

            People

              cfang@redhat.com Cheng Fang
              xkylex Kohei Nozaki (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: