Upgrade gitiles-servlet and blame-cache to 0.2-11

If a file doesn't exist in a commit we expect the GetBlame REST endpoint
to return an empty BlameInfo list. This works well unless the file
existed once and had been deleted. E.g. if there is a change that
recreates a file and the user clicks on 'SHOW BLAME' on the diff screen
the request to get the blame info for the base commit fails with 500
Internal Server Error. For example the newly added
GetBlameIT#forRecreatedFileFromBase test was failing like this:

com.google.common.util.concurrent.UncheckedExecutionException: java.lang.NullPointerException
	at com.google.common.cache.LocalCache$Segment.get(LocalCache.java:2051)
	at com.google.common.cache.LocalCache.get(LocalCache.java:3953)
	at com.google.common.cache.LocalCache$LocalManualCache.get(LocalCache.java:4873)
	at com.google.gitiles.blame.cache.BlameCacheImpl.get(BlameCacheImpl.java:114)
	at com.google.gerrit.server.restapi.change.GetBlame.blame(GetBlame.java:145)
	at com.google.gerrit.server.restapi.change.GetBlame.apply(GetBlame.java:118)
	at com.google.gerrit.server.api.changes.FileApiImpl$2.get(FileApiImpl.java:149)
	at com.google.gerrit.acceptance.api.revision.GetBlameIT.forRecreatedFileFromBase(GetBlameIT.java:123)
        ...
Caused by: java.lang.NullPointerException
	at com.google.gitiles.blame.cache.BlameCacheImpl.loadRegions(BlameCacheImpl.java:156)
	at com.google.gitiles.blame.cache.BlameCacheImpl.loadBlame(BlameCacheImpl.java:139)
	at com.google.gitiles.blame.cache.BlameCacheImpl.lambda$newLoader$1(BlameCacheImpl.java:103)
	at com.google.common.cache.LocalCache$LocalManualCache$1.load(LocalCache.java:4878)
	at com.google.common.cache.LocalCache$LoadingValueReference.loadFuture(LocalCache.java:3529)
	at com.google.common.cache.LocalCache$Segment.loadSync(LocalCache.java:2278)
	at com.google.common.cache.LocalCache$Segment.lockedGetOrLoad(LocalCache.java:2155)
	at com.google.common.cache.LocalCache$Segment.get(LocalCache.java:2045)
	... 48 more

The updated version of blame-cache includes a fix for this.

Likely we want to have more tests for the GetBlame REST endpoint, but
adding those is outside the scope of this change.

Bug: Issue 5082
Change-Id: I11b529b48495e563148040dfb7f56379de13d128
Signed-off-by: Edwin Kempin <ekempin@google.com>
This commit is contained in:
Edwin Kempin
2019-11-14 15:08:20 +01:00
committed by David Pursehouse
parent beba231e4e
commit 59e3f0b6fa
5 changed files with 185 additions and 3 deletions

View File

@@ -17,16 +17,20 @@ package com.google.gerrit.server.api.changes;
import static com.google.gerrit.server.api.ApiUtil.asRestApiException;
import com.google.gerrit.extensions.api.changes.FileApi;
import com.google.gerrit.extensions.common.BlameInfo;
import com.google.gerrit.extensions.common.DiffInfo;
import com.google.gerrit.extensions.common.Input;
import com.google.gerrit.extensions.restapi.BinaryResult;
import com.google.gerrit.extensions.restapi.RestApiException;
import com.google.gerrit.server.change.FileResource;
import com.google.gerrit.server.restapi.change.GetBlame;
import com.google.gerrit.server.restapi.change.GetContent;
import com.google.gerrit.server.restapi.change.GetDiff;
import com.google.gerrit.server.restapi.change.Reviewed;
import com.google.inject.Inject;
import com.google.inject.Provider;
import com.google.inject.assistedinject.Assisted;
import java.util.List;
class FileApiImpl implements FileApi {
interface Factory {
@@ -34,6 +38,7 @@ class FileApiImpl implements FileApi {
}
private final GetContent getContent;
private final Provider<GetBlame> getBlame;
private final GetDiff getDiff;
private final Reviewed.PutReviewed putReviewed;
private final Reviewed.DeleteReviewed deleteReviewed;
@@ -42,11 +47,13 @@ class FileApiImpl implements FileApi {
@Inject
FileApiImpl(
GetContent getContent,
Provider<GetBlame> getBlame,
GetDiff getDiff,
Reviewed.PutReviewed putReviewed,
Reviewed.DeleteReviewed deleteReviewed,
@Assisted FileResource file) {
this.getContent = getContent;
this.getBlame = getBlame;
this.getDiff = getDiff;
this.putReviewed = putReviewed;
this.deleteReviewed = deleteReviewed;
@@ -132,4 +139,18 @@ class FileApiImpl implements FileApi {
throw asRestApiException("Cannot retrieve diff", e);
}
}
@Override
public BlameRequest blameRequest() throws RestApiException {
return new BlameRequest() {
@Override
public List<BlameInfo> get() throws RestApiException {
try {
return getBlame.get().setBase(isForBase()).apply(file).value();
} catch (Exception e) {
throw asRestApiException("Cannot retrieve blame", e);
}
}
};
}
}