'Immutable not generating correct code when using Map

I have this code using https://immutables.github.io/:

@Value.Immutable
@Value.Style(visibility = Value.Style.ImplementationVisibility.PRIVATE)
public interface TypedEntityQuery<T> {
  String environment();

  T entity();

  Map<String, PropertyCondition> conditions();

  Integer offset();

  Integer max();

  String sort();
}
public interface PropertyCondition {
}

And used like this:

TypedEntityQuery<Manager> query = new TypedEntityQueryBuilder<Manager>()
   .entity(manager)
   .conditions(manager.getConditions()) 
   .build();

The manager class above is defined as such:

@Builder
class Manager {
   private @Getter @Setter Map<String, PropertyCondition> conditions;
}

However it throws this error:

[ERROR] .../target/generated-sources/annotations/com/mycompany/backend/model/builder/TypedEntityBuilder.java:[124,20] method put in class com.google.common.collect.ImmutableMap.Builder<K,V> cannot be applied to given types;
[ERROR]   required: java.lang.String,com.mycompany.core.PropertyCondition
[ERROR]   found: java.util.Map.Entry<java.lang.String,capture#2 of ? extends com.mycompany.core.PropertyCondition>
[ERROR]   reason: actual and formal argument lists differ in length
[ERROR] -> [Help 1]

The generated code is:

/**
 * Put one entry to the {@link TypedEntity#conditions() conditions} map. Nulls are not permitted
 * @param entry The key and value entry
 * @return {@code this} builder for use in a chained invocation
 */
@CanIgnoreReturnValue 
public final TypedEntityBuilder<T> putConditions(Map.Entry<String, ? extends PropertyCondition> entry) {
  this.conditions.put(entry); // error here
  return this;
}


Solution 1:[1]

I would have added this as a comment but I don't have "50 reputation".

For anyone that runs into this issue later -- you can use the jdkOnly implementation even if you have guava on the class path. For example

@Value.Immutable
@Value.Style(
  visibility = Value.Style.ImplementationVisibility.PRIVATE,
  jdkOnly = true // Add this to avoid using the guava implementation
)
public interface TypedEntityQuery<T> {
  String environment();

  T entity();

  Map<String, PropertyCondition> conditions();

  Integer offset();

  Integer max();

  String sort();
}

Ref: https://immutables.github.io/style.html

I don't think this resolves the issue. My next best bet is that you need to check the version of guava you are using. Maybe you need to pull in a version that has what you want?

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 anthonker