-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Change lombok's property capitalization code. Field xName
-> getxName()
.
#2693
Comments
is there a way to fix the (missing) link for ... to the other behaviour (SOURCE: this issue.? thanks. |
This comment has been minimized.
This comment has been minimized.
Fixed. |
IDK if this relates to current issue but I just keep it here to not create more requests. Code: @lombok.Value
public class SrcDto {
String filename;
String fileName;
} results in only one getter:
So here we can see only one getter and it's misuse in other methods. Lombok 1.18.20 |
@rzwitserloot any news? |
@rzwitserloot what about adding optional configuration, something like JavaBeansSpecCapitalization=true (default to false)? |
@SimSonic That is another one of those "Whatever we do, 90% don't care, though have a mild preference for no changes to the status quo whatever it may be, 5% want A, and 5% want B". We chose A, you want B, even if we could go back in time and argue that B is slightly better, now that we are here, no change wins due to the 90%. We aren't fixing that. Why do you have 2 fields with the exact same name other than capitalization? |
@YonatanSherwin I think using |
True story, gateway between mobiles and fintech services, which renames the field accidentally... I've tried to read both name variants and select non-null one. Ok, I'm agree, it's a stupidly rare case. But it's hard for me look at current behavior as "not a bug, feature". I'm understanding your position and just want you to not discard possibility of future bugfix. Thanks for you work. |
Thanks @rzwitserloot , waiting for update. I'll be happy to implement this if that's ok :-) |
@rspilker wasn't feeling so good. I don't see any reason for not doing this, but it's been a contentious issue so I'm sure he has thoughts on the topic. We'll try to discuss it this weekend. |
I'm all for accepting a pull request that caters both capitalization strategies based on a config key. I prefer the default to be the current strategy in order to not introduce a breaking change. |
PR link: |
The current edge includes this update (the changelog listed on the edge download page is wrong, it's in there): |
…ation lombok.config
…tion = beanspec’ feature.
Do you plan to mention the default value |
This is a catch-all issue that tries to capture the relevant information from a ton of separate issue requests (to those reviewing bug reports, please mark as duplicate of just this issue).
The problem:
Lombok's name conversion tool, used by
@Getter
and@Setter
, as well as@With
, and therefore also@Data
and@Value
, turns a field that starts with a single lowercase letter followed by a capital into a capital followed by a capital:@Getter private String uName;
generatedpublic String getUName() {return this.uName; }
.However, various tools out there expect
getuName
instead, in this unique case where the second letter of the field/property name is a capital where the first is lowercase.Unfortunately, there is no convention we can follow, because there are also tools out there that expected
getUName
. No matter what lombok does, some tooling / expectations will be left out in the cold. More generally then, because of these conflicts, names like uName are problematic in any case, and you should try never to use such names.There is nothing lombok can do to solve all problems with single-lower-case-letter property names: If you decide to use fields named like this, sooner or later you're going to run into trouble. Quoting user @Maaartinus:
However, the majority of the community has standardized on
xName
->getxName()
, and thus we are now willing to accept a PR, even though this will cause no small amount of pain, as it'll be backwards incompatible, and we reserve the right to wimp out and delay integrating the Pull Request until a major update with more breaking changes.Tools and specs that prefer
xName
->getxName
:(warning from @rzwitserloot: Do not write
setURL
. All major style guides and modern JDK standards say you should writesetUrl
. This nuance wasn't around in 1997 / it was, but this document tries to cater to existing code that did not follow it; a bunch of JDK methods, particularly in swing, fail to adhere to this, for example).(It's subtle, but this
URL
➝URL
rule means thatgetXName()
is turned into property nameXName
because it starts with 2 capitals. This is presumably the source of whyxName
->getxName
, becausegetXName
doesn't convert back toxName
according to beanspec §8.8.java.beans.Introspector
'sdecapitalize
method.Tools and specs that prefer
xName
->getXName
:getx
ingetxName
to not be a word, following the convention explained in the previous point). Yes, intellij's built in code generator can generate code that is marked as problematic by its built-in linter.java.beans.PropertyDescriptor
, which uses internal classjava.beans.NameGenerator
'scapitalize
method.getuName()
is a lot harder to read as 'get the uName property' versusgetUName
.Tools that used to
xName
->getXName
but nowxName
->getxName
:See also this Stack overflow answer that goes into a lot of depth on this sad state of affairs, as well as this conversation on the lombok list.
Workaround:
Just write the getter/setter out, with the casing you want. Lombok will see it and recognize that you clearly wanted this alternate casing:
This issue is a catch-all for at least 25 earlier issues; all relevant information from all issues marked as duplicate is included in this one post.
The text was updated successfully, but these errors were encountered: