Path: blob/master/test/jdk/java/net/PlainSocketImpl/CustomSocketImplFactory.java
41149 views
/*1* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @bug 802495226* @summary ClassCastException in PlainSocketImpl.accept() when using custom socketImpl27* @run main/othervm CustomSocketImplFactory28*/2930import java.net.*;31import java.io.*;3233public class CustomSocketImplFactory implements SocketImplFactory {3435@Override36public SocketImpl createSocketImpl() {37try {38SocketImpl s = new CustomSocketImpl();39System.out.println("Created " + s);40return s;41} catch (Exception e) {42throw new RuntimeException(e);43}44}4546public static void main(String[] args) throws Exception {4748Socket.setSocketImplFactory(new CustomSocketImplFactory());49try (ServerSocket ss = new ServerSocket(0)) {50ss.setSoTimeout(1);51ss.accept();52System.out.println("PASS");53} catch (SocketTimeoutException | NullPointerException e) {54// Not a real socket impl55}56}5758class CustomSocketImpl extends SocketImpl {5960public void create(boolean stream) throws IOException {61}6263public void connect(String host, int port) throws IOException {64}6566public void connect(InetAddress addr, int port) throws IOException {67}6869public void connect(SocketAddress addr, int timeout) throws IOException {70}7172public void bind(InetAddress host, int port) throws IOException {73}7475public void listen(int backlog) throws IOException {76}7778public void accept(SocketImpl s) throws IOException {79}8081public InputStream getInputStream() throws IOException {82return null;83}8485public OutputStream getOutputStream() throws IOException {86return null;87}8889public int available() throws IOException {90return 0;91}9293public void close() throws IOException {94}9596public void sendUrgentData(int data) throws IOException {97}9899public Object getOption(int i) throws SocketException {100return null;101}102103public void setOption(int i, Object o) throws SocketException {104}105}106}107108109