Fix Broken Error Handling in CacheFile#acquire (#65342) (#65347)

If we fail to create the `FileChannelReference` (e.g. because the directory it should be created in
was deleted in a test) we have to remove the listener from the `listeners` set to not trip internal
consistency assertions.

Relates #65302 (does not fix it though, but reduces noise from failures by removing secondary
tripped assertions after the test fails)
This commit is contained in:
Armin Braun 2020-11-23 08:57:24 +01:00 committed by GitHub
parent 67b6317488
commit b0cea04f95
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -138,12 +138,12 @@ public class CacheFile {
try { try {
synchronized (listeners) { synchronized (listeners) {
ensureOpen(); ensureOpen();
final boolean added = listeners.add(listener); if (listeners.isEmpty()) {
assert added : "listener already exists " + listener;
if (listeners.size() == 1) {
assert channelRef == null; assert channelRef == null;
channelRef = new FileChannelReference(); channelRef = new FileChannelReference();
} }
final boolean added = listeners.add(listener);
assert added : "listener already exists " + listener;
} }
success = true; success = true;
} finally { } finally {