Skip to content

Commit f813a28

Browse files
fgualliniAlan Bateman
authored andcommitted
8254692: (se) Clarify the behaviour of the non-abstract SelectorProvider::inheritedChannel
Reviewed-by: chegar, bpb, alanb
1 parent c9269bf commit f813a28

File tree

3 files changed

+74
-25
lines changed

3 files changed

+74
-25
lines changed

src/java.base/share/classes/java/nio/channels/spi/SelectorProvider.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -301,6 +301,9 @@ public abstract SocketChannel openSocketChannel()
301301
* returned. Subsequent invocations of this method return the same
302302
* channel. </p>
303303
*
304+
* @implSpec The default implementation of this method returns
305+
* {@code null}.
306+
*
304307
* @return The inherited channel, if any, otherwise {@code null}.
305308
*
306309
* @throws IOException

test/jdk/java/nio/channels/etc/ProtocolFamilies.java

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
*/
2323

2424
import jdk.test.lib.NetworkConfiguration;
25-
import jdk.test.lib.Platform;
2625
import jdk.test.lib.net.IPSupport;
2726
import org.testng.annotations.BeforeTest;
2827
import org.testng.annotations.DataProvider;
@@ -31,11 +30,8 @@
3130
import java.io.IOException;
3231
import java.net.*;
3332
import java.nio.channels.*;
34-
import java.nio.channels.spi.AbstractSelector;
3533
import java.nio.channels.spi.SelectorProvider;
3634
import static java.lang.System.out;
37-
import static java.lang.System.getProperty;
38-
import static java.lang.Boolean.parseBoolean;
3935
import static java.net.StandardProtocolFamily.INET;
4036
import static java.net.StandardProtocolFamily.INET6;
4137
import static jdk.test.lib.net.IPSupport.*;
@@ -305,26 +301,6 @@ public void testUoe() {
305301
assertThrows(UOE, () -> SelectorProvider.provider().openDatagramChannel(BAD_PF));
306302
}
307303

308-
// A concrete subclass of SelectorProvider, in order to test implSpec
309-
static final SelectorProvider customerSelectorProvider = new SelectorProvider() {
310-
@Override public DatagramChannel openDatagramChannel() { return null; }
311-
@Override public DatagramChannel openDatagramChannel(ProtocolFamily family) { return null; }
312-
@Override public Pipe openPipe() { return null; }
313-
@Override public AbstractSelector openSelector() { return null; }
314-
@Override public ServerSocketChannel openServerSocketChannel() { return null; }
315-
@Override public SocketChannel openSocketChannel() { return null; }
316-
};
317-
318-
// Tests the specified default implementation of SelectorProvider
319-
@Test
320-
public void testCustomProvider() {
321-
assertThrows(NPE, () -> customerSelectorProvider.openSocketChannel(null));
322-
assertThrows(NPE, () -> customerSelectorProvider.openServerSocketChannel(null));
323-
324-
assertThrows(UOE, () -> customerSelectorProvider.openSocketChannel(BAD_PF));
325-
assertThrows(UOE, () -> customerSelectorProvider.openServerSocketChannel(BAD_PF));
326-
}
327-
328304
// Helper methods
329305

330306
private static SocketChannel openSC(StandardProtocolFamily family)
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/*
2+
* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation.
8+
*
9+
* This code is distributed in the hope that it will be useful, but WITHOUT
10+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12+
* version 2 for more details (a copy is included in the LICENSE file that
13+
* accompanied this code).
14+
*
15+
* You should have received a copy of the GNU General Public License version
16+
* 2 along with this work; if not, write to the Free Software Foundation,
17+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18+
*
19+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20+
* or visit www.oracle.com if you need additional information or have any
21+
* questions.
22+
*/
23+
24+
/*
25+
* @test
26+
* @bug 8254692
27+
* @summary Basic test for java.nio.channels.spi.SelectorProvider.java default implementation
28+
* @run testng TestDefaultImplementation
29+
*/
30+
31+
import org.testng.annotations.Test;
32+
33+
import java.io.IOException;
34+
import java.net.ProtocolFamily;
35+
import java.nio.channels.*;
36+
import java.nio.channels.spi.AbstractSelector;
37+
import java.nio.channels.spi.SelectorProvider;
38+
39+
import static org.testng.Assert.assertNull;
40+
import static org.testng.Assert.assertThrows;
41+
42+
public class TestDefaultImplementation {
43+
static final Class<UnsupportedOperationException> UOE = UnsupportedOperationException.class;
44+
static final Class<NullPointerException> NPE = NullPointerException.class;
45+
static final ProtocolFamily BAD_PF = () -> "BAD_PROTOCOL_FAMILY";
46+
47+
@Test
48+
public void testSelectorProvider() throws IOException {
49+
CustomSelectorProviderImpl customSpi = new CustomSelectorProviderImpl();
50+
51+
assertNull(customSpi.inheritedChannel());
52+
53+
assertThrows(NPE, () -> customSpi.openSocketChannel(null));
54+
assertThrows(NPE, () -> customSpi.openServerSocketChannel(null));
55+
56+
assertThrows(UOE, () -> customSpi.openSocketChannel(BAD_PF));
57+
assertThrows(UOE, () -> customSpi.openServerSocketChannel(BAD_PF));
58+
}
59+
60+
// A concrete subclass of SelectorProvider, in order to test the
61+
// default java.nio.channels.spi.SelectorProvider implementation
62+
static class CustomSelectorProviderImpl extends SelectorProvider {
63+
@Override public DatagramChannel openDatagramChannel() { return null; }
64+
@Override public DatagramChannel openDatagramChannel(ProtocolFamily family) { return null; }
65+
@Override public Pipe openPipe() { return null; }
66+
@Override public AbstractSelector openSelector() { return null; }
67+
@Override public ServerSocketChannel openServerSocketChannel() { return null; }
68+
@Override public SocketChannel openSocketChannel() { return null; }
69+
}
70+
}

0 commit comments

Comments
 (0)