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:
		@@ -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) {
 | 
			
		||||
      try {
 | 
			
		||||
        l.onGitReferenceUpdated(event);
 | 
			
		||||
      } catch (RuntimeException e) {
 | 
			
		||||
        log.warn("Failure in GitReferenceUpdatedListener", e);
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -118,7 +118,11 @@ public class PerformCreateProject {
 | 
			
		||||
          }
 | 
			
		||||
        };
 | 
			
		||||
        for (NewProjectCreatedListener l : createdListener) {
 | 
			
		||||
          try {
 | 
			
		||||
            l.onNewProjectCreated(event);
 | 
			
		||||
          } catch (RuntimeException e) {
 | 
			
		||||
            log.warn("Failure in NewProjectCreatedListener", e);
 | 
			
		||||
          }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        final RefUpdate u = repo.updateRef(Constants.HEAD);
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user