Torque
  1. Torque
  2. TORQUE-107

calling getRelatedObjects(Criteria) can result in NullPointerException if the collection has not be initialized (with a Criteria)

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: 3.3-RC1
    • Fix Version/s: 4.0-beta1
    • Component/s: Generator
    • Labels:
      None
    • Environment:
      RHEL 5, Java 6, Oracle 10g

      Description

      The Object.vm template and generator produce object classes with

      public List<SomeClass> getSomeClasss(Criteria criteria) throws TorqueException

      If torque.objectIsCaching is set, this method uses a "last used Criteria" comparison to determine whether or not to re-fetch the Collection of <SomeClass>. The way the template (Object.vm) is written, we wind up with

      if (!lastSomeClassCriteria.equals(criteria))
      ...

      which can throw NullPointerException if this is the first time this method is called (lastSomeClassCriteria will be null).

      This could be fixed by changing the comparison to

      if (!criteria.equals(last$

      {relCol}Criteria))

      or

      if (last${relCol}

      Criteria == null || !last$

      {relCol}

      Criteria.equals(criteria))

      Granted, there are other ways to achieve these results (create the appropriate Criteria and call SomeClassPeer.doSelect(Criteria)), but the "getRelatedObjects(Criteria)" method is a handy abstraction that is already generated for each class.

        Activity

        Hide
        Thomas Fox added a comment -

        Patch applied, thanks

        Show
        Thomas Fox added a comment - Patch applied, thanks
        Hide
        Scott Eade added a comment -
        Show
        Scott Eade added a comment - Somewhere in test/test-project - see http://db.apache.org/torque/developer-info/test-project.html
        Hide
        Brendan Miller added a comment -

        Would the testcase belong in the generator? I'm trying to think how to simulate this outside of a full-blown application.

        Show
        Brendan Miller added a comment - Would the testcase belong in the generator? I'm trying to think how to simulate this outside of a full-blown application.
        Hide
        Scott Eade added a comment -

        I can't see an obvious way to make this happen, so a test case will definitely be required.

        Show
        Scott Eade added a comment - I can't see an obvious way to make this happen, so a test case will definitely be required.
        Hide
        Scott Eade added a comment -

        Would it be possible to provide a test case for this.

        Show
        Scott Eade added a comment - Would it be possible to provide a test case for this.

          People

          • Assignee:
            Thomas Fox
            Reporter:
            Brendan Miller
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development