migrator / guava-libraries-2

Guava: Google Core Libraries for Java 1.6+
0 stars 0 forks source link

Nullpointerexception if FluentIterable.transformAndConcat()'s function parameter is nullable #42

Open migrator opened 9 years ago

migrator commented 9 years ago

i'm conflicted over the fact that Function.apply is annotated as nullable, yet this causes an exception

FluentIterable objects = FluentIterable.from(Arrays.asList("a", "b")) .transformAndConcat(new Function<String, Iterable<?>>() { @Nullable @Override public Iterable<?> apply(@Nullable String input) { return null; } }); try { Iterables.isEmpty(objects); }catch (NullPointerException e){ System.err.println("see?"); e.printStackTrace(); } }

relevance: 2

migrator commented 9 years ago

summary: Not Defined

The intention of the @Nullable annotations on Function.apply is that implementations of Function may or may not choose to accept or return null, and to make that freedom explicit. Interpretations of @Nullable vary, however.

The behavior itself looks WAI for FluentIterable.transformAndConcat, though I'm not sure if we should change the documentation to make this more explicit.

status Not Defined creator: lowas...@google.com created at: Sep 4, 2014