#956 HDictBuilder NullPointerException

Bryant Holland Tue 26 Oct 2021

Hi,

I recently ran into an issue where the HDictBuilder class was throwing a NullPointerException when calling a .has() call. After investigating, I noticed that the HDictBuilder constructor can cause a NullPointerException if nothing is added to the HashMap and you try calling a .has() or a .size() call.

That is because the constructor doesn't initialize the HashMap in anyway. The HashMap gets initialized once a .add() is called on it. In my mind, this could cause issues like the ones I ran into as it is odd to throw exceptions on an empty HDictBuilder variable.

So my question is this: Can the initialization be added to the constructor of the HDictBuilder? If not, can someone explain why it is implemented this way? Just trying to understand the best way around this issue.

My current solution is calling .toDict() now before doing any .has() or .size() calls on it, as the .toDict() call checks for a null HashMap before proceeding.

Thanks in advance!

Chris Breederveld Tue 26 Oct 2021

Hi Bryant, what library and version are you using?

Bryant Holland Thu 4 Nov 2021

Hi Chris - I'm pretty sure I'm using an outdated library, but not entirely sure. Looking back at my repo history, I had originally pulled the nHaystack 2.1.0 version, and I don't think I've updated it since.

Would you recommend that I merge into the newest nHaystack version, as this issues keeps popping up for me?

Chris Breederveld Thu 4 Nov 2021

Unfortunately I can't help you with this library, as I only work in the C# lib. But perhaps this info will trigger someone else who does.

Login or Signup to reply.