I have seen NPEs with two different stack traces during tests:
1)
java.lang.NullPointerException
at java.util.AbstractCollection.addAll(AbstractCollection.java:320)
at org.infinispan.distribution.L1ManagerImpl.buildInvalidationAddressList(L1ManagerImpl.java:100)
at org.infinispan.distribution.L1ManagerImpl.flushCache(L1ManagerImpl.java:56)
at org.infinispan.interceptors.DistributionInterceptor.handleWriteCommand(DistributionInterceptor.java:390)
at org.infinispan.interceptors.DistributionInterceptor.visitRemoveCommand(DistributionInterceptor.java:218)
at org.infinispan.commands.write.RemoveCommand.acceptVisitor(RemoveCommand.java:70)
at org.infinispan.interceptors.base.CommandInterceptor.invokeNextInterceptor(CommandInterceptor.java:118)
at org.infinispan.interceptors.LockingInterceptor.visitRemoveCommand(LockingInterceptor.java:325)
at org.infinispan.commands.write.RemoveCommand.acceptVisitor(RemoveCommand.java:70)
at org.infinispan.interceptors.base.CommandInterceptor.invokeNextInterceptor(CommandInterceptor.java:118)
at org.infinispan.interceptors.base.CommandInterceptor.handleDefault(CommandInterceptor.java:132)
at org.infinispan.commands.AbstractVisitor.visitRemoveCommand(AbstractVisitor.java:63)
at org.infinispan.commands.write.RemoveCommand.acceptVisitor(RemoveCommand.java:70)
at org.infinispan.interceptors.base.CommandInterceptor.invokeNextInterceptor(CommandInterceptor.java:118)
at org.infinispan.interceptors.TxInterceptor.enlistWriteAndInvokeNext(TxInterceptor.java:186)
at org.infinispan.interceptors.TxInterceptor.visitRemoveCommand(TxInterceptor.java:139)
at org.infinispan.interceptors.DistTxInterceptor.visitRemoveCommand(DistTxInterceptor.java:86)
at org.infinispan.commands.write.RemoveCommand.acceptVisitor(RemoveCommand.java:70)
at org.infinispan.interceptors.base.CommandInterceptor.invokeNextInterceptor(CommandInterceptor.java:118)
at org.infinispan.interceptors.InvocationContextInterceptor.handleAll(InvocationContextInterceptor.java:95)
at org.infinispan.interceptors.InvocationContextInterceptor.handleDefault(InvocationContextInterceptor.java:62)
at org.infinispan.commands.AbstractVisitor.visitRemoveCommand(AbstractVisitor.java:63)
at org.infinispan.commands.write.RemoveCommand.acceptVisitor(RemoveCommand.java:70)
at org.infinispan.interceptors.InterceptorChain.invoke(InterceptorChain.java:273)
at org.infinispan.CacheDelegate.remove(CacheDelegate.java:226)
at org.infinispan.distribution.IllegalMonitorTest.testScenario(IllegalMonitorTest.java:64)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:636)... Removed 11 stack frames
2)
org.infinispan.CacheException: java.lang.NullPointerException
at org.infinispan.remoting.rpc.RpcManagerImpl.invokeRemotely(RpcManagerImpl.java:116)
...
at org.infinispan.distribution.IllegalMonitorTest.testScenario(IllegalMonitorTest.java:63)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:636)
Caused by: java.lang.NullPointerException
at org.infinispan.distribution.L1ManagerImpl.addRequestor(L1ManagerImpl.java:47)
at org.infinispan.interceptors.DistributionInterceptor.visitPutKeyValueCommand(DistributionInterceptor.java:203)
at org.infinispan.commands.write.PutKeyValueCommand.acceptVisitor(PutKeyValueCommand.java:76)
at org.infinispan.interceptors.base.CommandInterceptor.invokeNextInterceptor(CommandInterceptor.java:118)
at org.infinispan.interceptors.LockingInterceptor.visitPutKeyValueCommand(LockingInterceptor.java:297)
at org.infinispan.commands.write.PutKeyValueCommand.acceptVisitor(PutKeyValueCommand.java:76)
at org.infinispan.interceptors.base.CommandInterceptor.invokeNextInterceptor(CommandInterceptor.java:118)
at org.infinispan.interceptors.base.CommandInterceptor.handleDefault(CommandInterceptor.java:132)
at org.infinispan.commands.AbstractVisitor.visitPutKeyValueCommand(AbstractVisitor.java:59)
at org.infinispan.commands.write.PutKeyValueCommand.acceptVisitor(PutKeyValueCommand.java:76)
at org.infinispan.interceptors.base.CommandInterceptor.invokeNextInterceptor(CommandInterceptor.java:118)
at org.infinispan.interceptors.TxInterceptor.enlistWriteAndInvokeNext(TxInterceptor.java:186)
at org.infinispan.interceptors.TxInterceptor.visitPutKeyValueCommand(TxInterceptor.java:134)
at org.infinispan.interceptors.DistTxInterceptor.visitPutKeyValueCommand(DistTxInterceptor.java:79)
at org.infinispan.commands.write.PutKeyValueCommand.acceptVisitor(PutKeyValueCommand.java:76)
at org.infinispan.interceptors.base.CommandInterceptor.invokeNextInterceptor(CommandInterceptor.java:118)
at org.infinispan.interceptors.InvocationContextInterceptor.handleAll(InvocationContextInterceptor.java:95)
at org.infinispan.interceptors.InvocationContextInterceptor.handleDefault(InvocationContextInterceptor.java:62)
at org.infinispan.commands.AbstractVisitor.visitPutKeyValueCommand(AbstractVisitor.java:59)
at org.infinispan.commands.write.PutKeyValueCommand.acceptVisitor(PutKeyValueCommand.java:76)
...
Looks like cleanupRequestors() should also use synchronization.
It might also be better to lock on the requestors map values instead of the keys, as the keys can be also locked by user code.