summaryrefslogtreecommitdiff
path: root/annotations/generate_annotated_java_files.py
diff options
context:
space:
mode:
authorPete Gillin <peteg@google.com>2018-11-13 17:19:13 +0000
committerPete Gillin <peteg@google.com>2018-11-13 17:42:24 +0000
commit30ba19d330bd49d4ad38064d6f454cdaa5e6b569 (patch)
treedf3c3f4bdd70ddf119eacecc9452c084a195719d /annotations/generate_annotated_java_files.py
parentd22837f7a8108fc12e0d417d668e4b0ca4b49ef4 (diff)
Add nullability annotations to JSONObject.
Since names cannot be null, get(null) is guaranteed to throw, so the parameter to get() is declared @NonNull. Since opt(null) is guaranteed to return null, the parameter to opt() is declared @Nullable. The type-specific get* and opt* methods follow that pattern. The overload of optString which takes a fallback actually does accept a null fallback, and may return null if the fallback is null but not otherwise. The most helpful thing seems to be to declare the fallback parameter and the return type as both @NonNull since that is presumably the common usage. The toString() implementation does return null if a JSONException was thrown during the processing. It seems like this shouldn't be possible for a validly constituted instance, and forcing users to do null checks on the returned String seems like it would not be helpful, so the return value is annotated as @NonNull. (JSONStringer.toString also returns null if its out field is zero length, but the preceding call to writeTo(JSONStringer) will ensure that at least the { and } will have been appended, so that can't happen.) Test: make core-libart Bug: 64930165 Change-Id: Ie5a8c6c212b86035a1daeff14b784a5ca9e0f626
Diffstat (limited to 'annotations/generate_annotated_java_files.py')
0 files changed, 0 insertions, 0 deletions