Protect Gerrit against bad plugins

If a plugin implements a listener to react on Gerrit events and then
fails with a RuntimeException in the callback this shouldn't effect
Gerrit. Gerrit should only log this as a warning but the operation
in Gerrit that triggered the event should not fail.

Change-Id: I416915742cbf2f638e8032b63f76c171ff735369
Signed-off-by: Edwin Kempin <edwin.kempin@sap.com>
This commit is contained in:
Edwin Kempin
2013-09-12 13:59:35 +02:00
parent 1f1e0cacaa
commit 709f2dbd7a
2 changed files with 15 additions and 2 deletions

View File

@@ -22,11 +22,16 @@ import com.google.inject.Inject;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.RefUpdate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Collections;
import java.util.List;
public class GitReferenceUpdated {
private static final Logger log = LoggerFactory
.getLogger(GitReferenceUpdated.class);
public static final GitReferenceUpdated DISABLED = new GitReferenceUpdated(
Collections.<GitReferenceUpdatedListener> emptyList());
@@ -52,7 +57,11 @@ public class GitReferenceUpdated {
ObjectId n = newObjectId != null ? newObjectId : ObjectId.zeroId();
Event event = new Event(project, ref, o.name(), n.name());
for (GitReferenceUpdatedListener l : listeners) {
l.onGitReferenceUpdated(event);
try {
l.onGitReferenceUpdated(event);
} catch (RuntimeException e) {
log.warn("Failure in GitReferenceUpdatedListener", e);
}
}
}

View File

@@ -118,7 +118,11 @@ public class PerformCreateProject {
}
};
for (NewProjectCreatedListener l : createdListener) {
l.onNewProjectCreated(event);
try {
l.onNewProjectCreated(event);
} catch (RuntimeException e) {
log.warn("Failure in NewProjectCreatedListener", e);
}
}
final RefUpdate u = repo.updateRef(Constants.HEAD);