How to reproduce:
1. Trade melons (or anything else for that matter) with a villager.
2. Sell him out of the melon while still holding melon.
3. Close the villager GUI.
4. even though you just sold him out, he will keep holding the emerald (which you get by giving him the melon).
5. hold something else (no melon).
6. His hand-item (emerald) will disappear
7. swap back to melon
8. he wont hold the emerald anymore
Thank you for your report!
We're tracking this issue in MC-196916, so this ticket is being resolved and linked as a duplicate.
If you would like to add a vote and any extra information to the main ticket it would be appreciated.
If you haven't already, you might like to make use of the search feature to see if the issue has already been mentioned.
Quick Links:
📓 Bug Tracker Guidelines – 💬 Community Support – 📧 Mojang Support
📓 Project Summary – ✍️ Feedback and Suggestions – 📖 Game Wiki