Fixed
Status Update
Comments
il...@google.com <il...@google.com>
ap...@google.com <ap...@google.com> #2
Project: platform/frameworks/support
Branch: androidx-master-dev
commit 004b5cf28d4155f0116b43eb8141003bcc1b8595
Author: Ian Lake <ilake@google.com>
Date: Wed Aug 15 15:02:14 2018
Make NavController.getGraph() NonNull
getGraph() should only be called after a call to
setGraph() and can therefore be NonNull. It
now throws an IllegalStateException if called when
mGraph is null.
Test: updated NavControllerTests
BUG: 112243286
Change-Id: I28860943d33a5d5f5d50a0201f77829fa4c56d57
M navigation/runtime/src/androidTest/java/androidx/navigation/NavControllerTest.java
M navigation/runtime/src/main/java/androidx/navigation/NavController.java
https://android-review.googlesource.com/732866
https://goto.google.com/android-sha1/004b5cf28d4155f0116b43eb8141003bcc1b8595
Branch: androidx-master-dev
commit 004b5cf28d4155f0116b43eb8141003bcc1b8595
Author: Ian Lake <ilake@google.com>
Date: Wed Aug 15 15:02:14 2018
Make NavController.getGraph() NonNull
getGraph() should only be called after a call to
setGraph() and can therefore be NonNull. It
now throws an IllegalStateException if called when
mGraph is null.
Test: updated NavControllerTests
BUG: 112243286
Change-Id: I28860943d33a5d5f5d50a0201f77829fa4c56d57
M navigation/runtime/src/androidTest/java/androidx/navigation/NavControllerTest.java
M navigation/runtime/src/main/java/androidx/navigation/NavController.java
il...@google.com <il...@google.com> #3
Given that:
1) Most NavController usage is via a NavHostFragment with app:navGraph set, ensuring that the graph is already set
2) Programmatically constructed graphs will result in developers always calling setGraph before using the NavController
Calling getGraph() before a call to setGraph() is almost always a developer error that needs to be corrected, so throwing an IllegalStateException is acceptable.
Please file a new bug if you have a specific use case that would benefit from a maybeGetGraph() / hasGraph() type of API.
1) Most NavController usage is via a NavHostFragment with app:navGraph set, ensuring that the graph is already set
2) Programmatically constructed graphs will result in developers always calling setGraph before using the NavController
Calling getGraph() before a call to setGraph() is almost always a developer error that needs to be corrected, so throwing an IllegalStateException is acceptable.
Please file a new bug if you have a specific use case that would benefit from a maybeGetGraph() / hasGraph() type of API.
Description
NavController.getGraph is marked as @Nullable, though it seems that in default case it is @NonNull.
As Jake suggested, we probably should reshape API expose two versions Null/NonNull