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

NPE in QueryKey.createKey using criteria with QueryCache enabled

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 2.2.1, 2.2.2, 2.3.0, 2.4.0
    • Fix Version/s: 2.2.1.1, 2.2.3, 2.4.0
    • Component/s: criteria, datacache
    • Labels:
      None

      Description

      Running an example in the spec using Criteria API with "left join fetch" AND query cache enabled yield the following NPE exception. See the testcase to reproduce the problem and the spec section where the example comes from:

      <openjpa-2.2.1.1-SNAPSHOT-r422266:1438134 nonfatal user error> org.apache.openjpa.persistence.ArgumentException: Failed to execute query "null". Check the query syntax for correctness. See nested exception for details.
      at org.apache.openjpa.kernel.QueryImpl.execute(QueryImpl.java:872)
      at org.apache.openjpa.kernel.QueryImpl.execute(QueryImpl.java:794)
      at org.apache.openjpa.kernel.DelegatingQuery.execute(DelegatingQuery.java:542)
      at org.apache.openjpa.persistence.QueryImpl.execute(QueryImpl.java:286)
      at org.apache.openjpa.persistence.QueryImpl.getResultList(QueryImpl.java:302)
      at com.ibm.ws.persistence.QueryImpl.getResultList(QueryImpl.java:118)
      at test.TestNPE.test(TestNPE.java:62)
      ......
      Caused by: java.lang.NullPointerException
      at org.apache.openjpa.datacache.QueryKey.createKey(QueryKey.java:203)
      at org.apache.openjpa.datacache.QueryKey.newInstance(QueryKey.java:139)
      at org.apache.openjpa.datacache.QueryCacheStoreQuery$QueryCacheExecutor.executeQuery(QueryCacheStoreQuery.java:339)
      at org.apache.openjpa.kernel.QueryImpl.execute(QueryImpl.java:1005)
      at org.apache.openjpa.kernel.QueryImpl.execute(QueryImpl.java:863)
      ... 33 more

      1. OPENJPA-2502.221x.patch
        25 kB
        Albert Lee
      2. OPENJPA-2502.test.zip
        6 kB
        Albert Lee

        Activity

        Hide
        allee8285 Albert Lee added a comment -

        The NPE comes from the following code fragment in createKey() where q.getAccessPathMetaDatas() returns
        [null, test.Department] and subsequent meta.getDescribedType() on the first element takes the NPE.

        // we can't cache the query if we don't know which classes are in the
        // access path
        ClassMetaData[] metas = q.getAccessPathMetaDatas();
        if (metas.length == 0)
        return null;

        Set<String> accessPathClassNames = new HashSet<String>((int) (metas.length * 1.33 + 1));
        ClassMetaData meta;
        for (int i = 0; i < metas.length; i++) {
        // since the class change framework deals with least-derived types,
        // record the least-derived access path types
        meta = metas[i];
        accessPathClassNames.add(meta.getDescribedType().getName()); <<<< NPE
        while (meta.getPCSuperclass() != null)

        { meta = meta.getPCSuperclassMetaData(); }

        accessPathClassNames.add(meta.getDescribedType().getName());
        }

        Show
        allee8285 Albert Lee added a comment - The NPE comes from the following code fragment in createKey() where q.getAccessPathMetaDatas() returns [null, test.Department] and subsequent meta.getDescribedType() on the first element takes the NPE. // we can't cache the query if we don't know which classes are in the // access path ClassMetaData[] metas = q.getAccessPathMetaDatas(); if (metas.length == 0) return null; Set<String> accessPathClassNames = new HashSet<String>((int) (metas.length * 1.33 + 1)); ClassMetaData meta; for (int i = 0; i < metas.length; i++) { // since the class change framework deals with least-derived types, // record the least-derived access path types meta = metas [i] ; accessPathClassNames.add(meta.getDescribedType().getName()); <<<< NPE while (meta.getPCSuperclass() != null) { meta = meta.getPCSuperclassMetaData(); } accessPathClassNames.add(meta.getDescribedType().getName()); }
        Hide
        allee8285 Albert Lee added a comment -

        The NPE is caused by the CriteriaExpressionBuilder trying to find the metadata for the join fetch field. Since this field is mostly a collection, the metadata class is of collection type, hence there is no metadata in the repository, hence a null is stored in the metas array. Subsequently, when the metas array is processed the NPE is surfaced.

        I tried the equivalent JPQL as the criteria API and the JPQLExpressionBuilder does not include any metadata for the fetch clause.

        Show
        allee8285 Albert Lee added a comment - The NPE is caused by the CriteriaExpressionBuilder trying to find the metadata for the join fetch field. Since this field is mostly a collection, the metadata class is of collection type, hence there is no metadata in the repository, hence a null is stored in the metas array. Subsequently, when the metas array is processed the NPE is surfaced. I tried the equivalent JPQL as the criteria API and the JPQLExpressionBuilder does not include any metadata for the fetch clause.
        Hide
        jira-bot ASF subversion and git services added a comment -

        Commit 1597006 from Heath Thomann in branch 'openjpa/branches/2.2.1.x'
        [ https://svn.apache.org/r1597006 ]

        OPENJPA-2502: NPE in QueryKey.createKey using criteria with QueryCache enabled - committed Albert Lee's patch.

        Show
        jira-bot ASF subversion and git services added a comment - Commit 1597006 from Heath Thomann in branch 'openjpa/branches/2.2.1.x' [ https://svn.apache.org/r1597006 ] OPENJPA-2502 : NPE in QueryKey.createKey using criteria with QueryCache enabled - committed Albert Lee's patch.
        Hide
        jira-bot ASF subversion and git services added a comment -

        Commit 1597007 from Heath Thomann in branch 'openjpa/branches/2.2.1.x'
        [ https://svn.apache.org/r1597007 ]

        OPENJPA-2502: NPE in QueryKey.createKey using criteria with QueryCache enabled - committed Albert Lee's patch to 2.2.1.x

        Show
        jira-bot ASF subversion and git services added a comment - Commit 1597007 from Heath Thomann in branch 'openjpa/branches/2.2.1.x' [ https://svn.apache.org/r1597007 ] OPENJPA-2502 : NPE in QueryKey.createKey using criteria with QueryCache enabled - committed Albert Lee's patch to 2.2.1.x
        Hide
        jira-bot ASF subversion and git services added a comment -

        Commit 1600682 from Rick Curtis in branch 'openjpa/trunk'
        [ https://svn.apache.org/r1600682 ]

        OPENJPA-2502 : Update accessPath metas in CriteriaExpressionBuilder. Merged changes from 2.2.1.x. Patch contributed by Albert Lee.

        Show
        jira-bot ASF subversion and git services added a comment - Commit 1600682 from Rick Curtis in branch 'openjpa/trunk' [ https://svn.apache.org/r1600682 ] OPENJPA-2502 : Update accessPath metas in CriteriaExpressionBuilder. Merged changes from 2.2.1.x. Patch contributed by Albert Lee.
        Hide
        jira-bot ASF subversion and git services added a comment -

        Commit 1602050 from Heath Thomann in branch 'openjpa/branches/2.2.x'
        [ https://svn.apache.org/r1602050 ]

        OPENJPA-2502: Update accessPath metas in CriteriaExpressionBuilder. Merged changes from trunk. Patch contributed by Albert Lee.

        Show
        jira-bot ASF subversion and git services added a comment - Commit 1602050 from Heath Thomann in branch 'openjpa/branches/2.2.x' [ https://svn.apache.org/r1602050 ] OPENJPA-2502 : Update accessPath metas in CriteriaExpressionBuilder. Merged changes from trunk. Patch contributed by Albert Lee.
        Hide
        jira-bot ASF subversion and git services added a comment -

        Commit 1602059 from Heath Thomann in branch 'openjpa/branches/2.3.x'
        [ https://svn.apache.org/r1602059 ]

        OPENJPA-2502: Update accessPath metas in CriteriaExpressionBuilder. Merged changes from trunk. Patch contributed by Albert Lee.

        Show
        jira-bot ASF subversion and git services added a comment - Commit 1602059 from Heath Thomann in branch 'openjpa/branches/2.3.x' [ https://svn.apache.org/r1602059 ] OPENJPA-2502 : Update accessPath metas in CriteriaExpressionBuilder. Merged changes from trunk. Patch contributed by Albert Lee.

          People

          • Assignee:
            jpaheath Heath Thomann
            Reporter:
            allee8285 Albert Lee
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development