summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEdwin Kempin <ekempin@google.com>2016-06-23 12:00:00 +0200
committerEdwin Kempin <ekempin@google.com>2016-06-23 10:54:25 +0000
commitc8f311b9f978fea8dfca1bb5755f66c369e01a94 (patch)
tree257f0bd58ead73812cd3619349e3a1421f10e97a
parent09034c03f1f6500c9a88933286fc12f4bb744771 (diff)
RemoteSuggestOracle: Fix JavaScript TypeError
If Gerrit is configured to show suggestions only after typing n characters (see gerrit config parameter suggest.from) typing characters in the suggest box causes a JavaScript TypeError while n characters are not reached yet: Caused by: Class$S146: (TypeError) : Cannot read property 'start_5' of undefined at Unknown.onSuggestionsReady_2(gerrit_ui-0.js) at Unknown.onSuggestionsReady_4(gerrit_ui-0.js) at Unknown.onRequestSuggestions_0(gerrit_ui-0.js) at Unknown.requestSuggestions(gerrit_ui-0.js) at Unknown.start_5(gerrit_ui-0.js) at Unknown.requestSuggestions_0(gerrit_ui-0.js) at Unknown.showSuggestions_0(gerrit_ui-0.js) at Unknown.refreshSuggestions(gerrit_ui-0.js) at Unknown.onKeyUp_5(gerrit_ui-0.js) ... This is because the query is started before assigning it to the 'query' variable, which the callback expects to be non-null. If n characters are not typed yet, there is no remote call and the callback is immediately invoked with empty results as soon as the query is started. This means the 'query' variable is still not set and this results in the TypeError as shown above. If a remote call was done to get the suggestions, there was no problem, because then the callback was always invoked after the 'query' variable has been assigned. Change-Id: Ia41102a8cc87237b9e7ed728259daf2b6b86996c Signed-off-by: Edwin Kempin <ekempin@google.com>
-rw-r--r--gerrit-gwtui-common/src/main/java/com/google/gerrit/client/ui/RemoteSuggestOracle.java4
1 files changed, 3 insertions, 1 deletions
diff --git a/gerrit-gwtui-common/src/main/java/com/google/gerrit/client/ui/RemoteSuggestOracle.java b/gerrit-gwtui-common/src/main/java/com/google/gerrit/client/ui/RemoteSuggestOracle.java
index 9554ac5f25..cf7e1d8e66 100644
--- a/gerrit-gwtui-common/src/main/java/com/google/gerrit/client/ui/RemoteSuggestOracle.java
+++ b/gerrit-gwtui-common/src/main/java/com/google/gerrit/client/ui/RemoteSuggestOracle.java
@@ -44,9 +44,11 @@ public class RemoteSuggestOracle extends SuggestOracle {
public void requestSuggestions(Request req, Callback cb) {
Query q = new Query(req, cb);
if (query == null) {
+ query = q;
q.start();
+ } else {
+ query = q;
}
- query = q;
}
@Override