IBM Support

PM64809: DIVISION BY ZERO ERROR WITH JPA 2

Subscribe

You can track all active APARs for this component.

 

APAR status

  • Closed as program error.

Error description

  • https://issues.apache.org/jira/browse/OPENJPA-2118
    
    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.setCollectionVa
    luedParameter(PreparedQueryImpl.java:389)
    

Local fix

  • n/a
    

Problem summary

  • ****************************************************************
    * USERS AFFECTED:  All users of IBM WebSphere Application      *
    *                  Server V8.0.0 and V8.5.0 who make           *
    *                  use of quries which contain an empty        *
    *                  collection.                                 *
    ****************************************************************
    * PROBLEM DESCRIPTION: OpenJPA Prepared SQL query does not     *
    *                      handle collection-valued parameter      *
    *                      where collection is empty.              *
    ****************************************************************
    * RECOMMENDATION:                                              *
    ****************************************************************
    When using a Prepared SQL query, there exists the potential
    for a 'java.lang.ArithmeticException: divide by zero'
    exception.  This occurs when the a collection-valued parameter
    is used in the SQL.  For example, take the following SQL:
    String jpql =
    "select e from Employee e where e.department in :param";
    where Employee and Department are in a relationship, as
    follows:
    public class Employee {
    @Id
    @GeneratedValue
    private long id;
    @ManyToOne
    private Department department;
    ......
    public class Department {
    @Id
    @GeneratedValue
    private long id;
    @OneToMany
    private Collection<Employee> employees = new
    HashSet<Employee>();
    ......
    Given these two entities, and the above query, the following
    execution will result in the exception:
    // Pass an empty list to 'param'.
    em.createQuery(jpql).setParameter("param",
    new ArrayList<Department>()).getResultList();
    

Problem conclusion

  • With this fix, code has been added to guard against a
    division by zero exception in the scenario described.  That
    is, the area of code which causes the division by zero
    will add a check for a zero before performing a division.
    
    The fix for this APAR is currently targeted for
    inclusion in Service Levels (Fix Packs) 8.0.0.5 and
    8.5.0.1 of WebSphere Application Server versions 8.0.0 and
    8.5.0.
    
    Please refer to the recommended updates page for delivery
    information:
    http://www.ibm.com/support/docview.wss?rs=180&uid=swg27004980
    

Temporary fix

Comments

APAR Information

  • APAR number

    PM64809

  • Reported component name

    WEBSPHERE APP S

  • Reported component ID

    5724J0800

  • Reported release

    800

  • Status

    CLOSED PER

  • PE

    NoPE

  • HIPER

    NoHIPER

  • Special Attention

    NoSpecatt

  • Submitted date

    2012-05-16

  • Closed date

    2012-07-09

  • Last modified date

    2012-09-21

  • APAR is sysrouted FROM one or more of the following:

    PM59928

  • APAR is sysrouted TO one or more of the following:

    PM70232

Fix information

  • Fixed component name

    WEBSPHERE APP S

  • Fixed component ID

    5724J0800

Applicable component levels

  • R800 PSY

       UP

  • R850 PSY

       UP

[{"Business Unit":{"code":"BU059","label":"IBM Software w\/o TPS"},"Product":{"code":"SSEQTP","label":"WebSphere Application Server"},"Platform":[{"code":"PF025","label":"Platform Independent"}],"Version":"8.0","Line of Business":{"code":"LOB45","label":"Automation"}}]

Document Information

Modified date:
28 October 2021