Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
600 views
in Technique[技术] by (71.8m points)

guava - Findbugs error - RV_RETURN_VALUE_IGNORED when using ImmutableSet.Builder

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

question from:https://stackoverflow.com/questions/65942116/findbugs-error-rv-return-value-ignored-when-using-immutableset-builder

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

56.9k users

...