diff options
author | 2019-03-06 17:21:41 +0100 | |
---|---|---|
committer | 2019-03-06 17:21:41 +0100 | |
commit | 9b7ad51bc16ba07cc401103cf8723a05ac260132 (patch) | |
tree | 9f75c2677413bd2dd065c402a4ddd1ca945ac264 /tools/apilint | |
parent | 26968d81f8291f1dd4a0f8a7e962c60d62b9ef61 (diff) |
apilint: suppress certain nullability lints
Fixes: 126699235
Test: python tools/apilint/apilint.py api/current.txt
Change-Id: Ifdce2d8c6da7c8fbfc9288d8d0eed4cfad49ebe1
Diffstat (limited to 'tools/apilint')
-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 a91fbe76be8d..3197962ff2c2 100644 --- a/tools/apilint/apilint.py +++ b/tools/apilint/apilint.py @@ -1974,7 +1974,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") @@ -1983,8 +1985,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") |