0

So here I have a really strange mistake on my treemap that happen from time to time.

There she is :

java.lang.NullPointerException
At java.util.TreeMap.rotateRight (TreeMap.java:2243)
At java.util.TreeMap.fixAfterInsertion (TreeMap.java:2275)
At java.util.TreeMap.put (TreeMap.java:582)

The error is made an addition of an object in a map therefore.

I understand that this was a very rare case since it is actually two threads that start at the same time to do the same action. A check to avoid duplicates is done and the error is well on the put, so that's why I think that's the worry. Would a sync on this map solve the worry? While knowing that there are instructions in strings: We load characters, we load the items. If we have a worry about the load of the items, it is that there is a double load of the character simultaneously.

So I would like your opinion on that and above all, would you have an idea how to solve the problem? Knowing that the method "I try then we see what it gives to the compilation" can not work because I can reproduce the bug at my will.

Thank you in advance if you get to help me, or else you try at least :)

JuuM
  • 1
  • 2
  • 1
    Possible duplicate of [What is a NullPointerException, and how do I fix it?](https://stackoverflow.com/questions/218384/what-is-a-nullpointerexception-and-how-do-i-fix-it) – Paul Karam Jun 09 '17 at 14:34
  • I think it's just because your `Entry` had a null (left) child. – Jeremy Grand Jun 09 '17 at 14:45
  • Are you saying that you’re accessing the TreeMap from multiple threads without any thread safety measures? – VGR Jun 09 '17 at 15:17
  • Please refer https://stackoverflow.com/questions/37048084/is-this-null-pointer-exception-in-treemap-due-to-concurrent-access – Shubham Srivastava Apr 02 '19 at 07:05

0 Answers0