Hi there,
I believe a little more information about your setup and/or use case is required to help you fix this issue.
The modified_by_id will update after a change to the item has been made, but you might get discrepancies if you are inside an onBeforeUpdate or onBeforeVersion method and try to access this information.
The ItemIsNotLockedException could indicate that you are "apply()"-ing a change on an item inside a method that results in another change "apply()"-ed on that item. I would always be careful with using apply() on items within any onBefore/AfterUpdate/Version etc method, since you are unlocking the item implicitly when, for example, applying an edit-action on an item. This then leads to the exception when the update that caused the onBeforeUpdate-method to trigger tries to apply() its changes and finds an unlocked item (to which update/edit-actions cannot be applied).
For some setups, however, you can simply set the new property on the Item in the onBeforeXxxx-method without using apply() and have your change committed to the database using the implicit apply() in the scope that the method gets called in. But, to advise anything more specific, a little more information on your setup would be required.
Hope this helps,
C