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

Variables with similar names - "Cannot find Symbol" for getter method #2590

Closed
mrieman opened this issue Oct 2, 2020 · 5 comments
Closed

Comments

@mrieman
Copy link

mrieman commented Oct 2, 2020

I believe I have encountered a bug where Lombok build fails when 2 variables with very similar names. In this example, the only difference is a single character capitalization.

`import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;

@EqualsAndHashCode @tostring @Setter @builder
@NoArgsConstructor @AllArgsConstructor
public class History implements java.io.Serializable {

//UpperCase "I" in this variable name`
@getter
private Integer histDeIdPtr;

//LowerCase "i" in this variable name`
@getter
private Integer histDeidPtr;

}`

Building via Maven, this causes
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project lombok-pojos: Compilation failure: Compilation failure: [ERROR] /C:/git/lombok-pojos/src/main/java/org/test/lombok/pojos/History.java:[27,1] cannot find symbol [ERROR] symbol: method getHistDeIdPtr()

NOTES on my setup:

  • I cannot change the method names since the getter/setter methods are referenced by "closed" jars that are out of my control.
  • Eclipse compiles this fine with no errors
  • All other POJO classes build fine
  • These POJO are generated.
  • The Lombok annotations are added during the POJO generation via a template.

One workaround is to write my own getter/setter. But doing so would complicate the POJO generation templates, or require after-processing; both of which I would like to avoid.

If this is not a bug, is another workaround available?

@Rawi01
Copy link
Collaborator

Rawi01 commented Oct 2, 2020

I can confirm that lombok only generates one getter if there are two fields sharing the same name with different upper and lower case characters. It's quite funny that @EqualsAndHashCode and @ToString still try to use these methods. Seems to be a bug.

@Lekanich
Copy link
Contributor

Lekanich commented Oct 3, 2020

I think the root cause is here. It's because lombok checks getter names without case sensitivity.
https://github.com/rzwitserloot/lombok/blob/8943b49dfed95228e324422435a77597a95943c0/src/core/lombok/javac/handlers/HandleGetter.java#L203
I'm curious why...

And also it shouldn't work for the eclipse compiler because it also has the same check...

It was introduced here:
89d60fc
@rzwitserloot Is it some kind of feature?

@Rawi01
Copy link
Collaborator

Rawi01 commented Oct 10, 2020

Original issue: #148, https://groups.google.com/g/javaposse/c/4AzRsqJdzKM

It seems like the reason for this behaviour is to handle cases where someone wants to add a method like getURL by hand and not generate a lomobk method. As that could also solved using @Getter(AccessLevel.NONE) I think that lombok should switch back to case sensitv method name comparision.

Disclaimer: I'm not a project owner.

@aloktech
Copy link

Hi,
@DaTa
@builder
public class History implements Serializable {
private Integer histDeldPtr;
private Integer histDeidPtr;
}
The above piece of code generates a proper class file, without any issue in JDK 8(IntelliJ).

@rzwitserloot
Copy link
Collaborator

Duplicate of #2130: We won't fix this, for reasons, see that issue.

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