-
Notifications
You must be signed in to change notification settings - Fork 94
Error Prone / NullAway support for JSpecify #196
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
Changes from all commits
3f676ac
4fbeccd
4a68a39
7a6749e
afd5dc1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
import org.jetbrains.kotlin.gradle.dsl.JvmTarget | ||
import org.jetbrains.kotlin.gradle.dsl.KotlinVersion | ||
import net.ltgt.gradle.errorprone.CheckSeverity | ||
import java.text.SimpleDateFormat | ||
|
||
plugins { | ||
|
@@ -11,11 +14,28 @@ plugins { | |
id 'io.github.gradle-nexus.publish-plugin' version '1.0.0' | ||
id 'com.github.ben-manes.versions' version '0.51.0' | ||
id "me.champeau.jmh" version "0.7.3" | ||
id "net.ltgt.errorprone" version '4.2.0' | ||
|
||
// Kotlin just for tests - not production code | ||
id 'org.jetbrains.kotlin.jvm' version '2.1.21' | ||
} | ||
|
||
java { | ||
toolchain { | ||
languageVersion = JavaLanguageVersion.of(11) | ||
languageVersion = JavaLanguageVersion.of(17) | ||
} | ||
} | ||
|
||
kotlin { | ||
compilerOptions { | ||
apiVersion = KotlinVersion.KOTLIN_2_0 | ||
languageVersion = KotlinVersion.KOTLIN_2_0 | ||
jvmTarget = JvmTarget.JVM_11 | ||
javaParameters = true | ||
freeCompilerArgs = [ | ||
'-Xemit-jvm-type-annotations', | ||
'-Xjspecify-annotations=strict', | ||
] | ||
} | ||
} | ||
|
||
|
@@ -75,8 +95,35 @@ dependencies { | |
// this is needed for the idea jmh plugin to work correctly | ||
jmh 'org.openjdk.jmh:jmh-core:1.37' | ||
jmh 'org.openjdk.jmh:jmh-generator-annprocess:1.37' | ||
|
||
errorprone 'com.uber.nullaway:nullaway:0.12.6' | ||
errorprone 'com.google.errorprone:error_prone_core:2.37.0' | ||
|
||
// just tests | ||
testCompileOnly 'org.jetbrains.kotlin:kotlin-stdlib-jdk8' | ||
} | ||
|
||
tasks.withType(JavaCompile) { | ||
options.release = 11 | ||
options.errorprone { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. builds with v17 - targets v11 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmmm .. I don't think we can do that: build with 17 would allow to use APIs which are in 17, but not in 11, which would result in errors when run with 11. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure how to achieve errorprone / nullaway checking without this I took this from @bclozel examples : bclozel@f449972 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It should be safe as the "-release" option is tailored for that:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. https://docs.gradle.org/current/userguide/building_java_projects.html#sec:compiling_with_release
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So we are running the v17 compiler but using the "release" of JDK 11 including libraries |
||
disableAllChecks = true | ||
check("NullAway", CheckSeverity.ERROR) | ||
// | ||
// end state has us with this config turned on - eg all classes | ||
// | ||
//option("NullAway:AnnotatedPackages", "org.dataloader") | ||
option("NullAway:OnlyNullMarked", "true") | ||
option("NullAway:JSpecifyMode", "true") | ||
} | ||
// Include to disable NullAway on test code | ||
if (name.toLowerCase().contains("test")) { | ||
options.errorprone { | ||
disable("NullAway") | ||
} | ||
} | ||
} | ||
|
||
|
||
task sourcesJar(type: Jar) { | ||
dependsOn classes | ||
archiveClassifier.set('sources') | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package org.dataloader | ||
|
||
import org.junit.jupiter.api.Test | ||
import java.util.concurrent.CompletableFuture | ||
import java.util.concurrent.CompletableFuture.* | ||
|
||
/** | ||
* Some Kotlin code to prove that are JSpecify annotations work here | ||
* as expected in Kotlin land. We don't intend to ue Kotlin in our tests | ||
* or to deliver Kotlin code in the java | ||
*/ | ||
class KotlinExamples { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just enough Kotlin - tests only confirmed the build .jar has no Kotlin classes! |
||
|
||
@Test | ||
fun `basic kotlin test of non nullable value types`() { | ||
val dataLoader: DataLoader<String, String> = DataLoaderFactory.newDataLoader { keys -> completedFuture(keys.toList()) } | ||
|
||
val cfA = dataLoader.load("A") | ||
val cfB = dataLoader.load("B") | ||
|
||
dataLoader.dispatch() | ||
|
||
assert(cfA.join().equals("A")) | ||
assert(cfA.join().equals("A")) | ||
} | ||
|
||
@Test | ||
fun `basic kotlin test of nullable value types`() { | ||
val dataLoader: DataLoader<String, String?> = DataLoaderFactory.newDataLoader { keys -> completedFuture(keys.toList()) } | ||
|
||
val cfA = dataLoader.load("A") | ||
val cfB = dataLoader.load("B") | ||
|
||
dataLoader.dispatch() | ||
|
||
assert(cfA.join().equals("A")) | ||
assert(cfA.join().equals("A")) | ||
} | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
needs to run on 17 to get errorprone happy (compiled for 17)
but we target 11 later