8336339: (se) SelectionKey.interestOps(int) should not throw ClosedSelectorException

Reviewed-by: jpai, bpb
This commit is contained in:
Alan Bateman 2024-07-23 05:13:49 +00:00
parent 22914e0774
commit 9f03f68755
8 changed files with 136 additions and 34 deletions

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2000, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2000, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -188,11 +188,11 @@ public abstract class SelectorImpl
// Deregister channels
Iterator<SelectionKey> i = keys.iterator();
while (i.hasNext()) {
SelectionKeyImpl ski = (SelectionKeyImpl)i.next();
SelectionKeyImpl ski = (SelectionKeyImpl) i.next();
deregister(ski);
SelectableChannel selch = ski.channel();
if (!selch.isOpen() && !selch.isRegistered())
((SelChImpl)selch).kill();
((SelChImpl) selch).kill();
selectedKeys.remove(ski);
i.remove();
}
@ -221,13 +221,14 @@ public abstract class SelectorImpl
keys.add(k);
try {
k.interestOps(ops);
} catch (ClosedSelectorException e) {
} catch (CancelledKeyException e) {
// key observed and cancelled. Okay to return a cancelled key.
}
if (!isOpen()) {
assert ch.keyFor(this) == null;
keys.remove(k);
k.cancel();
throw e;
} catch (CancelledKeyException e) {
// key observed and cancelled. Okay to return a cancelled key.
throw new ClosedSelectorException();
}
return k;
}
@ -277,7 +278,7 @@ public abstract class SelectorImpl
SelectableChannel ch = ski.channel();
if (!ch.isOpen() && !ch.isRegistered())
((SelChImpl)ch).kill();
((SelChImpl) ch).kill();
}
}
}