Skip to content

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

Merged
merged 5 commits into from
Jun 5, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Error Prone / NullAway support for JSpecify - added Kotlin
  • Loading branch information
bbakerman committed Jun 4, 2025
commit 4fbeccdc96de752a02879bbb74a974973b1d7d5b
24 changes: 22 additions & 2 deletions build.gradle
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 {
Expand All @@ -12,6 +15,9 @@ plugins {
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
id 'org.jetbrains.kotlin.jvm' version '2.1.21'
}

java {
Expand All @@ -20,6 +26,19 @@ java {
}
}

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',
]
}
}

def getDevelopmentVersion() {
def output = new StringBuilder()
def error = new StringBuilder()
Expand Down Expand Up @@ -79,9 +98,10 @@ dependencies {

errorprone 'com.uber.nullaway:nullaway:0.12.6'
errorprone 'com.google.errorprone:error_prone_core:2.37.0'
}

import net.ltgt.gradle.errorprone.CheckSeverity
// just tests
testCompileOnly 'org.jetbrains.kotlin:kotlin-stdlib-jdk8'
}

tasks.withType(JavaCompile) {
options.release = 11
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/dataloader/DataLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
*/
@PublicApi
@NullMarked
public class DataLoader<K, V> {
public class DataLoader<K, V extends @Nullable Object> {

private final @Nullable String name;
private final DataLoaderHelper<K, V> helper;
Expand Down
39 changes: 39 additions & 0 deletions src/test/kotlin/org/dataloader/KotlinExamples.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package org.dataloader

import org.junit.jupiter.api.Test
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 {
Copy link
Member Author

Choose a reason for hiding this comment

The 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 -> CompletableFuture.completedFuture(keys.toList()) }

val cfA = dataLoader.load("A")
val cfB = dataLoader.load("B")

dataLoader.dispatch()

cfA.join().equals("A")
cfB.join().equals("B")
}

@Test
fun `basic kotlin test of nullable value types`() {
val dataLoader: DataLoader<String, String?> = DataLoaderFactory.newDataLoader { keys -> CompletableFuture.completedFuture(keys.toList()) }

val cfA = dataLoader.load("A")
val cfB = dataLoader.load("B")

dataLoader.dispatch()

cfA.join().equals("A")
cfB.join().equals("B")
}

}