Hello Christian,
I checked again my code, but I am quite sure that each LocalSession is created and used by only one thread.
I attach the test application code.
Each LocalSession is used to execute several commands, but that shouldn't be a problem, right ?
I also had a look in BaseX code, especially in the org.basex.core.users.User class.
What happens in my test application is that I create several Writer that will add XML document each in a specific collection, but using the same user.
Each time I create a new Writer it will first create the collection then grant read and write permission to this collection to the user "USER", and then start adding XML document in this collection.
My suspicion is that the problem occurs when a new Writer is created, and it is granting permission to the newly created collection while another Writer (in another thread) is adding a new XML document in its own collection.
If, during the execution of the Grant command, the method User#perm(final Perm prm, final String pattern) is called while the execution of a concurrent Write command is at the same time executing the User#find(final String db) method, then we have a ConcurrentModificationException as perm method will put a new entry in locals field while the find method is iterating on the locals entrySet of the same User, the same User instance being shared by all subcontext created when opening a new LocalSession.
For test purposes, I synchronized the access to locals in the perm(), find() and remove() methods of the class User, in that case I do not have the ConcurrentModificationException any more.
What do you think, is this possible ?
Regards