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

[java] NullAway checks added #14421

Open
wants to merge 7 commits into
base: trunk
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
8 changes: 8 additions & 0 deletions .github/workflows/ci-java.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,11 @@ jobs:
java-version: 17
run: |
bazel test --flaky_test_attempts 3 //java/test/org/openqa/selenium/chrome:ChromeDriverFunctionalTest-remote

nullaway-checks:
name: NullAway Checks
uses: ./.github/workflows/bazel.yml
with:
name: NullAway Checks
java-version: 17
run: bazel build //java/... --//java:nullaway_level=ERROR
1 change: 1 addition & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ maven.install(
"com.google.googlejavaformat:google-java-format:jar:1.23.0",
"com.graphql-java:graphql-java:20.2",
"com.graphql-java:java-dataloader:3.2.0",
"com.uber.nullaway:nullaway:0.11.3",
"dev.failsafe:failsafe:3.3.2",
"io.grpc:grpc-context:1.66.0",
"io.lettuce:lettuce-core:6.4.0.RELEASE",
Expand Down
35 changes: 35 additions & 0 deletions java/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
load("@bazel_skylib//rules:common_settings.bzl", "string_flag")
load("@contrib_rules_jvm//java:defs.bzl", "spotbugs_config")
load(":defs.bzl", "artifact")

Expand All @@ -21,6 +22,16 @@ java_plugin(
],
)

java_plugin(
name = "nullaway",
visibility = [
"//java:__subpackages__",
],
deps = [
artifact("com.uber.nullaway:nullaway"),
],
)

