OpenJPA
  1. OpenJPA
  2. OPENJPA-2118

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

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 2.0.0, 2.1.0, 2.2.0
    • Fix Version/s: 2.0.2, 2.1.2, 2.2.1, 2.3.0
    • Component/s: sql
    • Labels:
      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.

        Issue Links

          Activity

          Heath Thomann created issue -
          Heath Thomann made changes -
          Field Original Value New Value
          Link This issue is related to OPENJPA-1738 [ OPENJPA-1738 ]
          Heath Thomann made changes -
          Status Open [ 1 ] Resolved [ 5 ]
          Fix Version/s 2.0.2 [ 12315257 ]
          Fix Version/s 2.1.2 [ 12317142 ]
          Fix Version/s 2.3.0 [ 12319463 ]
          Fix Version/s 2.2.1 [ 12319943 ]
          Resolution Fixed [ 1 ]
          Heath Thomann made changes -
          Status Resolved [ 5 ] Closed [ 6 ]
          Transition Time In Source Status Execution Times Last Executer Last Execution Date
          Open Open Resolved Resolved
          121d 3h 34m 1 Heath Thomann 31/May/12 02:49
          Resolved Resolved Closed Closed
          36s 1 Heath Thomann 31/May/12 02:49

            People

            • Assignee:
              Heath Thomann
              Reporter:
              Heath Thomann
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development