You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@openjpa.apache.org by Michael Dick <mi...@gmail.com> on 2010/08/11 20:56:44 UTC

Re: Re: NullPointerException in pcGet-Method

Hi Heiko, comments below.

On Fri, Jul 30, 2010 at 2:03 AM, <it...@daimler.com> wrote:

> Helo Michael,
>
> I'm almost entirely sure that there is no sharing between threads. In our
> system the webservice handling method is created via ThreadLocal. There
> may be about 100 parallel handlers, each having its own thread for
> handling requests. When a handler starts, it obtains an EntityManager that
> is again created via ThreadLocal, thus there will be the same entity
> manager for the same thread. As much as I understand from openJPA, the
> entity manager handles the the entities and keeps track of them.
>
> We never close the entity manager, but rather let it open for reuse, but
> as noted only in the same thread protected by ThreadLocal. No new threads
> are spawned or created while handling a single webservice request. No
> entities are being stored anywhere in the request handling code, neither
> statically or as instances.
>
> This is the dilemma here, I've really put efford in finding out if the
> entites have been shared, but I simply can't find any situation where this
> can be true.
>

I can't dispute your research. It sounds like you've done a lot of looking.


> And just my two cents. Its fine that the state manager is nulled but in
> that case, this shall not lead to an NPE IMHO, don't you think?


Well that's the crux of the matter, I took another look at the code :

private static final EconomicRelationshipGroup
pcGetgroup(EconomicRelationship paramEconomicRelationship)
 {
   if (paramEconomicRelationship.pcStateManager == null)  // Point A:  we
check for null
     return paramEconomicRelationship.group;
   int i = pcInheritedFieldCount + 1;
   paramEconomicRelationship.pcStateManager.accessingField(i); // Point B:
NPE occurs.
   return paramEconomicRelationship.group;
 }

How can paramEconomicRelationship.pcStateManager be non-null at point A but
null at point B unless another thread has modified it? Either the entity (or
EntityManager) is accessed on multiple threads with one of them setting it
to null, or we're looking in the wrong spot.

What would help here is a testcase that reproduces the problem - maybe a
jUnit that spawns threads and saves the EMs in threadLocal?


> And even
> weirder is that in my error I do not even query a complex entity, like an
> embedded key or something. Its a simple Long-Value. That shall even WORK
> for detached objects, don't you think (again)? *smirk*
>

I'm not sure what you're saying here. Once an entity is detached you
certainly should not be able to access any unloaded fields regardless of
whether they're embedded. I think I'm missing the point of your assertion
though.

-mike


> Thanks for all your help in tracking this down.
>
> Best regards,
>
> Heiko
>
>
>
>
> michael.d.dick@gmail.com
> 29.07.2010 16:17
> Bitte antworten an
> users@openjpa.apache.org
>
>
> An
> users@openjpa.apache.org
> Kopie
>
> Thema
> Re: NullPointerException in pcGet-Method
>
>
>
>
>
>
> Disclaimer: there's been a lot of discussion on OPENJPA-453 - I haven't
> digested all of it.
>
> The testcase for OPENJPA-453 has a single entity (not EntityManager) being
> accessed by two threads simultaneously. Heiko, are you sure the entity
> instances are not shared between threads?
>
> The StateManager may be nulled out when the entity is detached or evicted
> (based on OPENJPA-453). So the only way you _should_ be able to get into
> this case is if the entity is accessed on multiple threads - one thread
> detaches / evicts and the other uses it.
>
> Christiaan, I don't think the statemanager will be nulled on refresh() -
> if
> you've seen differently that's good data.
>
> -mike
>
>
> On Wed, Jul 28, 2010 at 6:09 AM, Christiaan
> <ch...@hotmail.com>wrote:
>
> >
> > Hi Heiko,
> > your situation seems related to this one (also see related jira issue
> > http://issues.apache.org/jira/browse/OPENJPA-453):
> >
> >
>
> http://openjpa.208410.n2.nabble.com/NullPointerException-in-pcReplaceField-td2979657.html#a2979657
>
> >
> > Although in this scenario the nullpointer relates to the statemanager of
> > the
> > embedded object. You do have an embedded primary key object, however the
> > nullpointer seems to happen in the owning object? I can imagine that
> > nullifying the statemanager happens with the refresh() call. My own
> > experience is that it happens with the evict() or commit() with
> > retainValues
> > set to false.
> >
> > Personally I think this really is a problem related to multithreading in
> > the
> > internal structures of OpenJPA, since the nullpointer happens in code
> > generated by OpenJPA. Accessing the statemanager and at the same time
> > nullifying it is something OpenJPA code is aware of, not the application
> > programmer.
> >
> > regards,
> > Christiaan
> > --
> > View this message in context:
> >
>
> http://openjpa.208410.n2.nabble.com/NullPointerException-in-pcGet-Method-tp5337474p5345501.html
>
> > Sent from the OpenJPA Users mailing list archive at Nabble.com.
> >
>
>
>
> If you are not the intended addressee, please inform us immediately that
> you have received this e-mail in error, and delete it. We thank you for your
> cooperation.