-
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
patch for "AutoValue should respect @Nullable annotations on types #283" #293
Conversation
Thanks for your pull request. It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). 📝 Please visit https://cla.developers.google.com/ to sign. Once you've signed, please reply here (e.g.
|
Thanks for this contribution! If I could make a couple of requests:
Since the main motivation for this change is to ensure that null values are allowed if a property is FYI the way our code flow works we won't be merging this PR. Instead, we'll submit it into Google's internal code base and it will appear at our next push as a later PR that references this one. We do need the CLA to be signed before we can start that. |
"Rather than having a Java 8 version of CompilationTest, I think it would be more maintainable to have a Java 8 version of AutoValueTest. I'd like to minimize the amount of code that tests the exact code generated, because it's a pain to update it all whenever we change the details of code generation." I felt a bit of the pain while creating the test, so I really understand what you mean. The problem is that TYPE_USE annotations don't compile at all with java 7 or older, so the integration tests wouldn't even compile and I currently have no idea how to exclude the tests on the maven level depending on the jdk. I'll have a look at the indentation and CLA. |
Wrt the test, you'd create a new integration-test project (e.g. There probably are ways to get it run with Java 8 while Maven is invoked with a JDK 7, using Maven Toolchains, but AFAICT it's a PITA to get it working and would require everyone willing to build the project to configure his Maven toolchains. |
I signed it! |
We found a Contributor License Agreement for you (the sender of this pull request), but were unable to find agreements for the commit author(s). If you authored these, maybe you used a different email address in the git commits than was used to sign the CLA (login here to double check)? If these were authored by someone else, then they will need to sign a CLA as well, and confirm that they're okay with these being contributed to Google. |
I signed it! |
CLAs look good, thanks! |
Thanks for the hints regarding maven, I'll try to create a java 8 version of AutoValueTest. |
It looks like AutoValueTest currently doesn't get executed at all. The files Maybe this was not intended? |
Yow! It looks as if something pretty bad happened in that commit. We'll need to investigate. (Paging @cgruber...) |
Fixed. Please fetch the remote origin branch and rebase this pull On Tue, 1 Dec 2015 at 08:38 Éamonn McManus notifications@github.com wrote:
|
3b65e8e
to
d8d05b3
Compare
Limitations: The following cases currently don't work with javac (i.e. the annotation processors don't see the @nullable so a null check is generated in the constructor): public abstract int @nullable [] getInts() This works with eclipse JDT and the null check is ommited in the generated code, but note that the @nullable is in the wrong position in the generated code (i.e. @nullable int[] instead of int @nullable[])), which might lead to compiler warnings For generic type T: @nullable public abstract T getT() (works in JDT) Also @nullable won't work for types which can't be imported because of naming conflicts, because the @nullable is generated at the wrong place, i.e. "@nullable some.package.Map" instead of "some.package.@nullable Map" which won't compile at all for TYPE_USE @nullable.
d8d05b3
to
336cbcb
Compare
Updated. Some notes:
Limitations: The following cases currently don't work with javac (i.e. public abstract int @nullable [] getInts() For generic type T: Also @nullable won't work for types which can't be imported because of |
Regarding the javac limitations: openjdk bug 8031744 is fixed for java 9 as of JEP 217. I have tried the it/functional-java8 test with the Early Access Java 9 Build 95 and the annotations are now visible to the Annotations processor, so the @Nullable
@Override
public @com.google.auto.value.annotation.Nullable T t() {
return t;
} |
Thanks for this detailed investigation! I'm not sure whether JDK 9 should be including annotations in the toString. Maybe. Regardless, avoiding the problem seems straightforward, by overriding This makes me think that |
Limitations: The following cases currently don't work with javac (i.e. the annotation processors don't see the @nullable so a null check is generated in the constructor): public abstract int @nullable [] getInts() This works with eclipse JDT and the null check is ommited in the generated code, but note that the @nullable is in the wrong position in the generated code (i.e. @nullable int[] instead of int @nullable[])), which might lead to compiler warnings For generic type T: @nullable public abstract T getT() (works in JDT) Also @nullable won't work for types which can't be imported because of naming conflicts, because the @nullable is generated at the wrong place, i.e. "@nullable some.package.Map" instead of "some.package.@nullable Map" which won't compile at all for TYPE_USE @nullable. This change was imported from github: google#293 The original author is Till Brychy. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=120629206
This code has been incorporated into the latest snapshot. Thanks! Our processes mean that we do this in Google's internal repository rather than merging the code here, so I'm closing the PR. |
The patch invokes the required java8-method via reflection, so everything should work with earlier java version (verified with java 7). The tests for java 8 functionality are ignored with earlier java versions, too.
What currently doesn't work (because of javac limitations):
abstract java.lang.@nullable String anString()