diff options
author | Neil Fuller <nfuller@google.com> | 2014-11-27 17:10:45 +0000 |
---|---|---|
committer | Neil Fuller <nfuller@google.com> | 2014-12-02 15:55:27 +0000 |
commit | 99a0c82619a88c6aea038757cf14090f5d33afeb (patch) | |
tree | 311ee48d5f1483ac313fa1849bcc74ebf28f7a19 /luni/src/test | |
parent | 8aab60ff17eed154c079e55dcfcd84dacef93351 (diff) | |
download | libcore-99a0c82619a88c6aea038757cf14090f5d33afeb.zip libcore-99a0c82619a88c6aea038757cf14090f5d33afeb.tar.gz libcore-99a0c82619a88c6aea038757cf14090f5d33afeb.tar.bz2 |
Fix crash in selector.wakeup() with closed selector
Selector.wakeup() can throw an undeclared IOException
(from native code).
This is not compatible with the signature of wakeup(). In prior
Android releases no exception is thrown in this case.
This change reverts the behavior to the same as prior Android
releases.
Many thanks to diddysbestbud@ for the report.
Bug: https://code.google.com/p/android/issues/detail?id=80785
Bug: 18548071
(cherry picked from commit 1791f6be1bd2733babb0c862ad8509f4c847b48f)
Change-Id: I19ee879dcd783655d8a402e12855a5fa1f1eb90c
Diffstat (limited to 'luni/src/test')
-rw-r--r-- | luni/src/test/java/libcore/java/nio/channels/SelectorTest.java | 63 |
1 files changed, 37 insertions, 26 deletions
diff --git a/luni/src/test/java/libcore/java/nio/channels/SelectorTest.java b/luni/src/test/java/libcore/java/nio/channels/SelectorTest.java index c5f449e..9789197 100644 --- a/luni/src/test/java/libcore/java/nio/channels/SelectorTest.java +++ b/luni/src/test/java/libcore/java/nio/channels/SelectorTest.java @@ -146,32 +146,43 @@ public class SelectorTest extends TestCase { } public void test_57456() throws Exception { - Selector selector = Selector.open(); - ServerSocketChannel ssc = ServerSocketChannel.open(); - - try { - // Connect. - ssc.configureBlocking(false); - ssc.socket().bind(null); - SocketChannel sc = SocketChannel.open(); - sc.connect(ssc.socket().getLocalSocketAddress()); - sc.finishConnect(); - - // Switch to non-blocking so we can use a Selector. - sc.configureBlocking(false); - - // Have the 'server' write something. - ssc.accept().write(ByteBuffer.allocate(128)); - - // At this point, the client should be able to read or write immediately. - // (It shouldn't be able to connect because it's already connected.) - SelectionKey key = sc.register(selector, SelectionKey.OP_CONNECT | SelectionKey.OP_READ | SelectionKey.OP_WRITE); - assertEquals(1, selector.select()); - assertEquals(SelectionKey.OP_READ | SelectionKey.OP_WRITE, key.readyOps()); - assertEquals(0, selector.select()); - } finally { + Selector selector = Selector.open(); + ServerSocketChannel ssc = ServerSocketChannel.open(); + + try { + // Connect. + ssc.configureBlocking(false); + ssc.socket().bind(null); + SocketChannel sc = SocketChannel.open(); + sc.connect(ssc.socket().getLocalSocketAddress()); + sc.finishConnect(); + + // Switch to non-blocking so we can use a Selector. + sc.configureBlocking(false); + + // Have the 'server' write something. + ssc.accept().write(ByteBuffer.allocate(128)); + + // At this point, the client should be able to read or write immediately. + // (It shouldn't be able to connect because it's already connected.) + SelectionKey key = sc.register(selector, + SelectionKey.OP_CONNECT | SelectionKey.OP_READ | SelectionKey.OP_WRITE); + assertEquals(1, selector.select()); + assertEquals(SelectionKey.OP_READ | SelectionKey.OP_WRITE, key.readyOps()); + assertEquals(0, selector.select()); + } finally { + selector.close(); + ssc.close(); + } + } + + // http://code.google.com/p/android/issues/detail?id=80785 + public void test_80785() throws Exception { + Selector selector = Selector.open(); selector.close(); - ssc.close(); - } + + // Historically on android this did not throw an exception. Due to the bug it would throw + // an (undeclared) IOException. + selector.wakeup(); } } |