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] Builder doesn't generate build() method when build field present. #2011

Closed
janinko opened this issue Jan 10, 2019 · 6 comments
Closed

Comments

@janinko
Copy link

janinko commented Jan 10, 2019

Describe the bug
build() method on the builder is not generated, when there is build field in the class, only build(SomeObejct build) is generated.

To Reproduce
Compile this. The FooBarBuilder doesn't have build() method.

@Data
@Builder
public class FooBar {
    private final String build;
}

Expected behavior
The builder should have both build() and build(String) methods.

Version info (please complete the following information):

  • Lombok version 1.18.2
  • Platform javac 1.8.0_191
@janinko janinko changed the title [BUG] Builder doesn't generate Build() method when build field present. [BUG] Builder doesn't generate build() method when build field present. Jan 10, 2019
@Maaartinus
Copy link
Contributor

The builder should have both build() and build(String) methods.

IMHO it really should not. Yes, this is a bug, but having two overloads doing something completely different is looking for troubles.

I guess, there'll be more such cases, fields called builder, toBuilder, equals, ...

I'm not sure, if they all are really worth fixing. Just my 2c.

@randakar
Copy link

randakar commented Jan 11, 2019 via email

@kalexmills
Copy link

Right now Java just complains that a method which my IDE plugin says is there actually is not there -- which will be frustrating, so good catch. I think that the plugins should check for this case if it will not be supported.

If you really need to have a variable named build, you can use buildMethodName argument to @builder annotation to make all these problems go away.

@randakar, would a more all-encompassing fix be to check all method names in output classes against fields for naming collisions during compilation?

@randakar
Copy link

randakar commented Jan 12, 2019 via email

@rzwitserloot
Copy link
Collaborator

While I agree with @Maaartinus that having both Foo build() and FooBuilder build(arg) in the same builder doing completely different things makes for deplorably bad API, there is a fine line between the notion of 'lombok should not accidentally generate crappy code' and 'lombok should attempt to eliminate lunacy'.

We hold to the notion that a sufficiently idiotic coder in your team results in bad code. No amount of rules, hooks, linting tools, style guides, and opinionated checker frameworks/software will ever outwit the inventive lunacy of a dedicated moron on a team. With the obvious exception that for some reason even otherwise capable and experienced coders turn into blithering baboons when they are faced with operator overloading so definitely never ever add that to anything. 😛

Having build as a field is sufficiently exotic that I decided to just roll with 'make both methods, let crazy API be damned'.

@rzwitserloot
Copy link
Collaborator

bugfix available in edge release: https://projectlombok.org/download-edge

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

5 participants