[Problem Solution] - lombok's @Data is not case-sensitive

Problem Description

When I was compiling the project locally today, I found a very strange problem. It kept prompting that the symbol could not be found at a certain location.
Insert image description here
But it actually displayed normally in Idea. At first I thought it was IDEA's fault again, so I restarted IDEA, executed mvn clean and then recompiled. But the problem has not been solved
Insert image description here


Cause Analysis:

No one has changed this code recently, so I was very confused, so I clicked into the corresponding class and found that someone submitted a new field yesterday, and it was very similar to an original field. There was only one problem with the capitalization of letters. Could it be added? Problem with adding fields?
Insert image description here

Because this class uses the @Data annotation, based on past experience, I felt that there might be a problem with lombok when processing similar fields, and it did not create a get set method for the second field, so I built a class myself and The classes generated by its compilation are decompiled.

Insert image description here

Sure enough, only the first field has a get set method created, and the second field is completely ignored

Insert image description here

Then the cause of the problem has been located. It is actually a bug in lombok. When I was about to report the bug on github, I found that someone had actually mentioned it a long time ago, as shown below:

Insert image description here

At that time, the developer believed that this was not a bug, but that there should not be such two fields with different case in a class at all, and then closed the issue.

Insert image description here

The author says this and it’s actually not a big problem. There are many standards in programming itself, and the framework is based on the standards. If you don’t strictly abide by the standards, it is normal for bugs not to be repaired.


solution:

Handwritten get set method can cure all problems, just use Idea to help us generate it
Insert image description here
Insert image description here
Remove the @Data annotation and compile it again, and find that the compilation returns to normal
Insert image description here
Insert image description here

おすすめ

転載: blog.csdn.net/u011709538/article/details/134988879