ACMNexus / google-collections

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

Function.apply interface is incompatible with implementation #126

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Function.apply() is inconsistent with Functions.ToStringFunction.  The
consequence is that a client who is using Function according to its
documentation may suffer an unexpected null pointer exception.

Function.apply() is declared as

    T apply(@Nullable F from);

and the @Nullable annotation means (according to its Javadoc):

   The presence of this annotation on a method parameter indicates that
   null is an acceptable value for that parameter.

However, the documentation for Functions.toStringFunction says:

  /**
   * Returns a function that calls {@code toString()} on its argument. The
   * function does not accept nulls; it will throw a
   * {@link NullPointerException} when applied to {@code null}.
   */
  public static <F> Function<F, String> toStringFunction() {

If Function says that null is an acceptable argument to apply(), then any
subclass must also satisfy that contract.  (This property is required by
behavioral subtyping, which is also known as substitutability.)

Without knowing the design rationale, I'm not sure which of the Function
interface and the ToStringFunction implementation should be changed, but
they should be made consistent.

Original issue reported on code.google.com by michael.ernst@gmail.com on 4 Mar 2009 at 11:13

GoogleCodeExporter commented 8 years ago
Our Nullable annotation is effed.  We're ripping it out and replacing it with 
the
JSR-305 Nullable annotation, which is defined more appropriately.  We've run 
FindBugs
and told it to treat our Nullable annotation as if it was the other one, and 
fixed
the few problems that came out of that, so things should be basically correct 
now.

Original comment by kevin...@gmail.com on 4 Mar 2009 at 11:46