How much will insurance cost me?

I am 16 years old. I live in Skowhegan Maine, 04976. I will be driving a 2000 ford taurus. I completed drivers ed. My own policy, no parent to go under. ANSWER: I recommend that you visit this site…

Smartphone

独家优惠奖金 100% 高达 1 BTC + 180 免费旋转




Some Dangers of Using Lombok

Java and Lombok are close to each other. Maybe too close ? :)

I happened to become a user of Lombok in an existing codebase. After some fustrating hours let me share some thoughts about its dangers, which I became aware of.

The integration with Eclipse is anyway not perfect. If we want to see the callers of a setter or getter, we cannot do so, since there is no such method in the editor to right click on. The only workaround I know is to open the outline and there we can look for the method and in the local menu call hierarchy can be triggered.

If I want to see, why two objects are not equal, I have lost again. I can set a method breakpoint, but I have no idea on which code lines I debug step by step. Again, pain. I can delombok the code and then debug, but then why should I use Lombok anyway? I recently decompiled a class just to see, which step inside the equals method results in a “false” return value.

My example is a simple parent class with a subclass.

So both foo and bar are the same, still according to the generated equals method they are not equal.

Here I think Lombok is simply wrong. It should always give a compile error, if my class extends anything having the default hashcode method (not only for java.lang.Object itself, like in the quote above).

I think earlier someone tried this cool feature “callSuper”. Default value is false. He or she has seen, oops. I got a warning… Ok, lets make it true, then it works…

If we use a hammer, we should know exactly how it works. Since WrongEntityExample has the callsuper set to true, it will call the equals method of the POJO class, which is the default implementation. That gives only true back if the two references refer to the same object. So I can construct any number of WrongEntityExample, they will be never equal to each other.

The correction is simply setting callSuper to false:

These things are not caused by Lombok, but by using it inappropiate. Still Lombok makes it easy to be used inappropiate.

Lets suppose I have a bean like this:

At first I had only fooo and bar as members and only bar was used in equals and hashcode.

Then some day, a developer makes some internal calculation and caches it in the myInternalCalculationResult. He forgets to exclude the field and the internal state of the SideEffectExample class is directly exposed with a setter and getter. Thats bad. Without Lombok it would not happen, since I have a reflex to make all fields private by default and I do not generate automatically getters and setters like Lombok.

After that thisIsSomeCachedValue is added, which as the name supposes has nothing to do with the equality of the object. Still it will be silently involved into the equality check and ruins probably everything. Again this does not happen without Lombok, since it would not be included automatically otherwise.

My personal answer is no. Thanks. I do not need Lombok.

Add a comment

Related posts:

3 Value Generating Opportunities Unique to Crypto Assets

By owning cryptoassets, people are entitled to a variety of rights that are difficult to claim and/or not apparent. These rights take the following 3 main forms: Forks happen when there is a divide…

But what is the difference between UX and UI?

I recently finished a ¨Google UX Design Specialization¨ designed by Google. Here I will share my thoughts about a few things that I learned from this UI/UX Bootcamp. But before we begin, what is UX…

The Advantages and Disadvantages of Transcribing

As a Virtual Assistant, one of the services you may want to consider offering to your clients is transcription. While it sounds easy enough (you listen to an audio tape and just type what you hear)…