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] Non-copyable type parameter annotations are copied #3460

Open
joao-martins-tdx opened this issue Jul 13, 2023 · 6 comments
Open

[BUG] Non-copyable type parameter annotations are copied #3460

joao-martins-tdx opened this issue Jul 13, 2023 · 6 comments

Comments

@joao-martins-tdx
Copy link

joao-martins-tdx commented Jul 13, 2023

Describe the bug

When a type parameter of a field is annotated with a non-copyable annotation, the annotation is copied to the getter, setter, constructor and "$default$" method.

To Reproduce

Compile the following source file with javac -cp lombok-1.18.28.jar:validation-api-2.0.1.Final.jar Example.java:

import lombok.Builder;
import lombok.Getter;
import lombok.Setter;

import javax.validation.constraints.NotNull;
import java.util.ArrayList;
import java.util.List;

@Builder
@Getter
@Setter
public class Example {
    @Builder.Default
    private List<@NotNull String> strings = new ArrayList<>();
}

Expected behavior

The javax.validation.constraints.NotNull annotation is not copied.

Version info (please complete the following information):

  • Lombok version: 1.18.28
  • Platform: javac 17.0.7

Additional context

Delomboked source:

import javax.validation.constraints.NotNull;
import java.util.ArrayList;
import java.util.List;

public class Example {
    private List<@NotNull String> strings;

    @java.lang.SuppressWarnings("all")
    private static List<@NotNull String> $default$strings() {
        return new ArrayList<>();
    }

    @java.lang.SuppressWarnings("all")
    Example(final List<@NotNull String> strings) {
        this.strings = strings;
    }


    @java.lang.SuppressWarnings("all")
    public static class ExampleBuilder {
        @java.lang.SuppressWarnings("all")
        private boolean strings$set;
        @java.lang.SuppressWarnings("all")
        private List<@NotNull String> strings$value;

        @java.lang.SuppressWarnings("all")
        ExampleBuilder() {
        }

        /**
         * @return {@code this}.
         */
        @java.lang.SuppressWarnings("all")
        public Example.ExampleBuilder strings(final List<@NotNull String> strings) {
            this.strings$value = strings;
            strings$set = true;
            return this;
        }

        @java.lang.SuppressWarnings("all")
        public Example build() {
            List<@NotNull String> strings$value = this.strings$value;
            if (!this.strings$set) strings$value = Example.$default$strings();
            return new Example(strings$value);
        }

        @java.lang.Override
        @java.lang.SuppressWarnings("all")
        public java.lang.String toString() {
            return "Example.ExampleBuilder(strings$value=" + this.strings$value + ")";
        }
    }

    @java.lang.SuppressWarnings("all")
    public static Example.ExampleBuilder builder() {
        return new Example.ExampleBuilder();
    }

    @java.lang.SuppressWarnings("all")
    public List<@NotNull String> getStrings() {
        return this.strings;
    }

    @java.lang.SuppressWarnings("all")
    public void setStrings(final List<@NotNull String> strings) {
        this.strings = strings;
    }
}
@dstango
Copy link

dstango commented Jul 14, 2023

Please check if this might be a duplicate or related to #3180, which should already be resolved in the most current version of lombok.

@joao-martins-tdx
Copy link
Author

Thanks for the prompt reply @dstango.

It does seem to be related to #3180, however, I've tested the steps to reproduce in the most current version of lombok and the annotation is still copied.

@dstango
Copy link

dstango commented Jul 14, 2023

According to this:
1473389#:~:text=//%09%09%09%22-,javax.validation.constraints.NotNull,-%22%2C%20//%20%2D%20this%20should%20definitely

it should have been fixed in 1.18.28. If not: Did you try the edge-version?

And maybe this has some interesting info, too: #3150

@joao-martins-tdx
Copy link
Author

Just tested it again in 1.18.28 and confirmed that it's not fixed.

I didn't test it in the edge-version because https://projectlombok.org/download-edge states that "no edge build has been released since the last stable release of lombok". Is there another download link for the edge-version, or there is indeed no edge-version at the moment?

@dstango
Copy link

dstango commented Jul 14, 2023

Interesting, maybe it's because the type annotation is put on the generic type parameter.

It might be Lombok doesn't do any further checks on type annotations in generic type parameters.
If you modify your example leaving out the List - what is happening then? (can't try myself right now, as I'm on my phone).

@Rawi01, @rzwitserloot: what do you say?

@joao-martins-tdx
Copy link
Author

joao-martins-tdx commented Jul 15, 2023

If I leave out the list or place @NotNull on the field instead of placing it on the type parameter, the annotation is not copied (as expected).

maybe it's because the type annotation is put on the generic type parameter.

It seems so.

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