diff options
author | Adrian Roos <roosa@google.com> | 2019-10-10 13:41:16 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2019-10-10 13:41:16 +0000 |
commit | ab911951aed8ce17a6c623e8acc4101b12553de1 (patch) | |
tree | 1b0c4df5f00645061d602fdc74f1074aa354ae95 | |
parent | 90a84e26bd3648e9565c8d10f43788e8571c7d7d (diff) | |
parent | 9b7ad51bc16ba07cc401103cf8723a05ac260132 (diff) | |
download | base-ab911951aed8ce17a6c623e8acc4101b12553de1.tar.gz |
Merge "apilint: suppress certain nullability lints"
-rw-r--r-- | tools/apilint/apilint.py | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/tools/apilint/apilint.py b/tools/apilint/apilint.py index 9e42c044e209..912c1ad377c1 100644 --- a/tools/apilint/apilint.py +++ b/tools/apilint/apilint.py @@ -1976,7 +1976,9 @@ def verify_nullability(clazz): """Catches missing nullability annotations""" for f in clazz.fields: - if f.value is not None and 'static' in f.split and 'final' in f.split: + if "enum_constant" in f.split: + continue # Enum constants are never null + if f.value is not None and 'final' in f.split: continue # Nullability of constants can be inferred. if f.typ not in PRIMITIVES and not has_nullability(f.annotations): error(clazz, f, "M12", "Field must be marked either @NonNull or @Nullable") @@ -1985,8 +1987,12 @@ def verify_nullability(clazz): verify_nullability_args(clazz, c) for m in clazz.methods: - if m.name == "writeToParcel" or m.name == "onReceive": - continue # Parcelable.writeToParcel() and BroadcastReceiver.onReceive() are not yet annotated + if m.name == "writeToParcel" or m.name == "onReceive" or m.name == "onBind": + continue # Parcelable.writeToParcel(), BroadcastReceiver.onReceive(), and Service.onBind() are not yet annotated + + if (m.name == "equals" and m.args == ["java.lang.Object"] or + m.name == "toString" and m.args == []): + continue # Nullability of equals and toString is implicit. if m.typ not in PRIMITIVES and not has_nullability(m.annotations): error(clazz, m, "M12", "Return value must be marked either @NonNull or @Nullable") |