maidh91 / guava-libraries

Automatically exported from code.google.com/p/guava-libraries
Apache License 2.0
0 stars 0 forks source link

Annotate parameters of Ordering methods as @Nullable #346

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Some methods of Ordering (e.g. compare, min, max) can sometimes be passed 
null arguments, e.g. if the ordering was returned by Ordering.nullsFirst() 
or Ordering.nullsLast().

The parameters could be annotated @Nullable, but maybe it would make more 
sense to add a public intermediate class (returned by nullsFirst() and 
nullsLast()) that has @Nullable parameters, overriding the (sensible) 
default of @NonNull for the parameters of Comparator.compare.

e.g.

public abstract class Ordering<T> {

  public NullableOrdering nullsFirst() {
    return new NullsFirstOrdering(this);
  }

  private static class NullsFirstOrdering<T> extends NullableOrdering<T> {
    // ...
  }

}

public abstract class NullableOrdering<T> extends Ordering<T> {

  public abstract int compare(@Nullable T a, @Nullable T b);

  public abstract T min(@Nullable T a, @Nullable T b);

  // ...
}

Original issue reported on code.google.com by fin...@gmail.com on 8 Apr 2010 at 9:57

GoogleCodeExporter commented 9 years ago
Aigh.  I believe that @Nullable status is not going to be nearly enough 
justification 
to create a new public type.  So we have to just add @Nullable to these 
Ordering 
methods. I believe @Nullable is only supposed to mean "might accept null", as 
opposed 
to "definitely rejects null".

Original comment by kevinb@google.com on 9 Apr 2010 at 7:12

GoogleCodeExporter commented 9 years ago

Original comment by kevinb@google.com on 30 Jul 2010 at 3:50

GoogleCodeExporter commented 9 years ago
thanks!

Original comment by kevinb@google.com on 14 Sep 2010 at 8:50

GoogleCodeExporter commented 9 years ago
This issue has been migrated to GitHub.

It can be found at https://github.com/google/guava/issues/<id>

Original comment by cgdecker@google.com on 1 Nov 2014 at 4:15

GoogleCodeExporter commented 9 years ago

Original comment by cgdecker@google.com on 3 Nov 2014 at 9:10