Skip to content
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

Fix compilation in Java 9 #3638

Merged
merged 2 commits into from
Mar 29, 2018
Merged

Fix compilation in Java 9 #3638

merged 2 commits into from
Mar 29, 2018

Conversation

ejona86
Copy link
Member

@ejona86 ejona86 commented Oct 30, 2017

Tests still fail; at the very least because of missing Jetty ALPN. I
don't know why the dependency on javax.annotations is unnecessary in the
compiler tests and the example when using Maven.

This depends on #3637. This isn't quite enough for #3633, because we've
not yet clear in our README what's necessary. The annotations stuff is still
very confusing to me; I think our users will suffer unless we have a pretty good
understanding of what's going on and clearly document what they need to do.

CC @carl-mastrangelo

@ejona86
Copy link
Member Author

ejona86 commented Oct 30, 2017

There's quite a bit of confusion on what to do:

  • --add-modules java.xml.ws.annotation. Based on the Java documentation that seems like a temporary solution because the module will be removed. This is also incompatible with -target and -source, but it may be compatible with -release (I didn't try). Also, when using a module, I think it breaks javax.annotation.Nullable (which is probably another issue we need to fix independent of this)
  • There's plenty of references to javax.annotation:jsr250-api:1.0 (note search.maven.org thinks 1.0-20050927.133100 is a later version).
  • Then there's also javax.annotation:javax.annotation-api. The versions should match jsr250, but as with most JSRs it's hard to figure out what version to use when. 1.3 uses -target 1.8 and 1.2 uses -target 1.6
  • Then there's org.glassfish:javax.annotation. The JSR references Glassfish as the "Reference Implementation", but doesn't provide any version information

javax.annotation-api seems the thing to use, but I'd really like to find some clear documentation saying to use it and which version to use (without becoming an expert on the JSR). I would have also hoped for clear documentation (like, "we deploy to Maven Central with artifact id BLAH") at https://github.com/javaee/javax.annotation, but alas. I'll note, it mentions module java.annotation "to match the module name used in JDK 9", but a module by that name doesn't exist in JDK 9; I feel reasonably confident it was renamed several times during JDK 9 development, as in a bug it's called java.annotations.common instead.

Because of the poor state of dependency clarity, I think it's very safe to believe all the deps will be mixed. Luckily, that may not break anything because @Generated is a source-only annotation.

In related news, I continue to dislike the poor usability of the JSR website.

build.gradle Outdated
@@ -214,6 +215,8 @@ subprojects {
netty_proxy_handler: "io.netty:netty-handler-proxy:${nettyVersion}",
netty_tcnative: 'io.netty:netty-tcnative-boringssl-static:2.0.7.Final',

conscrypt: 'org.conscrypt:conscrypt-openjdk-uber:1.0.0',
Copy link
Contributor

Choose a reason for hiding this comment

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

intended?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes. Jetty ALPN doesn't exist in Java 9. So for OkHttp TLS testing it will use Conscrypt instead.

if (ServerBuilder.class.isAssignableFrom(clazz) && clazz != ServerBuilder.class) {
classes.add(clazz);
} else if (ManagedChannelBuilder.class.isAssignableFrom(clazz)
&& clazz != ManagedChannelBuilder.class ) {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: extra space

Copy link
Member Author

Choose a reason for hiding this comment

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

It was pre-existing, but done.

@@ -48,19 +49,39 @@
*/
@Parameters(name = "class={0}")
public static Collection<Object[]> params() throws Exception {
@SuppressWarnings("unchecked")
Copy link
Contributor

Choose a reason for hiding this comment

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

This somewhat defeats the purpose of this test. It showed that every class that gRPC knows about overrides the static ctors, but since you enumerate it, new builders will be missed. (Like the recently added Alts Channel)

Copy link
Member Author

Choose a reason for hiding this comment

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

Not so. We have a hard-coded list, but it is verified when possible (JDK < 9). So that means the list will be kept up-to-date. It is true that if we only ran on JDK 9 the list would likely get out-of-date, but in that case it seems like the best we could do is use the hard-coded list or delete the test. Looking at ClassPath.Scanner.getClassLoaderUrls, it seems impossible to fix for Java 9.

Copy link
Contributor

Choose a reason for hiding this comment

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

If this doesn't work for Java 9, it might as well not run. The list will get out of date, and it will give false confidence.

It would be better to check the java version and call Assume.assumeTrue(javaVersion() <= 8) in a BeforeClass. If that isn't possible you could make a dummy test that asserts there is more than one class to check and throw an assumption exception otherwise.

If this test doesn't work on java 9 then so be it. That's okay.

Copy link
Member Author

Choose a reason for hiding this comment

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

@BeforeClass runs after params(), so an assume in it doesn't work. Similarly, a failing assume in params() causes a test failure. And a dummy test doesn't work because no tests are run if params() returns an empty list.

I'm detecting when getTopLevelClassesRecursive() returns nothing and returning no params in that case. Note that returning an empty list of params causes the test class to be excluded from test reports, since by definition there were no tests within the class. So there isn't any "ignored" count or similar.

@ejona86
Copy link
Member Author

ejona86 commented Mar 26, 2018

@carl-mastrangelo, PTAL

Copy link
Contributor

@carl-mastrangelo carl-mastrangelo left a comment

Choose a reason for hiding this comment

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

LGTM

@ejona86 ejona86 merged commit 4e82e62 into grpc:master Mar 29, 2018
@ejona86 ejona86 deleted the java9 branch March 29, 2018 00:13
ejona86 added a commit that referenced this pull request Jul 30, 2018
Previously it was just erroring:
[[: command not found

This has been broken since #3638
@lock lock bot locked as resolved and limited conversation to collaborators Jan 18, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants