apache / datasketches-java

A software library of stochastic streaming algorithms, a.k.a. sketches.

Home Page:https://datasketches.apache.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

NullPointerException on ANotB

mix74rus opened this issue · comments

IntegerSketch x = new IntegerSketch(12, 2, 0.1f, IntegerSummary.Mode.Min);
IntegerSketch y = new IntegerSketch(12, 2, 0.1f, IntegerSummary.Mode.Min);
x.update(1L, 1);
IntegerSummarySetOperations setOperations = new IntegerSummarySetOperations(IntegerSummary.Mode.Min, IntegerSummary.Mode.Min);
Intersection<IntegerSummary> intersection = new Intersection<>(setOperations);
CompactSketch<IntegerSummary> intersect = intersection.intersect(x, y);
AnotB.aNotB(x, intersect); // NPE here
java.lang.NullPointerException
	at org.apache.datasketches.HashOperations.hashArrayInsert(HashOperations.java:170)
	at org.apache.datasketches.HashOperations.convertToHashTable(HashOperations.java:341)
	at org.apache.datasketches.tuple.AnotB.getResultArraysTuple(AnotB.java:357)
	at org.apache.datasketches.tuple.AnotB.aNotB(AnotB.java:255)

Thanks for the report and example code, @mix74rus

Can you let us know what release version this was (or if it was current main branch)?

To my mind looks like the root cause of such behaviour is that intersect sketch has null in hashArr_ (and summaryArr_ for that matter), but at the same time empty_ flag is set to false.

Going farther, such state of sketch might occur because samplingProbability was not equal to 1. (notice intentionally passed 0.1f as samplingProbability in IntegerSketch constructor) and there was no retained entries, so this code does his thing and peacefully sets empty flag to false. But i'm not quite sure about this last part.

Can you let us know what release version this was (or if it was current main branch)?

Currently i'm using 2.0.0 release version and example was tested with version too. But looks like this would also reproduce in master.

Also I noticed that switching arguments in the last line of my example also leads to NPE but in other place.

Caused by: java.lang.NullPointerException
	at org.apache.datasketches.tuple.AnotB.getDataArraysA(AnotB.java:332) ~[datasketches-java-2.0.0.jar:?]
	at org.apache.datasketches.tuple.AnotB.aNotB(AnotB.java:248) ~[datasketches-java-2.0.0.jar:?]

Is your PR fixes that?

Your issue inspired me to look deeper where I have found a number of very subtle corner-case issues, which I am working to resolve. I am pretty confident I have uncovered them all. However, at the same time I am taking the time to do some refactoring that will make it easier to test and understand the code in the future. Please be patient :)

This bug should be considered fixed and is currently in master awaiting the next release.