Giter Site home page Giter Site logo

Comments (29)

dabrowt1 avatar dabrowt1 commented on July 17, 2024 2

This seems simple but would be very helpful.

from lombok.

lombokissues avatar lombokissues commented on July 17, 2024 1

๐Ÿ‘ค danielmalcolmabraham ย  ๐Ÿ•— Aug 19, 2013 at 12:58 UTC

I'm sure this is obvious, but when this happens, could it happen on @ Value as well please?

Thank you very much.

from lombok.

randakar avatar randakar commented on July 17, 2024 1

from lombok.

rzwitserloot avatar rzwitserloot commented on July 17, 2024 1

Now for some specific points:

  • I now get bugs because I did want to call super impls, and lombok by default does not.

That's what the warning is for. Unfortunately, the semantic meaning of 'warning' is not universally understood. Team lombok espouses the idea that warnings are virtually as bad as errors are, they only real difference is that, unlike with an error, you can continue your test run or debug session with warnings. Just like with errors, you should definitely not leave them in, check them into source control (unless in a debug branch), and they should absolutely never make it to production.

With that mindset, this problem goes away. Unfortunately it is not possible to cater to the mindset that warnings may safely be ignored; there is no default behaviour that works in all cases. You've run into a situation where 'call the supers' was a better choice, but there are cases where it is the wrong choice; there is no one-answer-fits-all, which is why we generate that warning. Somebody needs to make a choice and lombok is not technically capable of automatically figuring out which one is correct. We cannot fix this.

  • ... but my team did read the warning, didn't understand it, stuck 'callSuper = false' on it because it makes the warning go away, but now we still have bugs.

At risk of belittling your team's intelligence, I'm disregarding this one as a problem of lombok. For the same reason: If we posit that that's how development works, it is impossible for lombok to do the right thing. I'm taking this mindset (hey, if I do this, the warning goes away! Clearly that means I wrote correct code) โ€“ as a kind of code style I sometimes observe: You more or less type random stuff into your editor until things seem to work out (no errors, in this case no warnings, and a first run seems to indicate things appear to be working). If you are neither willing to fully test your code nor willing to take the time to understand what code (or in this case, a warning) means, then you're going to have bugs. There is nothing lombok can do to stop it from happening, and thus whilst I am totally on board that the best would be that lombok somehow prevents bugs here, we... can't. There's no point keeping an impossible feature request on the books.

  • how does SuperBuilder work?

... it works, and without resolution. If you delombok an @SuperBuilder class you can see the magic. It's.. a lot of weird generics. The way superbuilder was done simply cannot be applied sensibly to normal classes, and note that superbuilder inherently only works if the entire chain was all built with superbuilder; lombok's callSuper parameter is intended to work even if your parent's class has no lombok-generated implementations of toString and the like (though, given that it is impossible to just get it right silently if they aren't, lombok generates that warning: It's asking you to tell lombok that the parent's impls are compatible, and that you are willing to sign up to the notion that the API of the parent class is now signed up to maintaining this compatibility. Lombok obviously cannot silently inject future promises, which is why it has to be explicit).

  • Okay, so back to the simple case, the original intent of this feature request: @Data(callSuper = false)

Other than the precedence issue (which can be solved with Maaartinus' idea: The more specific one takes precedence), there's the constructor issue: @Data covers many annotations, and one of them doesn't have a callSuper: The @RequiredArgsConstructor. I can imagine someone reading the code would assume that Data(callSuper=true) also implies the non-existent @RequiredArgsConstructor(callSuper = true), and that this non-existent feature implies to call that constructor which covers each required arg. Which can be done โ€“ but only with resolution, and I assume everyone is aware that many lombok users are unaware that lombok cannot easily provide resolution-based features, and if not, well, I submit this very thread as Exhibit A :)

Given that I feel unsure that the text that appears in your source code will be properly understood, and that the feature only saves a relatively small and stable amount of boilerplate (does not expand if you add more fields, nor does it require that you rewrite it if you change your fields), the feature is not accepted.

PRs will not be merged.

To change this conclusion, I think it'd be a good idea to start up a new feature request (this one has been all over the place), referencing this one for historic context, but it would need a solid, implementable plan to solve the above issues. And frankly, I don't see any feasible route to that other than 'lombok does resolution now, with no caveats or maintenance burden'. Which we do want, one day. That day isn't today. I'm not worried about this feature once that day arrives: Changing what @Data and friends do will be the very first thing we'd use our shiny new 'oooh we have resolution now!' hammer on, I don't need an issue to remind me of how nice that'd be :)

from lombok.

lombokissues avatar lombokissues commented on July 17, 2024

๐Ÿ‘ค reinierz ย  ๐Ÿ•— Aug 05, 2009 at 20:17 UTC

This will also involve making @ EqualsAndHashCode and @ ToString aware of @ Data, as they'll need
to read @ Data's callSuper value if the user didn't explicitly specify one for @ EqAHC or @ ToString.

from lombok.

lombokissues avatar lombokissues commented on July 17, 2024

๐Ÿ‘ค jacek99 ย  ๐Ÿ•— Aug 13, 2009 at 14:15 UTC

+1 from me, it makes class inheritance problematic

from lombok.

lombokissues avatar lombokissues commented on July 17, 2024

๐Ÿ‘ค pe.fips ย  ๐Ÿ•— May 08, 2012 at 19:16 UTC

Here is a proof-of-concept implementation:

https://github.com/peichhorn/lombok/tree/Issue_19_%40Data_needs_a_callSuper

  • Philipp

from lombok.

lombokissues avatar lombokissues commented on July 17, 2024

๐Ÿ‘ค reinierz ย  ๐Ÿ•— May 09, 2012 at 09:32 UTC

from lombok.

lombokissues avatar lombokissues commented on July 17, 2024

๐Ÿ‘ค serverperformance ย  ๐Ÿ•— Jul 03, 2012 at 23:07 UTC

Is there an expected release date/version for this enhacement? (if any)
Thank you very much!

from lombok.

lombokissues avatar lombokissues commented on July 17, 2024

๐Ÿ‘ค askoning ย  ๐Ÿ•— May 09, 2013 at 08:15 UTC

Issue #550 has been merged into this issue.

from lombok.

lombokissues avatar lombokissues commented on July 17, 2024

๐Ÿ‘ค mederel ย  ๐Ÿ•— May 30, 2013 at 11:50 UTC

Hi, same question: is there an expected date version for this enhancement?
I see it marked for label 0.11.1. Does this means it is already included since 0.11.1?

Currently using 0.11.8 I write @ Data on a superclass and @ Data on a subclass and I get the warning that follows on the subclass:
"Generating equals/hashCode implementation but without a call to superclass, even though this class does not extend java.lang.Object. If this is intentional, add '@ EqualsAndHashCode(callSuper=false)' to your type."
Adding the line: "@ EqualsAndHashCode(callSuper = true)" the warning disappear.

Thanks and cheers, Emile

from lombok.

lombokissues avatar lombokissues commented on July 17, 2024

๐Ÿ‘ค r.spilker ย  ๐Ÿ•— Nov 08, 2013 at 13:16 UTC

Issue #443 has been merged into this issue.

from lombok.

lombokissues avatar lombokissues commented on July 17, 2024

๐Ÿ‘ค [email protected] ย  ๐Ÿ•— Jun 11, 2015 at 22:09 UTC

See #69

from lombok.

lombokissues avatar lombokissues commented on July 17, 2024

End of migration

from lombok.

tburch avatar tburch commented on July 17, 2024

Would love to see this! ๐Ÿ‘

from lombok.

jordanms avatar jordanms commented on July 17, 2024

Calling the super implementation for Equals and Hashcode should be the default behavior when the target class does not extend java.lang.Object. As changing default value for @EqualsAndHashCode would break compatibility, adding the parameter callSuper to @Data and @Value would add great value as we wouldn't need to add extra @EqualsAndHashCode(callSuper = true) annotation.

from lombok.

demi365 avatar demi365 commented on July 17, 2024

This is like a much needed feature, Call super feature in lombok inheritance, I have a project which have a bunch of classes that inherit classes down the line, and it would be much helpful, if we can have this feature in lombok.

from lombok.

rzwitserloot avatar rzwitserloot commented on July 17, 2024

@demi365 that requires Resolution and therefore not going to happen anytime soon; it'd be extremely complicated to get that right. The callSuper that this feature refers to is something else.

from lombok.

rzwitserloot avatar rzwitserloot commented on July 17, 2024

@jordanms there is no guarantee that the parent class has sensible support for either, or for that matter, has fields. Really, we don't KNOW what we ought to do, which is why we emit a warning instead; force you to acknowledge it.

This entire issue looks like it's filled with people who think that this feature request implies that lombok will figure out what parent's fields are or if parent has sensible implementations of equals and hashCode. There is no real way we can know; at best we can detect that lombok generated their equals, hashCode, toString etc and thus automatically do the right thing, but that's NOT what this is about. I'm closing it, as a consequence.

from lombok.

jordanms avatar jordanms commented on July 17, 2024

@rzwitserloot I didn't say to force that behavior, I said it should be the default. I also didn't say that lombok has to figure out if the parent class has fields that matter or not. I also didn't see anyone saying what you understood. Seems you didn't understand the proposition and you are being rude to people with no reason.

What we want is very simple: add the configuration so we can avoid few extra lines of code.

It's a pity you couldn't understand that.

from lombok.

demi365 avatar demi365 commented on July 17, 2024

from lombok.

janrieke avatar janrieke commented on July 17, 2024

@jordanms There is a reason why callSuper = true is not and should not be the default: It leads to hard-to-find bugs, because people will use it on classes where the superclass does not implement it, and suddenly no instances are equal because it also calls Object.equals().
You could argue that lombok should make callSuper = true the default, but also emit a warning. But where is the difference to the current behaviour (callSuper = false + warning)? You do not want warnings in your code, so you still have to acknowledge this by explicitly setting callSuper = true.

But let's get back to the original topic of this issue: an additional parameter callSuper = false for @Data (and possibly @Value).
Will it allow removing 2 additional annotations? Yes.
Will it make things more complicated? Also yes, because lombok has to check for possible contradictions on the parameter. E.g. what should be the result of @Data(callSuper = true) @ToString(callSuper = false)? An error, a warning, or does the more special annotation (@ToString) take precedence (so only equals() and hashCode() will call super)? It's not that easy.

from lombok.

janrieke avatar janrieke commented on July 17, 2024

@demi365 The problem is not figuring out the name of the superclass; lombok could do that just by looking at the extends clause. The problem is that this superclass is not accessible when lombok processes the subclass, so lombok cannot figure out how the constructor and the fields of this superclass look like.
This is the reason @rzwitserloot refers to when saying "It requires resolution."

from lombok.

demi365 avatar demi365 commented on July 17, 2024

from lombok.

jordanms avatar jordanms commented on July 17, 2024

@janrieke I got a bug because I annotated my class with @ToStringAndHashCode and the super methods were not called (I assume it would be the default). In my opinion, implementing toString and hashCode is mandatory and any developer should follow it because not doing so creates lots of hard to find bugs. Even worse than not implementing those methods, is to implement in the child class and not in the parent class (when it is not Object). If you got a case when you only need to look at the child to see if these objects are equal or not, then most likely the class should not have a parent. This is a good OO pattern and libraries should follow and enforce, as maximum as possible, good patterns. Therefore, have callSuper = true as default is the most appropriated. For the developers that don't follow it, this behavior is configurable, so they can set callSuper = false.
Regarding the warning, in my current company, they use @ToStringAndHashCode(callSuper = false) and I asked them why and the answer was that without it they get a warning! I guess the same is happening in other companies and I think this is not the intention of the warning. So I suggest you guys improve the message so people will think if they should set it to true or false.

Orignal topic

Will it make things more complicated?

As you said, yes. However, it will be more complicated for Lombok only. And I don't think it is a big deal for Lombok to solve the problems from it, because you guys already solved for other annotations. For instance, when annotating a class with @Value @Builder, or when in the class level we have @Data and in a field, we have @Getter(AccessLevel.PRIVATE). It is just a matter of setting the rules, which should not be complicated.

I also don't think it would be difficult to implement, the current solution for the Constructor annotations requires the parent class to have a default constructor and this constraint could be kept as @Data is just an umbrella for the other annotations. If we stick the solution to the behaviour we have currently, it is completely doable.

from lombok.

jordanms avatar jordanms commented on July 17, 2024

I really don't understand how you guys read that we want to change the current behavior. Pay attention: WE DO NOT WANT TO CHANGE CURRENT BEHAVIOR!!

Current solutions:

@Data
@ToString(callSuper = true)
@ToStringAndHashcode(callSuper = true)
public class A extends B {
}

Proposed solution:

@Data(callSuper = true)
public class A extends B {
}

How is it impossible? How does it change any current behavour?

from lombok.

Maaartinus avatar Maaartinus commented on July 17, 2024

@janrieke

Will it make things more complicated? Also yes, because lombok has to check for possible contradictions on the parameter. E.g. what should be the result of @Data(callSuper = true) @ToString(callSuper = false)? An error, a warning, or does the more special annotation (@ToString) take precedence (so only equals() and hashCode() will call super)? It's not that easy.

The more specific annotation should take precedence as this is what Lombok always does and also the reason for using them. OTOH, using both @Data(callSuper = true) and @ToString(callSuper = false) on the same scope does make little sense and should produce a warning. I'd vote for both: precedence and warning. Maybe someone can come up with a good use case for this combination and then the warning could go.

@jordanms

How is it impossible? How does it change any current behavour?

One problem is the possible setting conflict (s. above). Another problem is increasing the number of annotation arguments, which Lombok always tries to avoid. While you proposal saves just two lines per class, it seems to make sense as it makes Lombok simpler to use.

@jordanms

Regarding the warning, in my current company, they use @ToStringAndHashCode(callSuper = false) and I asked them why and the answer was that without it they get a warning! I guess the same is happening in other companies and I think this is not the intention of the warning. So I suggest you guys improve the message so people will think if they should set it to true or false.

I guess, you can help to make this happen by providing a PR or a better message.

Disclaimer: I'm not the project owner.

from lombok.

rzwitserloot avatar rzwitserloot commented on July 17, 2024

@jordanms Different cultural standards, perhaps? It wasn't intended as rude, and rereading what I wrote, I don't think I'm being rude. I apologize if it comes across as such. Note, however, that I'm having a very hard time understanding how what I wrote was rude, but this:

Pay attention: WE DO NOT WANT TO CHANGE CURRENT BEHAVIOR!!

is not. I ask you to keep an open mind before immediately jumping to the conclusion that rudeness is intended (It was not), whilst also trying to avoid coming across as rude if you can, which that line certainly did.

@randakar did a good job explaining the issues with resolution and the like.

from lombok.

jordanms avatar jordanms commented on July 17, 2024

@jordanms Different cultural standards, perhaps? It wasn't intended as rude, and rereading what I wrote, I don't think I'm being rude. I apologize if it comes across as such. Note, however, that I'm having a very hard time understanding how what I wrote was rude, but this:

Pay attention: WE DO NOT WANT TO CHANGE CURRENT BEHAVIOR!!

is not. I ask you to keep an open mind before immediately jumping to the conclusion that rudeness is intended (It was not), whilst also trying to avoid coming across as rude if you can, which that line certainly did.

Not my fault if people don't read things before commenting. This is just a way of catching people's attention for something that was mentioned at least 4 times before.

@rzwitserloot, I'm not saying Lombok has to catch bugs for me, I'm saying that the reasons you presented are not sufficient to justify your decisions as they apply to both sides. And I'm glad you recognized that. Also, this is not a matter if it is technical possible or not to implement the requested feature (as you tried to put it in the beginning), but how you think it should be (or how you think people will understand the change). This is not a technical discussion, just people giving their opinion. It's your project, your decision. As a user of your library, I'm already avoiding it in my new project. The classes are getting overloaded with annotations and it makes the code not took nice.

from lombok.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.