From 9f86d9a8cdfb35bd604e03e9c68be67944aaf928 Mon Sep 17 00:00:00 2001 From: Changcheng Xiao Date: Fri, 17 Feb 2017 11:45:19 +0100 Subject: [PATCH] Fix GWT UI AddFileBox to provide path suggestions continuously - How to reproduce the bug? In ChangeScreen, click 'Edit', then 'Add...'. Type in some text, you will get some path suggestions. Delete all the text you've typed in. There will be no suggestion any more until the page is reloaded. - Why does this happen? The UI will continue create new query when the text box is focused and the 'query' is null in RemoteSuggestOracle. When the text box is cleared, it will result in a NullPointerException in RESTApi.addParameter(String, String) when it calls URL.encodeQueryString as the request.getQuery() is null. Once this exception happens, onSuggestionReady will not be called and 'query' field in RemoteSuggestOracle will not be reset to null. That's why the UI will not try new Request until the page is reloaded. This problem may be related to GWT 2.8 upgrade. It started behaving differently after the upgrade. - Solution Don't add the query to the request if it is null. This solution will not affect ReviewerSuggestOracle as commit [1], which was revert by commit [2]. [1] https://gerrit-review.googlesource.com/#/c/97611/ [2] https://gerrit-review.googlesource.com/#/c/97731/ Bug: Issue 5365 Change-Id: Ie64bdf6384c022ec2be943ed9d67b1a1f3cee170 --- .../google/gerrit/client/change/PathSuggestOracle.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/gerrit-gwtui/src/main/java/com/google/gerrit/client/change/PathSuggestOracle.java b/gerrit-gwtui/src/main/java/com/google/gerrit/client/change/PathSuggestOracle.java index 8e51ea7b3a..3b96a12776 100644 --- a/gerrit-gwtui/src/main/java/com/google/gerrit/client/change/PathSuggestOracle.java +++ b/gerrit-gwtui/src/main/java/com/google/gerrit/client/change/PathSuggestOracle.java @@ -17,6 +17,7 @@ package com.google.gerrit.client.change; import com.google.gerrit.client.changes.ChangeApi; import com.google.gerrit.client.info.ChangeInfo.RevisionInfo; import com.google.gerrit.client.rpc.Natives; +import com.google.gerrit.client.rpc.RestApi; import com.google.gerrit.reviewdb.client.Change; import com.google.gwt.core.client.JsArrayString; import com.google.gwt.user.client.rpc.AsyncCallback; @@ -37,10 +38,11 @@ class PathSuggestOracle extends HighlightSuggestOracle { @Override protected void onRequestSuggestions(final Request req, final Callback cb) { - ChangeApi.revision(changeId.get(), revision.name()) - .view("files") - .addParameter("q", req.getQuery()) - .background() + RestApi api = ChangeApi.revision(changeId.get(), revision.name()).view("files"); + if (req.getQuery() != null) { + api.addParameter("q", req.getQuery() == null ? "" : req.getQuery()); + } + api.background() .get( new AsyncCallback() { @Override