79799340

Date: 2025-10-25 06:07:32
Score: 1.5
Natty:
Report link

Two threads contend for the same lock. After first one releases it, the second will still acquire it. But before the second unlocks, the first will remove the lock from the map leading to NullPointerException.

Fix: You must hold a reference to the lock on the first get. (Use computeIfAbsent for simplicity). This ensures that even if the cache is cleared, the threads that are waiting on the lock are not affected.

Reasons:
  • No code block (0.5):
  • Low reputation (1):
Posted by: Isira Ratnayake