Fix NPE in AsyncFragmentLoader for 'already loaded' fragments.
AsyncFragmentLoader makes the assumption that fragment loads are always
initiated by runAsync() call, however Inbox uses an 'already downloaded'
download strategy whereby a server-side linker concatenates needed modules to
be preloaded onto the output. This means the onLoad() call is invoked without
a corresponding startFragment call.
This mostly works, except for the leftovers fragment, wherein a queue variable
is lazily initialized and deferenced early.
Change-Id: Id057ed61c50de12eeea8d0ac4a02c3dcc826103e
diff --git a/user/src/com/google/gwt/core/client/impl/AsyncFragmentLoader.java b/user/src/com/google/gwt/core/client/impl/AsyncFragmentLoader.java
index 0011be6..8c7528b 100644
--- a/user/src/com/google/gwt/core/client/impl/AsyncFragmentLoader.java
+++ b/user/src/com/google/gwt/core/client/impl/AsyncFragmentLoader.java
@@ -424,7 +424,12 @@
pendingDownloadErrorHandlers[fragment] = null;
}
- if (isInitial(fragment)) {
+ /**
+ * It is possible for a fragment to be preloaded by the linker or server before runAsync() has
+ * requested it, in this case the leftovers fragment will be have it's onLoad() called before
+ * remainingInitialFragments has been initialized.
+ */
+ if (isInitial(fragment) && remainingInitialFragments != null) {
assert (fragment == remainingInitialFragments.peek());
remainingInitialFragments.remove();
}