vigna / fastutil

fastutil extends the Java™ Collections Framework by providing type-specific maps, sets, lists and queues.
Apache License 2.0
1.76k stars 196 forks source link

Using Strategy to check for null #241

Closed arunthirupathi closed 3 years ago

arunthirupathi commented 3 years ago

I am trying to upgrade fastutil from 6.5.9 version to 8.5.2 in Presto (Open source query engine, that has connector to lot of databases).

During the upgrade all of the Strategy equals method is raising NPE, because the Strategy is used for null check. The collections can't contain null from the application, so the strategy does not handle nulls.

Why is the Strategy used for null check ? wouldn't it be simpler to do if (k == null) instead of if ( this.strategy.equals(k, (Object) null)) ?

public boolean add(K k) {
        if (this.strategy.equals(k, (Object)null)) {
            if (this.containsNull) {
                return false;
            }

            this.containsNull = true;
            this.key[this.n] = k;
        } else {
            K[] key = this.key;
            int pos;
vigna commented 3 years ago

That's the current approach—you must be able to handle null. People is interested in having a completely customized equality concept, which includes using null for representing an equivalence class of objects.

arunthirupathi commented 3 years ago

Thanks, no worries.