In my (multiplayer) world, I briefly switched to Creative mode to get an aerial view of our base for a screenshot. However, when I returned to the ground and switched back to survival mode, I couldn't gain any XP at all. None from zombies, none from villagers, coal went right through me. I tried restarting my game, restarting the server, and restarting my computer in hopes that it would work.
It didn't.
After grinding at my zombie spawner for around ten minutes, my EXP came back.
Even though you got your XP back, this is still a bug that should be fixed.