You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Compile fails when using a combination of @SuperBuilder(toBuilder = true) with @Singular on a Map field with error message 'no instance(s) of type variable(s) T exist so that java.util.List conforms to java.util.Map'
To Reproduce
Java source code:
import java.util.Map;
import lombok.Getter;
import lombok.Singular;
import lombok.experimental.SuperBuilder;
@SuperBuilder(toBuilder = true)
@Getter
public class SuperToBuilder {
@Singular("addToMap")
private final Map<String, String> itemMap;
}
Compile output:
$ javac -cp lombok-1.18.6.jar src/SuperToBuilder.java
src\SuperToBuilder.java:7: error: incompatible types: bad type in conditional expression
@SuperBuilder(toBuilder = true)
^
no instance(s) of type variable(s) T exist so that List<T> conforms to Map<? extends String,? extends String>
where T is a type-variable:
T extends Object declared in method <T>emptyList()
Note: Some messages have been simplified; recompile with -Xdiags:verbose to get full output
1 error
--
Delombok shows the bug may be a simple SuperToBuilderDelombok.java.gz
mismatch of logic for handling empty collections. A zip of the full delombok code has been attached to this issue.
private static void $fillValuesFromInstanceIntoBuilder(final SuperToBuilderDelombok instance, final SuperToBuilderBuilder<?, ?> b) {
b.itemMap(instance.itemMap == null ? java.util.Collections.emptyList() : instance.itemMap);
}
Appearantly, java.util.Collections.emptyMap() should be selected in the case of a null Map.
This issue only occurs with the Combination of @SuperBuilder(toBuilder = true) and @Singular on a Map field. The following changes to the example all compiled sucessfully:
I missed that this made it into 1.18.8 because I had worked around this issue. I've upgraded and verified that this problem issue fixed in my project. Thanks!
Describe the bug
Compile fails when using a combination of @SuperBuilder(toBuilder = true) with @Singular on a Map field with error message 'no instance(s) of type variable(s) T exist so that java.util.List conforms to java.util.Map'
To Reproduce
Java source code:
Compile output:
Delombok shows the bug may be a simple
SuperToBuilderDelombok.java.gz
mismatch of logic for handling empty collections. A zip of the full delombok code has been attached to this issue.
Appearantly, java.util.Collections.emptyMap() should be selected in the case of a null Map.
This issue only occurs with the Combination of @SuperBuilder(toBuilder = true) and @Singular on a Map field. The following changes to the example all compiled sucessfully:
SuperToBuilderDelombok.java.gz
Expected behavior
The class should compile successfully and generate a builder with singular set methods for the Map.
Version info (please complete the following information):
Lombok Version: 1.18.6
Java Platform: OpenJDK 11.0.2 2019-01-15
OpenJDK Runtime Environment 18.9 (build 11.0.2+9) OpenJDK 64-Bit Server VM 18.9 (build 11.0.2+9, mixed mode)
Additional context
Attempted to use the latest edge-SNAPSHOT from https://projectlombok.org/edge-releases as of April 20, 2018, but the results were the same.
The text was updated successfully, but these errors were encountered: