I've come across a problem when using AutoValue with geneated Builder and fields with Guava ImmutableMap.
Say we have this Container value class:
public abstract class Container {
public abstract ImmutableMap<String, String> metadata();
public abstract Builder toBuilder();
public static Builder builder() {
return new AutoValue_Container.Builder();
}
@AutoValue.Builder
public abstract static class Builder {
public abstract ImmutableMap.Builder<String, String> metadataBuilder();
public final Builder addMetadata(String key, String value) {
metadataBuilder().put(key, value);
return this;
}
}
}
When I want to do the following, the ImmutableMap builder throws
java.lang.IllegalArgumentException: Multiple entries with same key
aContainer.toBuilder().addMetadata("existingKey", "someNewValue");
Does anyone familiar with AutoValue know how to coax the implementation to do as told?