cayenne-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Tomi NA" <hef...@gmail.com>
Subject Re: very, very serious problem - null values where objects should be
Date Thu, 08 Jun 2006 10:21:34 GMT
On 6/6/06, Andrus Adamchik <andrus@objectstyle.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.

Mime
View raw message