Assert RequestCleanup ran only once
Prevent the RequestCleanup.run() to be called more than once. Helps preventing bugs in the request context cleanup process and allow making changes to the Git/HTTP and Git/SSH protocols validating the correct request context management. Change-Id: I432d36f591ee9015856ac18ad27e98dcdca8e465
This commit is contained in:
		@@ -31,9 +31,7 @@ public class RequestCleanup implements Runnable {
 | 
			
		||||
  /** Register a task to be completed after the request ends. */
 | 
			
		||||
  public void add(Runnable task) {
 | 
			
		||||
    synchronized (cleanup) {
 | 
			
		||||
      if (ran) {
 | 
			
		||||
        throw new IllegalStateException("Request has already been cleaned up");
 | 
			
		||||
      }
 | 
			
		||||
      assertNotRan();
 | 
			
		||||
      cleanup.add(task);
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
@@ -41,6 +39,7 @@ public class RequestCleanup implements Runnable {
 | 
			
		||||
  @Override
 | 
			
		||||
  public void run() {
 | 
			
		||||
    synchronized (cleanup) {
 | 
			
		||||
      assertNotRan();
 | 
			
		||||
      ran = true;
 | 
			
		||||
      for (Iterator<Runnable> i = cleanup.iterator(); i.hasNext(); ) {
 | 
			
		||||
        try {
 | 
			
		||||
@@ -52,4 +51,10 @@ public class RequestCleanup implements Runnable {
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  private void assertNotRan() {
 | 
			
		||||
    if (ran) {
 | 
			
		||||
      throw new IllegalStateException("Request has already been cleaned up");
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user