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] Lombok generates only one @Getter and @Setter for a field name #2130
Comments
I guess, the reason is the javabeanscrap insanity: With their rules, there's no one-to-one correspondence between field and getter names. So the names could collide. I don't recall the rules anymore, so I can't give you an example. Moreover, there are people using their own rules and defining getters manually, when they dislike the name lombok would generate. So when lombok sees Sure, it could be smarter when it sees that the first getter was actually generated by lombok itself. But this is more complicated, would break backwards compatibility, would need a precise specification, updating documentation, maintenance.... and seriously, how often do you need it? |
@Maaartinus , it happens from time to time, and until today I thought that Lombok supports it. If this change as complex as you describe, then we can leave current behavior as it is, but add more flexibility to the @Getter(getterName = "getNaMe")
String naMe; which will generate a getter method with name Or by providing an additional attribute "caseSensitive" on the class level: @Setter(caseSensitive=true)
public class Cases {
String name;
String naMe;
String nAME;
} which will generate setters for each field considering its naming case: Cases cases = new Cases();
cases.setName("");
cases.setNaMe("");
cases.setNAME(""); |
I wouldn't say, it's complex. If it was code generation using reflection or plain annotation processing, I'd vote for finding the best solution. But lombok has to deal with undocumented compiler internals and that adds more than an order of magnitude overhead. And it has many users with many wishes, a few contributors and only two maintainers (I'm not a team member).
... which saves you a single line (or two or zero, depending on your formatting style) in a very rare case of name clash due to different casing. At least, I hope, it's a rare case in your code. 🤣
I guess, |
Sorry, although I understand that there is a use-case for it, due to the reasons @Maaartinus mentioned, we're not going to add support for multiple fields that have the same case-insensitive name. It's not common enough to warrant extra time on it. |
Duplicate of #2693 |
I want to emphasize that this issue is not related to "the first letter should be lowercase" like #757 and a pile of others.
Describe the bug
Lombok generates only one Getter/Setter for fields which names are differed by the case.
To Reproduce
When I have a class with fields that have the following names:
Lombok generates only 1 pair of getter and setter
Expected behavior
I expect lombok to generate 3 pairs of getter and setters
Version info:
Additional context
From the documentation - https://projectlombok.org/features/GetterSetter
I don't quite understand this irrational behavior - if these are different fields for Java - Lombok should treat them as separate fields and generate a pair of Getter/Setter for each.
The text was updated successfully, but these errors were encountered: