-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Generated equals(Object) method parameter should be @Nullable #73
Comments
I agree - this is entirely in line with the philosophy of "what you would have written". That said, I think this is one of the few cases where a processor option is appropriate because I wouldn't want to force users into an additional compile-time option. Any thoughts on this @eamonnmcmanus? |
I don't think there's any actual reason to avoid this. It feels like |
I'm strongly against AutoValue saddling users with a compile-time dep that On Mon, Feb 10, 2014 at 10:52 AM, Christian Edward Gruber <
Kevin Bourrillion | Java Librarian | Google, Inc. | kevinb@google.com |
Why? Quite honestly here, why? They didn't ask for a Guava dependency |
I don't think that's true. We don't use Guava anywhere in the processor. On Mon, Feb 10, 2014 at 11:32 AM, Christian Edward Gruber <
Kevin Bourrillion | Java Librarian | Google, Inc. | kevinb@google.com |
Ah. I see the point. I guess having not worked without a |
I confirm that the AutoValue processor does not use Guava, either in its own code or in the code it generates. I would not like to generalize from Christian's never needing to worry about dependencies to saying that nobody should. Additionally, the point about AbstractPackageSanityTests seems flimsy to me. I don't think NullPointerTester should ever require equals(Object) to throw an exception if given a null argument, regardless of the presence or absence of As an additional wrinkle, we recently changed the AutoValue processor so it would understand a In conclusion, I don't think it would be a good idea to make this change. |
@eamonnmcmanus, what would you think about a compiler flag to allow user to set the FQN of the Nullable annotation they would (or wouldn't) want to use? |
My bad, Eamonn. I do have a tendency to mix the auto projects a bit, and I did think that autovalue used Guava in the processor. But no matter. The view of this group is clearly against permitting this, and I can understand it. |
@gk5885, we don't currently include We could also put |
I would agree with @cgruber regarding a dependency on a package with the |
My 2c. I agree with Éamonn; accepting nulls is part of Object#equals'
|
From the javadocs of
So, it's very clear (of course) that the parameter to As a user, I'm fine with |
Another approach is to simply test for the presence of javax.annotation.Nullable in the processing environment - if it's there, use it, if not, don't. This leaves the signaling as a simple matter of "add it to your classpath if you care" and that takes care of the build dep issue also. |
That's an interesting suggestion, @cgruber. I'm a bit hesitant to make the output depend on whether a class is available. Elsewhere in Java I don't think we ever have a situation where you can get one successful compiler output if a class is present and a different successful compiler output if the only difference is that is not. [Puzzler?] To come back to the original reason for this discussion, it seems strange that the result of AbstractPackageSanityTests.testsNulls() would depend on what had been in the classpath when the package under test was compiled. |
I think annotations are the only place you could get away with such, @eamonnmcmanus, since they need only be present in the compile (and are guaranteed to be so in this case) but can be elided in the runtime environment if they do not need to be processed in the runtime environment (or can be processed reflectively). I have no strong commentary on AbstractPackageSantityTests, sorry. |
I think it may be hard to figure out whether the user added Another note is that I would say that the argument in favour of supporting generating code with Was there an argument against the use of a processor option for this? Such a processor option could specify the fully qualified class name of the annotation to use. |
I'm -1 for any such auto-detection. |
In AutoValue,
should be
I think it's better form, and without it, AutoValue doesn't play nicely with Guava's AbstractPackageSanityTests.
The text was updated successfully, but these errors were encountered: