Well I'll be… Over two decades of full time Java and I somehow didn't know
about that stack trace omission. Yikes. Thanks!
Now, looking at the first occurrence of the exception after app startup, I see
the NPE is happening in @PreUpdate on a listener registered to my DataDomain.
The offending code looks a bit like this:
@PreUpdate({ BaseDataObject.class })
public void handleUpdate( final BaseDataObject dataObject ) {
final DataContext dc = (DataContext)dataObject.getObjectContext();
final ObjectId objectId = dataObject.getObjectId();
final ObjEntity entity = dc.getEntityResolver().getObjEntity(
objectId.getEntityName() );
final DataRow snapshot = dc.getObjectStore().getSnapshot( objectId );
for( final ObjAttribute objAttribute : entity.getAttributes() ) {
final Object originalValue = snapshot.get(
objAttribute.getDbAttributeName() );
[ ... irrelevant rest of code omitted ... ]
}
}
…the NPE gets thrown by the first line in the for-loop (…snapshot.get(
objAttribute.getDbAttributeName() )).
So it seems either 'snapshot' or 'objAttribute' is null, probably the snapshot,
right? Any ideas why that might be?
- hugi
> On 7 May 2021, at 12:53, John Huss <[email protected]> wrote:
>
> Or if you have older logs, you can look back farther to find one without
> the cause omitted.
>
> On Fri, May 7, 2021 at 7:52 AM John Huss <[email protected]> wrote:
>
>> It will omit the trace if it has happened a very large number of times. If
>> you restart the server it will start printing it again when it happens.
>>
>> On Fri, May 7, 2021 at 7:26 AM Hugi Thordarson <[email protected]> wrote:
>>
>>> One would think so, but there's just no stack trace printed for the
>>> NullPointerException.
>>>
>>>
>>>> On 7 May 2021, at 12:24, John Huss <[email protected]> wrote:
>>>>
>>>> The first line of the stack after the Caused By line would tell you the
>>>> line with the problem, wouldn't it? What was that line?
>>>>
>>>> On Fri, May 7, 2021 at 7:16 AM Hugi Thordarson <[email protected]>
>>> wrote:
>>>>
>>>>> Hi all,
>>>>>
>>>>> occasionally my users encounter errors when committing changes to the
>>> DB.
>>>>> The relevant part of the stack trace looks like this:
>>>>>
>>>>> ---------
>>>>> org.apache.cayenne.CayenneRuntimeException: [v.4.1 Jul 14 2020
>>> 10:26:08]
>>>>> Commit Exception
>>>>> at
>>>>>
>>> org.apache.cayenne.access.DataContext.flushToParent(DataContext.java:774)
>>>>> at
>>>>>
>>> org.apache.cayenne.access.DataContext.commitChanges(DataContext.java:691)
>>>>> [...removed rest of trace…]
>>>>> Caused by: java.lang.NullPointerException
>>>>> ---------
>>>>>
>>>>> Unfortunately I've been unable to reproduce this error, so before I
>>> dive
>>>>> into it I'm wondering if this looks familiar to anyone, if there are
>>>>> obvious places to look or if there are recommendations for strategies
>>> to
>>>>> debug?
>>>>>
>>>>> Cheers,
>>>>> - hugi
>>>
>>>