cayenne-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From David Feshbach <djfeshb...@gmail.com>
Subject Race Condition in o.a.c.u.ReferenceMap.values() Causing NPE in ObjectStore.objectsInState(int)
Date Fri, 10 Nov 2017 17:15:57 GMT
This is in 4.1.M1

The stack trace is pretty short:
java.lang.NullPointerException
at
org.apache.cayenne.access.ObjectStore.objectsInState(ObjectStore.java:520)
at org.apache.cayenne.access.DataContext.newObjects(DataContext.java:242)
...

The problem is in ReferenceMap.values(). If the GC runs between
checkReferenceQueue() and the last v.get(), then null can be added to the
collection (when using the default WeakValueMap). keySet() and entrySet()
have similar issues.

I tried simply adding a check to exclude nulls from the collection, but I
get a test failure in WeakValueMapTest.testMapConstructor() because it
expects (a weak reference to) null to stay in the map.

What's the proper behavior here? Should weak mappings really allow null?
I'm surprised you're even allowed to create a reference with a null
referent.

Thanks,
David

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message