Lombok-intellij-plugin: Multiple Builders causing issues

Created on 6 Feb 2018  路  4Comments  路  Source: mplushnikov/lombok-intellij-plugin

Short description

When a class has multiple constructors with @Builder annotations in a class, it only picks up the last version. Whilst everything compiles fine, it ends up being very annoying having a lot of red everywhere. This seems obviously looks like it's going through the code and only allowing one to be used, so every time it finds one, it overrides it, hence the last one is available but the others aren't.

Expected behavior

All @Builder annotated constructors to be available without warnings.

Version information

  • IDEA Version: 2017.3.4
  • JDK Version: 1.8.0u152b11
  • OS Type & Version: Lubuntu Next 17.10 (same behaviour seen on Ubuntu and Mac 10.13)
  • Lombok Plugin Version: 0.15.17.2
  • Lombok Dependency Version: 1.16.18 (but have tried with other versions of 1.16.x and all have the same problem)

Steps to reproduce

  1. Create a class with multiple @Builder annotations on constructors that take different parameters
  2. Try and use the builder/methods and everything will compile, the compiled classes will have everything in them, but the uses will be unknown.

Sample project

Sample project

  • [ ] Sample project provided
  • [X] I am able to reproduce this error on the sample project by following the steps described above

Most helpful comment

I've managed to create a fix in my fork for this, but it then causes a lot of other tests to fail.

The issue I'm trying to fix seems to be around the fact that multiple builder classes with the same name are in fact overwriting the previous one, as obviously only 1 class with that signature can exist. I tried to make it so that whenever the class is being created, it will check and return the previously created version. This then creates an issue where we need to not recreate the same fields/methods. I then updated the LombokLightClassBuilder to not overwrite fields/methods, but that is what then causes the other test to fail. I can get the fields to overwrite perfectly fine, but as the methods are not accessible to be removed, the tests then fail because of that.

I don't really understand how this plugin works all that well, so I've kind of been fumbling my way through, so maybe you can get this to work where I can't.

All 4 comments

I've managed to create a fix in my fork for this, but it then causes a lot of other tests to fail.

The issue I'm trying to fix seems to be around the fact that multiple builder classes with the same name are in fact overwriting the previous one, as obviously only 1 class with that signature can exist. I tried to make it so that whenever the class is being created, it will check and return the previously created version. This then creates an issue where we need to not recreate the same fields/methods. I then updated the LombokLightClassBuilder to not overwrite fields/methods, but that is what then causes the other test to fail. I can get the fields to overwrite perfectly fine, but as the methods are not accessible to be removed, the tests then fail because of that.

I don't really understand how this plugin works all that well, so I've kind of been fumbling my way through, so maybe you can get this to work where I can't.

Hello @gigaSproule,
your example project is not online any more, but as I can understood, your are trying to create multiple Builder for the same class using different constructors/methods?
Did you specified unique names for builderClass and builderMethod parameters of @Builder annotation?
If not, this will not work with lombok because of:
https://github.com/rzwitserloot/lombok/issues/730
or
https://github.com/rzwitserloot/lombok/issues/912
This should be fixed by lombok first, before plugin can be made supported this.

That's how it was working, and Lombok worked fine. However, I've since left the company where it was being used, so feel free to close this.

Thank you @gigaSproule

Was this page helpful?
0 / 5 - 0 ratings