I'm getting the exception:
org.eclipse.core.internal.resources.ResourceException: The resource tree is locked for modifications.
After some searching I found out, that this comes from the fact that I am trying to add markers to a file. I'm doing this, when I am notified of a file change. So when my modification code is called the workspace is still in the middle of the notifying process and does not allow modifications to the resource tree.
How can I save markers so that I can add them to the file later or what would be another way to delay this changes?
You can't modify the resource tree from a resource delta event handler (imagine the potential for complete chaos if you could). The most common approach that I know of is to schedule a Job and make the modifications within the run() method of the Job. This means you need to remember the modifications that you want to make so that they can be done within the Job. It also means you can't make too many assumptions about the state of the resource tree because theoretically some other Job might run before yours that makes changes to the tree.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With