Skip to content

Commit

Permalink
Fix MockExecutor::toString race
Browse files Browse the repository at this point in the history
  • Loading branch information
mizosoft committed Dec 20, 2024
1 parent 957c15d commit bda4eb3
Showing 1 changed file with 17 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

package com.github.mizosoft.methanol.testing;

import com.google.errorprone.annotations.concurrent.GuardedBy;
import java.util.ArrayDeque;
import java.util.Queue;
import java.util.concurrent.Executor;
Expand All @@ -37,7 +38,10 @@ public class MockExecutor implements Executor {
private final Lock lock = new ReentrantLock();
private final Condition notEmpty = lock.newCondition();

@GuardedBy("lock")
private boolean reject;

@GuardedBy("lock")
private boolean executeDirectly;

public MockExecutor() {}
Expand Down Expand Up @@ -142,13 +146,18 @@ public boolean awaitNext(long timeout, TimeUnit unit) {

@Override
public String toString() {
return super.toString()
+ "{tasks="
+ tasks
+ ", reject="
+ reject
+ ", executeDirectly="
+ executeDirectly
+ "}";
lock.lock();
try {
return super.toString()
+ "{tasks="
+ tasks
+ ", reject="
+ reject
+ ", executeDirectly="
+ executeDirectly
+ "}";
} finally {
lock.unlock();
}
}
}

0 comments on commit bda4eb3

Please sign in to comment.