Findbugs error - RV_RETURN_VALUE_IGNORED when using ImmutableSet.Builder

394 Views Asked by At

Findbugs throws warning for the following piece of code. Seems like a simple of Builder class to add items and construct at the end. Whats the issue here ?

public static Set<Entity> convert(@NonNull final String id,
        @NonNull final Collection<SomeEntity> list) {

        Builder<Entity> builder = new ImmutableSet.Builder<>();
        final Entity entityOfType1 = createEntity(..);        
  //    Bug type RV_RETURN_VALUE_IGNORED 
        builder.add(entityOfType1);


        final Set<Entity> entitiesOfType2 = createEntity(..);
 //     Bug type RV_RETURN_VALUE_IGNORED 
        builder.addAll(entitiesOfType2);

        final Set<Entity> entitiesOfType3 = createEntity(..);
 //     Bug type RV_RETURN_VALUE_IGNORED 
        builder.addAll(entitiesOfType3);

        return builder.build();
    }

1

There are 1 best solutions below

0
On

Your code is OK, it's FindBugs issue.

If you switch to SpotBugs, which is "is the spiritual successor of FindBugs, carrying on from the point where it left off with support of its community", you'll have it fixed. Guava since 23.6 "migrated from jsr305 @CheckReturnValue, @GuardedBy and @OverridingMethodsMustInvokeSuper to the Error Prone equivalents", for which support in SpotBugs was added in 2018 in PR#538.