summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLuca Milanesio <luca.milanesio@gmail.com>2019-12-13 20:21:23 +0000
committerLuca Milanesio <luca.milanesio@gmail.com>2019-12-13 22:50:27 +0000
commita89aefab270f751b25551a3aa2678b8b570901d7 (patch)
tree559e2ca874c8c78766274bef702a81bfad6d6718
parentd2b12082143926e4feb362c8723602d6ef39e2c3 (diff)
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
-rw-r--r--java/com/google/gerrit/server/RequestCleanup.java11
1 files changed, 8 insertions, 3 deletions
diff --git a/java/com/google/gerrit/server/RequestCleanup.java b/java/com/google/gerrit/server/RequestCleanup.java
index 7ed9287c80..f405c57147 100644
--- a/java/com/google/gerrit/server/RequestCleanup.java
+++ b/java/com/google/gerrit/server/RequestCleanup.java
@@ -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");
+ }
+ }
}