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

          There are no comments yet on this issue.

            People

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

              Dates

              • Created:
                Updated:
                Resolved:

                Development