Skip to content

Rawtypes warning using @Builder returning a parameterized type. #1420

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

Closed
victorwss opened this issue Jun 20, 2017 · 1 comment
Closed

Rawtypes warning using @Builder returning a parameterized type. #1420

victorwss opened this issue Jun 20, 2017 · 1 comment

Comments

@victorwss
Copy link
Contributor

victorwss commented Jun 20, 2017

Compiling this code with lombok:

package com.example;

import java.util.List;
import lombok.Builder;

public class BugTest {

    @Builder
    public List<String> foo(int a, long b) {
        return null;
    }
}

Produces the following warning:

C:\path-to-project\src\main\java\com\example\BugTest.java:8: warning: [rawtypes] found raw type: List
    @Builder
    ^
  missing type arguments for generic class List<E>

The delomboked source confirms it:

// Generated by delombok at Tue Jun 20 11:29:00 BRT 2017
package com.example;

import java.util.List;

public class BugTest {
    public List<String> foo(int a, long b) {
        return null;
    }


    @java.lang.SuppressWarnings("all")
    @javax.annotation.Generated("lombok")
    public class ListBuilder {
        @java.lang.SuppressWarnings("all")
        @javax.annotation.Generated("lombok")
        private int a;
        @java.lang.SuppressWarnings("all")
        @javax.annotation.Generated("lombok")
        private long b;

        @java.lang.SuppressWarnings("all")
        @javax.annotation.Generated("lombok")
        ListBuilder() {
        }

        @java.lang.SuppressWarnings("all")
        @javax.annotation.Generated("lombok")
        public ListBuilder a(final int a) {
            this.a = a;
            return this;
        }

        @java.lang.SuppressWarnings("all")
        @javax.annotation.Generated("lombok")
        public ListBuilder b(final long b) {
            this.b = b;
            return this;
        }

        @java.lang.SuppressWarnings("all")
        @javax.annotation.Generated("lombok")
        public List build() {
            return BugTest.this.foo(a, b);
        }

        @java.lang.Override
        @java.lang.SuppressWarnings("all")
        @javax.annotation.Generated("lombok")
        public java.lang.String toString() {
            return "BugTest.ListBuilder(a=" + this.a + ", b=" + this.b + ")";
        }
    }

    @java.lang.SuppressWarnings("all")
    @javax.annotation.Generated("lombok")
    public ListBuilder builder() {
        return new ListBuilder();
    }
}

Note that the build() method returns a raw List, instead of List<String>.

I am using lombok 1.16.16. It would be appreciable if the return type preserves the generics information.

@victorwss victorwss changed the title Unchecked warning using @Builder returning a parameterized type. Rawtypes warning using @Builder returning a parameterized type. Jun 20, 2017
@udalrich
Copy link

Still present in 1.16.18. A fix would be appreciated.

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