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 JSpecify support on JDK 21 #869

Merged
merged 27 commits into from
Jan 10, 2024

Conversation

akulk022
Copy link
Collaborator

@akulk022 akulk022 commented Nov 25, 2023

Our JSpecify mode would not run on JDK 21 due some some internal javac API changes. This PR adapts to those changes using code specific to JDK 21.

Fixes #827

Copy link

codecov bot commented Nov 25, 2023

Codecov Report

Attention: 16 lines in your changes are missing coverage. Please review.

Comparison is base (257e4bb) 87.20% compared to head (b7d94cf) 86.94%.

❗ Current head b7d94cf differs from pull request most recent head ac250ed. Consider uploading reports for the commit ac250ed to get more accurate results

Files Patch % Lines
...laway/generics/PreservedAnnotationTreeVisitor.java 66.66% 13 Missing and 2 partials ⚠️
...away/src/main/java/com/uber/nullaway/NullAway.java 88.88% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master     #869      +/-   ##
============================================
- Coverage     87.20%   86.94%   -0.26%     
- Complexity     1947     1952       +5     
============================================
  Files            77       77              
  Lines          6268     6314      +46     
  Branches       1216     1222       +6     
============================================
+ Hits           5466     5490      +24     
- Misses          403      420      +17     
- Partials        399      404       +5     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Collaborator

@msridhar msridhar left a comment

Choose a reason for hiding this comment

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

Looks great! A few requested changes / comments

}
// This will cause the test tasks to run if the coverage data is requested by the aggregation task
tasks.withType(Test).forEach {task ->
outgoing.artifact(tasks.named(task.name).map { t -> t.extensions.getByType(JacocoTaskExtension).destinationFile })
Copy link
Collaborator

Choose a reason for hiding this comment

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

The whole tasks.named(task.name) thing is a horrible hack to force the test task to run when the coverage report is requested. I'll see if I can find a better way.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Meh, let's leave this hack for now and fix this properly in #871

Copy link
Collaborator

Choose a reason for hiding this comment

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

SGTM!

@msridhar
Copy link
Collaborator

msridhar commented Dec 1, 2023 via email

@msridhar msridhar marked this pull request as ready for review December 1, 2023 16:58
@msridhar msridhar requested a review from yuxincs December 1, 2023 16:59
@msridhar msridhar changed the title JSpecify: changes for using addMetadata and dropMetadata for jdk21 using MethodHandle Fix JSpecify support on JDK 21 Dec 1, 2023
@@ -118,3 +102,23 @@ def testJdk21 = tasks.register("testJdk21", Test) {
tasks.named('check').configure {
dependsOn testJdk21
}


// Share the coverage data to be aggregated for the whole product
Copy link
Collaborator

Choose a reason for hiding this comment

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

This change is required so that test coverage when running tests on JDK 21 gets reported to CodeCov.

Copy link
Collaborator

@yuxincs yuxincs left a comment

Choose a reason for hiding this comment

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

Overall LGTM! Just have a minor comment suggestions since we plan to drop JDK 8 in the near future.

}
// This will cause the test tasks to run if the coverage data is requested by the aggregation task
tasks.withType(Test).forEach {task ->
outgoing.artifact(tasks.named(task.name).map { t -> t.extensions.getByType(JacocoTaskExtension).destinationFile })
Copy link
Collaborator

Choose a reason for hiding this comment

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

SGTM!

Comment on lines -127 to -134
tasks.named('testJdk21', Test).configure {
filter {
// JSpecify Generics tests do not yet pass on JDK 21
// See https://github.com/uber/NullAway/issues/827
excludeTestsMatching "com.uber.nullaway.NullAwayJSpecifyGenericsTests"
}
}

Copy link
Collaborator

Choose a reason for hiding this comment

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

Nice! 👍

Comment on lines 220 to 236
/**
* Utility method to get the current JDK version, that works on Java 8 and above.
*
* @return the current JDK version
*/
private static int getVersion() {
String version = System.getProperty("java.version");
if (version.startsWith("1.")) {
version = version.substring(2, 3);
} else {
int dot = version.indexOf(".");
if (dot != -1) {
version = version.substring(0, dot);
}
}
return Integer.parseInt(version);
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

We won't need this anymore once we drop support for JDK 8, right? Since we can use Runtime.version() starting from JDK 9 https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/lang/Runtime.html#version()

If so maybe worth adding a TODO here for a cleanup reminder since we plan to drop JDK 8 in the near future 😃

Copy link
Collaborator

Choose a reason for hiding this comment

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

Good point! Done in ac250ed

@msridhar msridhar enabled auto-merge (squash) January 10, 2024 16:16
@msridhar msridhar merged commit 97771dc into uber:master Jan 10, 2024
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Fix JSpecify generics code on JDK 21
3 participants