Skip to content

ImmutableMemberCollection not detecting JDK Set.of(...) #2283

@vivekkothari

Description

@vivekkothari

Description of the problem / feature request:

I have following code,

private static final Set<String> SUPPORTED_METHODS = Set.of(
      HttpMethods.GET, HttpMethods.POST, HttpMethods.PUT, HttpMethods.DELETE,
      HttpMethods.HEAD, HttpMethods.OPTIONS, HttpMethods.TRACE
);

I have enabled ImmutableMemberCollection in my gradle file.
On error-prone version 2.5.1, this works fine.
But when I upgrade to 2.6.0, I get following error.

 error: [ImmutableMemberCollection] If you don't intend to mutate a member collection prefer using Immutable types.
public final class OkHttpTransport extends HttpTransport {
             ^
    (see https://errorprone.info/bugpattern/ImmutableMemberCollection)
  Did you mean 'private static final ImmutableSet<String> SUPPORTED_METHODS = ImmutableSet.copyOf(Set.of('?
1 error

Feature requests: what underlying problem are you trying to solve with this feature?

Set.of already returns an immutable collection, so error-prone should detect this and not throw an error.

Bugs: what's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.

public final class MyClass {
private static final Set<String> MY_STRINGS = Set.of("a", "b", "c");
}

What version of Error Prone are you using?

2.6.0

Have you found anything relevant by searching the web?

Nothing in particular.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions