Uploaded image for project: 'OpenJPA'
  1. OpenJPA
  2. OPENJPA-2118

Prepared SQL query does not handle collection-valued parameter where collection is empty

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.0.0, 2.1.0, 2.2.0
    • 2.0.2, 2.1.2, 2.2.1, 2.3.0
    • sql
    • None

    Description

      In PreparedQueryImpl.setCollectionValuedParameter, we do a '%n' but don't check for n==0, as can be seen here:

      private void setCollectionValuedParameter(Map<Integer,Object> result,
      Collection values, int[] indices, Object param) {
      int n = values.size();
      Object[] array = values.toArray();
      if (n > indices.length || indices.length%n != 0) { <---------------------line 389 in 2.0.x

      When n==0, the following exception will occur:

      Exception data: java.lang.ArithmeticException: divide by zero
      at org.apache.openjpa.jdbc.kernel.PreparedQueryImpl.setCollectionValuedParameter(PreparedQueryImpl.java:389)

      I will upload a test to reproduce this issue and a proposed fix in the next day or two.

      Attachments

        Issue Links

          Activity

            People

              jpaheath Heath Thomann
              jpaheath Heath Thomann
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: