Skip to content

Multimaps with non-parameterized key does not generate @SafeVarargs annotation, causes "Possible heap pollution from parameterized vararg type" warning #1479

Description

@maxqch

Version: 2.9.3

It seems like multimaps with a generic value does not generate @SafeVarargs in the put... methods, causing a compiler warning.

Example code:

import com.google.common.collect.Multimap;
import org.immutables.value.Value;

public interface ImmutableMultimapSafeVarargs {
    // Correct annotation
    //    @SafeVarargs @SuppressWarnings("varargs")
    //    public final Builder putVals(ImmutableMultimapTest.Val<String> key, String... values) {
    @Value.Immutable
    interface ParamKey {
        Multimap<Val<String>, String> vals();
    }

    // Missing annotation
    //    @CanIgnoreReturnValue
    //    public final Builder putVals(String key, ImmutableMultimapSafeVarargs.Val<String>... values) {
    // [WARNING] ...ImmutableParamVal.java:[156,41] Possible heap pollution from parameterized vararg type
    //           ...ImmutableMultimapSafeVarargs.Val<java.lang.String>
    // [INFO] 1 warning
    @Value.Immutable
    interface ParamVal {
        Multimap<String, Val<String>> vals();
    }

    // Correct annotation
    //    @SafeVarargs @SuppressWarnings("varargs")
    //    public final Builder putVals(ImmutableMultimapTest.Val<String> key, ImmutableMultimapTest.Val<String>... values) {
    @Value.Immutable
    interface ParamBoth {
        Multimap<Val<String>, Val<String>> vals();
    }

    class Val<T> {
        private final T val;

        public Val(final T val) {
            this.val = val;
        }

        T get() {
            return val;
        };
    }
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions