On 4/5/11 11:33 AM, Francis ANDRE wrote:
Hi Developers
I got sporadic NPE as follow. Has someone an idea of the context that could
lead to such NPE so I can try to find out how to always reproduce this NPE??
It can occurs in rare cases where the service is disposed, as the pool
will be cleared (at least, this is what I can infer from the code).
Here is the code that generates a NPE :
public final void add(S session) {
getProcessor(session).add(session);
}
private IoProcessor<S> getProcessor(S session) {
IoProcessor<S> processor = (IoProcessor<S>)
session.getAttribute(PROCESSOR);
if (processor == null) {
if (disposed || disposing) {
throw new IllegalStateException("A disposed processor
cannot be accessed.");
}
processor = pool[Math.abs((int) session.getId()) %
pool.length]; /// --> Here, if the pool is cleared, we will get a null
processor
session.setAttributeIfAbsent(PROCESSOR, processor);
}
return processor;
}
and the part that clear the pool :
public final void dispose() {
if (disposed) {
return;
}
synchronized (disposalLock) {
...
Arrays.fill(pool, null); /// -->> Here, the pool will now
contain nulls
disposed = true;
}
}
--
Regards,
Cordialement,
Emmanuel Lécharny
www.iktek.com