java_library(
name = "auto-service",
exported_plugins = [
Expand All @@ -43,3 +54,27 @@ spotbugs_config(
"//visibility:public",
],
)

string_flag(
name = "nullaway_level",
build_setting_default = "NONE",
values = [
"NONE",
"WARN",
"ERROR",
],
)

config_setting(
name = "use_nullaway_level_warn",
flag_values = {
":nullaway_level": "WARN",
},
)

config_setting(
name = "use_nullaway_level_error",
flag_values = {
":nullaway_level": "ERROR",
},
)
118 changes: 116 additions & 2 deletions java/maven_install.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"__AUTOGENERATED_FILE_DO_NOT_MODIFY_THIS_FILE_MANUALLY": "THERE_IS_NO_DATA_ONLY_ZUUL",
"__INPUT_ARTIFACTS_HASH": -809854593,
"__RESOLVED_ARTIFACTS_HASH": -1445024694,
"__INPUT_ARTIFACTS_HASH": 1792396849,
"__RESOLVED_ARTIFACTS_HASH": 1206533551,
"conflict_resolution": {
"com.google.code.gson:gson:2.8.9": "com.google.code.gson:gson:2.11.0",
"com.google.errorprone:error_prone_annotations:2.3.2": "com.google.errorprone:error_prone_annotations:2.28.0",
Expand Down Expand Up @@ -206,6 +206,13 @@
},
"version": "3.2.0"
},
"com.uber.nullaway:nullaway": {
"shasums": {
"jar": "daac4247daf18024c236a4f9bae99a145bca044037ca8d805e00dc1b76270b31",
"sources": "e76ad83c1796291c5c2c9cb6c35bd06eebe51735319f06b27992cea5edd50999"
},
"version": "0.11.3"
},
"commons-codec:commons-codec": {
"shasums": {
"jar": "b3e9f6d63a790109bf0d056611fbed1cf69055826defeb9894a71369d246ed63",
Expand Down Expand Up @@ -619,6 +626,13 @@
},
"version": "3.43.0"
},
"org.checkerframework:dataflow-nullaway": {
"shasums": {
"jar": "5575726419747f9681cdefae507013dbdfefbd0a28dff553be46cdd814756e49",
"sources": "49e6aed68eb1b29d850ea5e7221fed0eda56eb363935bdeee5c7b8488f35375a"
},
"version": "3.43.0"
},
"org.dom4j:dom4j": {
"shasums": {
"jar": "235a9167a8a199be04b5326d92927ca0adeb90d11f69fe2e821b34ce8433b591",
Expand Down Expand Up @@ -906,6 +920,11 @@
"com.graphql-java:java-dataloader": [
"org.slf4j:slf4j-api"
],
"com.uber.nullaway:nullaway": [
"com.google.guava:guava",
"org.checkerframework:dataflow-nullaway",
"org.jspecify:jspecify"
],
"io.grpc:grpc-context": [
"io.grpc:grpc-api"
],
Expand Down Expand Up @@ -1487,6 +1506,23 @@
"org.dataloader.stats",
"org.dataloader.stats.context"
],
"com.uber.nullaway:nullaway": [
"com.uber.nullaway",
"com.uber.nullaway.annotations",
"com.uber.nullaway.dataflow",
"com.uber.nullaway.dataflow.cfg",
"com.uber.nullaway.fixserialization",
"com.uber.nullaway.fixserialization.adapters",
"com.uber.nullaway.fixserialization.location",
"com.uber.nullaway.fixserialization.out",
"com.uber.nullaway.generics",
"com.uber.nullaway.handlers",
"com.uber.nullaway.handlers.contract",
"com.uber.nullaway.handlers.contract.fieldcontract",
"com.uber.nullaway.handlers.stream",
"com.uber.nullaway.handlers.temporary",
"com.uber.nullaway.jarinfer"
],
"commons-codec:commons-codec": [
"org.apache.commons.codec",
"org.apache.commons.codec.binary",
Expand Down Expand Up @@ -2551,6 +2587,80 @@
"org.checkerframework.dataflow.qual",
"org.checkerframework.framework.qual"
],
"org.checkerframework:dataflow-nullaway": [
"javax.annotation",
"javax.annotation.concurrent",
"javax.annotation.meta",
"org.checkerframework.dataflow.qual",
"org.checkerframework.nullaway.checker.builder.qual",
"org.checkerframework.nullaway.checker.calledmethods.qual",
"org.checkerframework.nullaway.checker.compilermsgs.qual",
"org.checkerframework.nullaway.checker.fenum.qual",
"org.checkerframework.nullaway.checker.formatter.qual",
"org.checkerframework.nullaway.checker.guieffect.qual",
"org.checkerframework.nullaway.checker.i18n.qual",
"org.checkerframework.nullaway.checker.i18nformatter.qual",
"org.checkerframework.nullaway.checker.index.qual",
"org.checkerframework.nullaway.checker.initialization.qual",
"org.checkerframework.nullaway.checker.interning.qual",
"org.checkerframework.nullaway.checker.lock.qual",
"org.checkerframework.nullaway.checker.mustcall.qual",
"org.checkerframework.nullaway.checker.nullness.qual",
"org.checkerframework.nullaway.checker.optional.qual",
"org.checkerframework.nullaway.checker.propkey.qual",
"org.checkerframework.nullaway.checker.regex.qual",
"org.checkerframework.nullaway.checker.signature.qual",
"org.checkerframework.nullaway.checker.signedness.qual",
"org.checkerframework.nullaway.checker.tainting.qual",
"org.checkerframework.nullaway.checker.units.qual",
"org.checkerframework.nullaway.com.google.common.annotations",
"org.checkerframework.nullaway.com.google.common.base",
"org.checkerframework.nullaway.com.google.common.base.internal",
"org.checkerframework.nullaway.com.google.common.cache",
"org.checkerframework.nullaway.com.google.common.collect",
"org.checkerframework.nullaway.com.google.common.escape",
"org.checkerframework.nullaway.com.google.common.eventbus",
"org.checkerframework.nullaway.com.google.common.graph",
"org.checkerframework.nullaway.com.google.common.hash",
"org.checkerframework.nullaway.com.google.common.html",
"org.checkerframework.nullaway.com.google.common.io",
"org.checkerframework.nullaway.com.google.common.math",
"org.checkerframework.nullaway.com.google.common.net",
"org.checkerframework.nullaway.com.google.common.primitives",
"org.checkerframework.nullaway.com.google.common.reflect",
"org.checkerframework.nullaway.com.google.common.util.concurrent",
"org.checkerframework.nullaway.com.google.common.util.concurrent.internal",
"org.checkerframework.nullaway.com.google.common.xml",
"org.checkerframework.nullaway.com.google.errorprone.annotations",
"org.checkerframework.nullaway.com.google.errorprone.annotations.concurrent",
"org.checkerframework.nullaway.com.google.j2objc.annotations",
"org.checkerframework.nullaway.com.google.thirdparty.publicsuffix",
"org.checkerframework.nullaway.common.aliasing.qual",
"org.checkerframework.nullaway.common.initializedfields.qual",
"org.checkerframework.nullaway.common.reflection.qual",
"org.checkerframework.nullaway.common.returnsreceiver.qual",
"org.checkerframework.nullaway.common.subtyping.qual",
"org.checkerframework.nullaway.common.util.count.report.qual",
"org.checkerframework.nullaway.common.value.qual",
"org.checkerframework.nullaway.dataflow.analysis",
"org.checkerframework.nullaway.dataflow.busyexpr",
"org.checkerframework.nullaway.dataflow.cfg",
"org.checkerframework.nullaway.dataflow.cfg.block",
"org.checkerframework.nullaway.dataflow.cfg.builder",
"org.checkerframework.nullaway.dataflow.cfg.node",
"org.checkerframework.nullaway.dataflow.cfg.playground",
"org.checkerframework.nullaway.dataflow.cfg.visualize",
"org.checkerframework.nullaway.dataflow.constantpropagation",
"org.checkerframework.nullaway.dataflow.expression",
"org.checkerframework.nullaway.dataflow.livevariable",
"org.checkerframework.nullaway.dataflow.reachingdef",
"org.checkerframework.nullaway.dataflow.util",
"org.checkerframework.nullaway.framework.qual",
"org.checkerframework.nullaway.javacutil",
"org.checkerframework.nullaway.javacutil.trees",
"org.checkerframework.nullaway.org.plumelib.reflection",
"org.checkerframework.nullaway.org.plumelib.util"
],
"org.dom4j:dom4j": [
"org.dom4j",
"org.dom4j.bean",
Expand Down Expand Up @@ -3022,6 +3132,8 @@
"com.graphql-java:graphql-java:jar:sources",
"com.graphql-java:java-dataloader",
"com.graphql-java:java-dataloader:jar:sources",
"com.uber.nullaway:nullaway",
"com.uber.nullaway:nullaway:jar:sources",
"commons-codec:commons-codec",
"commons-codec:commons-codec:jar:sources",
"commons-io:commons-io",
Expand Down Expand Up @@ -3140,6 +3252,8 @@
"org.bouncycastle:bcutil-jdk18on:jar:sources",
"org.checkerframework:checker-qual",
"org.checkerframework:checker-qual:jar:sources",
"org.checkerframework:dataflow-nullaway",
"org.checkerframework:dataflow-nullaway:jar:sources",
"org.dom4j:dom4j",
"org.dom4j:dom4j:jar:sources",
"org.eclipse.mylyn.github:org.eclipse.egit.github.core",
Expand Down
3 changes: 2 additions & 1 deletion java/private/export.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ load("@rules_jvm_external//private/rules:maven_bom_fragment.bzl", "maven_bom_fra
load("@rules_jvm_external//private/rules:maven_project_jar.bzl", "maven_project_jar")
load("@rules_jvm_external//private/rules:maven_publish.bzl", "maven_publish")
load("//java/private:module.bzl", "java_module")
load(":java_library.bzl", "java_library")

def java_export(
name,
Expand All @@ -24,7 +25,7 @@ def java_export(
lib_name = "%s-lib" % name

# Construct the java_library we'll export from here.
native.java_library(
java_library(
name = lib_name,
tags = tags,
exports = exports,
Expand Down
51 changes: 51 additions & 0 deletions java/private/java_library.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
load(
"@contrib_rules_jvm//java:defs.bzl",
_java_library = "java_library",
)

def java_library(
name,
deps = [],
srcs = [],
exports = [],
tags = [],
visibility = None,
javacopts = [],
plugins = [],
**kwargs):
# NullAway configuration
nullaway_plugins = select({
"//java:use_nullaway_level_warn": [
"//java:nullaway",
],
"//java:use_nullaway_level_error": [
"//java:nullaway",
],
"//conditions:default": [],
})
nullaway_javacopts = select({
"//java:use_nullaway_level_warn": [
"-Xep:NullAway:WARN",
"-XepOpt:NullAway:AnnotatedPackages=org.openqa.selenium",
"-XepOpt:NullAway:JSpecifyMode=true",
],
"//java:use_nullaway_level_error": [
"-Xep:NullAway:ERROR",
"-XepOpt:NullAway:AnnotatedPackages=org.openqa.selenium",
"-XepOpt:NullAway:JSpecifyMode=true",
],
"//conditions:default": [],
})

# global place for NullAway plugin use
_java_library(
name = name,
deps = deps,
srcs = srcs,
exports = exports,
tags = tags,
visibility = visibility,
plugins = plugins + nullaway_plugins,
javacopts = javacopts + nullaway_javacopts,
**kwargs
)
2 changes: 1 addition & 1 deletion java/private/library.bzl
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
load(
"@contrib_rules_jvm//java:defs.bzl",
_java_library = "java_library",
_java_test = "java_test",
)
load(":export.bzl", _java_export = "java_export")
load(":java_library.bzl", _java_library = "java_library")

java_export = _java_export
java_library = _java_library
Expand Down
Loading