Re: very, very serious problem - null values where objects should be

From: Andrus Adamchik (andru..bjectstyle.org)
Date: Thu Jun 08 2006 - 06:49:33 EDT

  • Next message: Andrus Adamchik: "Re: modeler, RC1 - misc. feedback"

    Can you run it in Eclipse (or some other) debugger and step through
    'getToLevel3Object' method? Then you can actually check the state of
    the objects and see if there is anything weird.

    If you still can't find anything, please open a Jira issue with a
    DataMap XML file attached with at least these three entities:
    Level1Object, Level2Object and Level3Object, with relationships
    between the entities preserved the way you have them now. I'll see if
    I can reproduce this.

    Andrus

    On Jun 8, 2006, at 2:21 PM, Tomi NA wrote:

    > On 6/6/06, Andrus Adamchik <andru..bjectstyle.org> wrote:
    >>
    >> On Jun 5, 2006, at 7:34 PM, Tomi NA wrote:
    >>
    >> > How would this provide more information than monitoring
    >> > setToObjectGroup() execution? Where is writeProperty used
    >> outside of
    >> > the setters?
    >>
    >> The framework can access objects bypassing the setters (e.g. this is
    >> how Generic Persistent Class operates [1], but this is also true for
    >> any DataObject).
    >>
    >> So since I don't know how your code is written, I am making general
    >> assumptions going from Cayenne end. There are two suspects. First is
    >> that the relationship is nullified indirectly by Cayenne in response
    >> to a sequence of events in the application. One more level down this
    >> path - can you try putting a thread dump in 'writePropertyDirectly'
    >> overriden method and see if it shows anything.
    >>
    >> Second is that serialization is somehow involved, as deserialization
    >> accesses fields directly.
    >>
    >> These are the two ways to bypass the setters. Otherwise I am out of
    >> ideas (without looking at the code that is).
    >
    > I've narrowed the problem down and now that I've done it, I can't
    > believe what I'm seeing.
    > I noticed that the problem occurs when I run my "advanced search".
    > Once I run it, I can isolate an object (just one of many) whose
    > relations have been set to null. I then proceeded to
    > System.out.println(object.getToGroup().getToGroupCluster().getName())
    > debugging, for reasons that are unlikely to become obvious at the
    > moment.
    > The idea of the code snippet is to fill the objList List with all
    > instances of level 1 objects, something along the lines "for the given
    > level4 object, get all level3 objects and for every level3 object get
    > all level2 objects and for all level2 objects, get all level 1
    > objects."
    >
    > Now, the debug statements inserted like this don't throw a
    > java.lang.NullPointerException:
    >
    > List<Level3Object> level3Objects =
    > criteria.getLevel4Object().getLevel3ObjectArray();
    > for (Level3Object u : level3Objects) {
    > List<Level2Object> level2Objects = u.getLevel2ObjectArray
    > ();
    > // 2 DEBUGGING STATEMENTS:
    > Level1Object l1o = (Level1Object)
    > DataObjectUtils.objectForPK(context, Level1Object.class, 31332);
    > System.out.println(l1o.getToLevel2Object
    > ().getToLevel3Object().getName());
    >
    > for (Level2Object l2o : level2Objects) {
    > objList.add(l2o);
    > }
    > }
    >
    > However, when I move the two debugging statements into the following
    > for-loop, I get the NullPointerException on the
    > System.out.println(...) because getLevel3Object() is null and
    > therefore can't call it's getName() method:
    >
    > List<Level3Object> level3Objects =
    > criteria.getLevel4Object().getLevel3ObjectArray();
    > for (Level3Object u : level3Objects) {
    > List<Level2Object> level2Objects =
    > u.getLevel2ObjectArray();
    > for (Level2Object l2o : level2Objects) {
    > Level1Object l1o = (Level1Object)
    > DataObjectUtils.objectForPK(context, Level1Object.class, 31332);
    > System.out.println(l1o.getToLevel2Object().getToLevel3Object
    > ().getName());
    > objList.add(l2o);
    > }
    > }
    >
    > I can't for the life of me guess what the final for-loop does that
    > nullifies the relevant object relationship.
    >
    > t.n.a.
    >



    This archive was generated by hypermail 2.0.0 : Thu Jun 08 2006 - 07:16:42 EDT