mkodekar / guava-libraries

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

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

Closed GoogleCodeExporter closed 9 years ago

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

 FluentIterable<Object> 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();
        }
    }

Original issue reported on code.google.com by rob.maxw...@gmail.com on 4 Sep 2014 at 6:42

GoogleCodeExporter commented 9 years ago
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.

Original comment by lowas...@google.com on 4 Sep 2014 at 6:47

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

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

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

GoogleCodeExporter commented 9 years ago

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

GoogleCodeExporter commented 9 years ago

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