When using an iron sword and switching to another tool in the quickbar after using the sword, it is often replaced by a duplicate of the tool to which has been switched.
I did not use any other sword material than iron, so i can't say if it happens with other swords like stone swords or diamond swords.
This problem only occurs while playing on Minecraft Realms and does happen randomly after using the sword and switching to another tool.
Comments 2
It seems that this always happen while actively fighting against mobs using the sword or other tools.
When attacking a mob and switching to another tool at the same time there is a potential chance to get the active tool replaced by that one you switched too.
Seems to be some kind of failure in synchronizing the current state of the server and the client inventory.
I have the same issue.