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] When the first letter of an attribute is lowercase and the second letter is uppercase, the getter and setter methods generated by Lombok are incorrect #2149

Closed
lw5946 opened this issue Jun 5, 2019 · 7 comments

Comments

@lw5946
Copy link

lw5946 commented Jun 5, 2019

In the JavaBean specification, getter and setter methods of pDept attributes are getpDetp and setpDept. But the getter and setter methods generated by Lombok are getPDetp and setPDept.

I used version 1.16.14, but I didn't see a new version fixing the bug in changelog.

@maxxyme
Copy link

maxxyme commented Jun 5, 2019

Hi @lw5946

I'd really like you provide some evidence of your saying. Because I just (discovered and) read the JavaBeans Specification 1.01 available on Oracle's website: https://www.oracle.com/technetwork/articles/javaee/spec-136004.html

Particularly this chapter 8.8 but there's nothing related to this exception (except what I have put in bold but it's about all-uppercase properties).

8.8 Capitalization of inferred names.

When we use design patterns to infer a property or event name, we need to decide what rules
to follow for capitalizing the inferred name. If we extract the name from the middle of a normal
mixedCase style Java name then the name will, by default, begin with a capital letter.

Java programmers are accustomed to having normal identifiers start with lower case letters.
Vigorous reviewer input has convinced us that we should follow this same conventional rule
for property and event names.

Thus when we extract a property or event name from the middle of an existing Java name, we
normally convert the first character to lower case. However to support the occasional use of all
upper-case names, we check if the first two characters of the name are both upper case and if
so leave it alone.
So for example,
“FooBah” becomes “fooBah”
“Z” becomes “z”
“URL” becomes “URL”
We provide a method Introspector.decapitalize which implements this conversion rule.

@mdpwpdw
Copy link

mdpwpdw commented Jun 6, 2019

@maxxyme
for example:
lombok entity, lombok Generate getter, setter
`@Getter
@Setter
public class LUser
{
private String tEst;

private String tDate;

private String ttttttDate;

}`

eclipse Generate getter, setter
`public class EUser
{
private String tEst;

private String tDate;

private String ttttttDate;


public String gettEst()
{
	return tEst;
}
public void settEst(String tEst)
{
	this.tEst = tEst;
}
public String gettDate()
{
	return tDate;
}
public void settDate(String tDate)
{
	this.tDate = tDate;
}
public String getTtttttDate()
{
	return ttttttDate;
}
public void setTtttttDate(String ttttttDate)
{
	this.ttttttDate = ttttttDate;
}

}
`

test
@Test public void testLombok() { LUser lu = new LUser(); lu.setTDate("xxx"); // lombok The first t character is capitalized lu.setTEst("xxxx"); // lombok The first t character is capitalized lu.setTtttttDate("werevfegv"); // lombok The first t character is capitalized } @Test public void testEclipse() { EUser eu = new EUser(); eu.settDate("xxx"); // eclipse First t character lowercase eu.settDate("xxxx"); // eclipse First t character lowercase eu.setTtttttDate("werevfegv"); // eclipse First t character lowercase }

The getter and setter generated by the two have character case differences, and if you use jackson serialization into json, there is a problem of json's name case.

FasterXML/jackson-databind#2327

@Maaartinus
Copy link
Contributor

IMHO duplicate of #927.

@lw5946 This is an old news.... the Javabeans crap is inconsistent in itself and what Lombok implements is not optimal. IIRC the team knows it and would accept a PR, but not change it themselves - as it's a lot of work with backwards incompatible changes for switching from one interpretation to a more frequently used one. Too little gain. Search for Javabeans in this repo if you want to know more.

@lw5946
Copy link
Author

lw5946 commented Jun 10, 2019

Oh, well, thank you.

@lsong98sh
Copy link

So, why not add an annotation attribute such as @getter(convention=NamingConvention.Eclipse)

@rzwitserloot
Copy link
Collaborator

lombok's behaviour is intentional. We will not change it and we will not be putting in a convention toggle. Not worth the effort or the maintenance burden.

@rzwitserloot
Copy link
Collaborator

Duplicate of #2693

@rzwitserloot rzwitserloot marked this as a duplicate of #2693 Jan 2, 2021
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

6 participants