Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Compile fails f @SuperBuilder(toBuilder = true) with @Singular on a Map #2104

Closed
nadernader99 opened this issue Apr 20, 2019 · 2 comments

Comments

@nadernader99
Copy link

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:

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:

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.

@janrieke
Copy link
Contributor

Thanks for the detailed report. The issue is probably caused by the hard-coded List in HandleSuperBuilder:728.

@nadernader99
Copy link
Author

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants