Skip to content

make AutoValue work in PubSub #1481

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

Merged
merged 3 commits into from
Dec 20, 2016
Merged

make AutoValue work in PubSub #1481

merged 3 commits into from
Dec 20, 2016

Conversation

pongad
Copy link
Contributor

@pongad pongad commented Dec 16, 2016

This commit digs us out of the AutoValue dependency hell.

Previously

  • We require Guava 20 for its Stats class.
  • Guava source has a @CanIgnoreReturnValue annotation,
    this annotation is in errorprone package.
  • Errorprone package required Java8 to run. So, I just took dependency
    on it without running to make the build pass in both 7 and 8.
  • Errorprone shades class javax.lang.model.type.IntersectionType.
    This class is Java8-only, but because it wasn't run, it didn't cause a problem.
  • AutoValue conditionally loads IntersectionType.
    It catches Exception and behaves properly if the class is not found;
    this is why it works on Java 7.
    However, because of the previous step, we have the class in our path.
    Because the class is 8-only, JVM7 loading it results in
    UnsupportedVersionError. This is an Error and not an Exception,
    and so AutoValue (probably wisely) ignore it and crashes.

The fix is simple.
Since #1480
already removed Stats, we can just go back to Guava 19.

@garrettjonesgoogle is full of wisdom!

@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label Dec 16, 2016
@pongad pongad changed the title DON'T MERGE YET!!! is this working??? make AutoValue work in PubSub Dec 16, 2016
This commit digs us out of the AutoValue dependency hell.

Previously
- We require Guava 20 for its Stats class.
- Guava source has a `@CanIgnoreReturnValue` annotation,
  this annotation is in errorprone package.
- Errorprone package required Java8 to run. So, I just took dependency
  on it without running to make the build pass in both 7 and 8.
- Errorprone shades class javax.lang.model.type.IntersectionType.
  This class is Java8-only, but because it wasn't run, it didn't cause a problem.
- AutoValue conditionally loads IntersectionType.
  It catches Exception and behaves properly if the class is not found;
  this is why it works on Java 7.
  However, because of the previous step, we have the class in our path.
  Because the class is 8-only, JVM7 loading it results in
  UnsupportedVersionError. This is an Error and not an Exception,
  and so AutoValue (probably wisely) ignore it and crashes.

The fix is simple.
Since #1480
already removed Stats, we can just go back to Guava 19.

@garrettjonesgoogle is full of wisdom!
@coveralls
Copy link

Coverage Status

Changes Unknown when pulling 5d8b386 on pongad:autovalue into ** on GoogleCloudPlatform:pubsub-hp**.

@coveralls
Copy link

Coverage Status

Changes Unknown when pulling 58be575 on pongad:autovalue into ** on GoogleCloudPlatform:pubsub-hp**.

@eamonnmcmanus
Copy link

I don't really understand the explanation. If ErrorProne shades IntersectionType, nothing else should see it, even if explicitly loading javax.lang.model.type.IntersectionType, right? Also, I don't see where it is that AutoValue loads that class.

@pongad
Copy link
Contributor Author

pongad commented Dec 17, 2016

@eamonnmcmanus I'm really not a Java expert but here's what I pieced together. I ran

mvn dependency:build-classpath | tr : '\n' | grep error | xargs -l1 zipinfo | grep -e ^Ar -e IntersectionType

The command shows that IntersectionType.class is in $HOME/.m2/repository/com/google/errorprone/javac/1.9.0-dev-r2973-2/javac-1.9.0-dev-r2973-2.jar.
Maybe I was wrong to use the word "shade".

AutoValue seems to be using IntersectionType here

@eamonnmcmanus
Copy link

To step back a bit, the reason I care is that it does not seem right to go back to an earlier version of Guava. You should be able to use the latest version always.

The code in com.google.auto.common that you reference could catch Throwable rather than Exception. We'd have to make new releases of auto.common and auto.value for that to apply.

I'm very puzzled at the dependency from Error Prone that you show. It really shouldn't be polluting the class path with what appear to be classes from the Java 9 javac. Perhaps @eaftan can clarify?

It's also not clear to me from the description why Error Prone needs to be in the picture at all. If it requires Java 8 to run, and you're supposed to be compatible with Java 7, then it sounds as if you are making life difficult for yourselves. Perhaps you could have a Java 8 configuration with Error Prone and a Java 7 configuration without?

@pongad
Copy link
Contributor Author

pongad commented Dec 19, 2016

@eamonnmcmanus I agree that it's not an ideal approach. Thank you for working with me on this.

Including errorprone, in hindsight, seems to be a mistake. However, it seems to be necessary to use guava20. Without it mvn compile fails because CanIgnoreReturnValue was missing from the classpath.

Grepping the source code, the annotation is used in 184 files in guava20, while it is not used at all in guava19.

@eaftan
Copy link

eaftan commented Dec 19, 2016

Hmm, we were aware that Error Prone is polluting the classpath for our non-Maven integrations: google/error-prone#492

But we thought our Maven integration was working correctly. Also, you shouldn't need Error Prone just to use Guava 20. You should be able to depend on our error-prone-annotations artifact to get the @CanIgnoreReturnValue annotation you need for Guava 20. I'll put a comment on the correct line in the PR.

</dependency>
<dependency>
<groupId>com.google.errorprone</groupId>
<artifactId>error_prone_core</artifactId>

This comment was marked as spam.

@pongad
Copy link
Contributor Author

pongad commented Dec 20, 2016

@eaftan Thank you for the suggestion, this seems to make everything work now.

@eamonnmcmanus @garrettjonesgoogle PTAL

}

@AutoValue
public abstract class PublisherStats {

This comment was marked as spam.

This comment was marked as spam.

@coveralls
Copy link

Coverage Status

Changes Unknown when pulling e8220b4 on pongad:autovalue into ** on GoogleCloudPlatform:pubsub-hp**.

@pongad
Copy link
Contributor Author

pongad commented Dec 20, 2016

PTAL. I have left SubscriberStats.Stats empty for now, since I'm still not sure what kind of stats we want.

Copy link

@eamonnmcmanus eamonnmcmanus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@pongad pongad merged commit 62a8aa7 into googleapis:pubsub-hp Dec 20, 2016
@pongad pongad deleted the autovalue branch December 20, 2016 02:34
@coveralls
Copy link

Coverage Status

Changes Unknown when pulling 6c6bc99 on pongad:autovalue into ** on GoogleCloudPlatform:pubsub-hp**.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes This human has signed the Contributor License Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants