Remove TODO(b/347672184) and explain why @Nullable is not used
After a conversation with the API council it was decided that the
benefits of marking the `findViewById(int)` methods `@Nullable` is
greatly outweighed by the cost.
Bug: 347672184
Test: N/A
Change-Id: I79b299e3988f1ed3bf25e2528d8450291f738a1e
diff --git a/core/java/android/app/Activity.java b/core/java/android/app/Activity.java
index ee82b3f..76e761d 100644
--- a/core/java/android/app/Activity.java
+++ b/core/java/android/app/Activity.java
@@ -3678,7 +3678,9 @@
* @see View#findViewById(int)
* @see Activity#requireViewById(int)
*/
- /* TODO(b/347672184): Re-add @Nullable */
+ // Strictly speaking this should be marked as @Nullable but the nullability of the return value
+ // is deliberately left unspecified as idiomatically correct code can make assumptions either
+ // way based on local context, e.g. layout specification.
public <T extends View> T findViewById(@IdRes int id) {
return getWindow().findViewById(id);
}
diff --git a/core/java/android/app/Dialog.java b/core/java/android/app/Dialog.java
index 160d00c..d73d536 100644
--- a/core/java/android/app/Dialog.java
+++ b/core/java/android/app/Dialog.java
@@ -565,7 +565,9 @@
* @see View#findViewById(int)
* @see Dialog#requireViewById(int)
*/
- /* TODO(b/347672184): Re-add @Nullable */
+ // Strictly speaking this should be marked as @Nullable but the nullability of the return value
+ // is deliberately left unspecified as idiomatically correct code can make assumptions either
+ // way based on local context, e.g. layout specification.
public <T extends View> T findViewById(@IdRes int id) {
return mWindow.findViewById(id);
}
diff --git a/core/java/android/service/dreams/DreamService.java b/core/java/android/service/dreams/DreamService.java
index 327ebd0..c9c2dcc 100644
--- a/core/java/android/service/dreams/DreamService.java
+++ b/core/java/android/service/dreams/DreamService.java
@@ -536,7 +536,9 @@
* @see View#findViewById(int)
* @see DreamService#requireViewById(int)
*/
- /* TODO(b/347672184): Re-add @Nullable */
+ // Strictly speaking this should be marked as @Nullable but the nullability of the return value
+ // is deliberately left unspecified as idiomatically correct code can make assumptions either
+ // way based on local context, e.g. layout specification.
public <T extends View> T findViewById(@IdRes int id) {
return getWindow().findViewById(id);
}
diff --git a/core/java/android/view/View.java b/core/java/android/view/View.java
index ba6d5df..9aa723a 100644
--- a/core/java/android/view/View.java
+++ b/core/java/android/view/View.java
@@ -27294,7 +27294,9 @@
* @return a view with given ID if found, or {@code null} otherwise
* @see View#requireViewById(int)
*/
- /* TODO(b/347672184): Re-add @Nullable */
+ // Strictly speaking this should be marked as @Nullable but the nullability of the return value
+ // is deliberately left unspecified as idiomatically correct code can make assumptions either
+ // way based on local context, e.g. layout specification.
public final <T extends View> T findViewById(@IdRes int id) {
if (id == NO_ID) {
return null;
diff --git a/core/java/android/view/Window.java b/core/java/android/view/Window.java
index bfdcd59..50cf5a5f 100644
--- a/core/java/android/view/Window.java
+++ b/core/java/android/view/Window.java
@@ -1712,7 +1712,9 @@
* @see View#findViewById(int)
* @see Window#requireViewById(int)
*/
- /* TODO(b/347672184): Re-add @Nullable */
+ // Strictly speaking this should be marked as @Nullable but the nullability of the return value
+ // is deliberately left unspecified as idiomatically correct code can make assumptions either
+ // way based on local context, e.g. layout specification.
public <T extends View> T findViewById(@IdRes int id) {
return getDecorView().findViewById(id);
}