This patch removes support for old, pre-1.4 SocketImpl and DatagramSocketImpl classes. Compiling these classes has been impossible since 1.4 because 1.4 added new abstract methods to the base classes.

Is this okay in principle?  Could you create bug ID for this?

--
Florian Weimer / Red Hat Product Security Team
# HG changeset patch
# User Florian Weimer <fwei...@redhat.com>
# Date 1392384255 -3600
#      Fri Feb 14 14:24:15 2014 +0100
# Node ID 5d60f520d1812e0209764bf960f4e8e383225565
# Parent  89b08242fc2aee6b6b8ed5c3ee11c3a9df182350
Remove support for old socket implementations

diff --git a/src/share/classes/java/net/DatagramSocket.java b/src/share/classes/java/net/DatagramSocket.java
--- a/src/share/classes/java/net/DatagramSocket.java
+++ b/src/share/classes/java/net/DatagramSocket.java
@@ -78,11 +78,6 @@
      */
     DatagramSocketImpl impl;
 
-    /**
-     * Are we using an older DatagramSocketImpl?
-     */
-    boolean oldImpl = false;
-
     /*
      * Connection state:
      * ST_NOT_CONNECTED = socket not connected
@@ -133,8 +128,8 @@
           bind(new InetSocketAddress(0));
 
         // old impls do not support connect/disconnect
-        if (oldImpl || (impl instanceof AbstractPlainDatagramSocketImpl &&
-             ((AbstractPlainDatagramSocketImpl)impl).nativeConnectDisabled())) {
+        if (impl instanceof AbstractPlainDatagramSocketImpl &&
+             ((AbstractPlainDatagramSocketImpl)impl).nativeConnectDisabled()) {
             connectState = ST_CONNECTED_NO_IMPL;
         } else {
             try {
@@ -188,7 +183,6 @@
         if (impl == null)
             throw new NullPointerException();
         this.impl = impl;
-        checkOldImpl();
     }
 
     /**
@@ -279,38 +273,15 @@
         this(new InetSocketAddress(laddr, port));
     }
 
-    private void checkOldImpl() {
-        if (impl == null)
-            return;
-        // DatagramSocketImpl.peekdata() is a protected method, therefore we need to use
-        // getDeclaredMethod, therefore we need permission to access the member
-        try {
-            AccessController.doPrivileged(
-                new PrivilegedExceptionAction<Void>() {
-                    public Void run() throws NoSuchMethodException {
-                        Class<?>[] cl = new Class<?>[1];
-                        cl[0] = DatagramPacket.class;
-                        impl.getClass().getDeclaredMethod("peekData", cl);
-                        return null;
-                    }
-                });
-        } catch (java.security.PrivilegedActionException e) {
-            oldImpl = true;
-        }
-    }
-
     static Class<?> implClass = null;
 
     void createImpl() throws SocketException {
         if (impl == null) {
             if (factory != null) {
                 impl = factory.createDatagramSocketImpl();
-                checkOldImpl();
             } else {
                 boolean isMulticast = (this instanceof MulticastSocket) ? true : false;
                 impl = DefaultDatagramSocketImplFactory.createDatagramSocketImpl(isMulticast);
-
-                checkOldImpl();
             }
         }
         // creates a udp socket
@@ -715,16 +686,9 @@
                         String peekAd = null;
                         int peekPort = 0;
                         // peek at the packet to see who it is from.
-                        if (!oldImpl) {
-                            // We can use the new peekData() API
-                            DatagramPacket peekPacket = new DatagramPacket(new byte[1], 1);
-                            peekPort = getImpl().peekData(peekPacket);
-                            peekAd = peekPacket.getAddress().getHostAddress();
-                        } else {
-                            InetAddress adr = new InetAddress();
-                            peekPort = getImpl().peek(adr);
-                            peekAd = adr.getHostAddress();
-                        }
+			DatagramPacket peekPacket = new DatagramPacket(new byte[1], 1);
+			peekPort = getImpl().peekData(peekPacket);
+			peekAd = peekPacket.getAddress().getHostAddress();
                         try {
                             security.checkAccept(peekAd, peekPort);
                             // security check succeeded - so now break
@@ -756,16 +720,10 @@
                     InetAddress peekAddress = null;
                     int peekPort = -1;
                     // peek at the packet to see who it is from.
-                    if (!oldImpl) {
-                        // We can use the new peekData() API
-                        DatagramPacket peekPacket = new DatagramPacket(new byte[1], 1);
-                        peekPort = getImpl().peekData(peekPacket);
-                        peekAddress = peekPacket.getAddress();
-                    } else {
-                        // this api only works for IPv4
-                        peekAddress = new InetAddress();
-                        peekPort = getImpl().peek(peekAddress);
-                    }
+		    // We can use the new peekData() API
+		    DatagramPacket peekPacket = new DatagramPacket(new byte[1], 1);
+		    peekPort = getImpl().peekData(peekPacket);
+		    peekAddress = peekPacket.getAddress();
                     if ((!connectedAddress.equals(peekAddress)) ||
                         (connectedPort != peekPort)) {
                         // throw the packet away and silently continue
@@ -1035,11 +993,7 @@
     public synchronized void setReuseAddress(boolean on) throws SocketException {
         if (isClosed())
             throw new SocketException("Socket is closed");
-        // Integer instead of Boolean for compatibility with older DatagramSocketImpl
-        if (oldImpl)
-            getImpl().setOption(SocketOptions.SO_REUSEADDR, new Integer(on?-1:0));
-        else
-            getImpl().setOption(SocketOptions.SO_REUSEADDR, Boolean.valueOf(on));
+	getImpl().setOption(SocketOptions.SO_REUSEADDR, Boolean.valueOf(on));
     }
 
     /**
diff --git a/src/share/classes/java/net/MulticastSocket.java b/src/share/classes/java/net/MulticastSocket.java
--- a/src/share/classes/java/net/MulticastSocket.java
+++ b/src/share/classes/java/net/MulticastSocket.java
@@ -390,9 +390,6 @@
         if (mcastaddr == null || !(mcastaddr instanceof InetSocketAddress))
             throw new IllegalArgumentException("Unsupported address type");
 
-        if (oldImpl)
-            throw new UnsupportedOperationException();
-
         checkAddress(((InetSocketAddress)mcastaddr).getAddress(), "joinGroup");
         SecurityManager security = System.getSecurityManager();
         if (security != null) {
@@ -437,9 +434,6 @@
         if (mcastaddr == null || !(mcastaddr instanceof InetSocketAddress))
             throw new IllegalArgumentException("Unsupported address type");
 
-        if (oldImpl)
-            throw new UnsupportedOperationException();
-
         checkAddress(((InetSocketAddress)mcastaddr).getAddress(), "leaveGroup");
         SecurityManager security = System.getSecurityManager();
         if (security != null) {
diff --git a/src/share/classes/java/net/ServerSocket.java b/src/share/classes/java/net/ServerSocket.java
--- a/src/share/classes/java/net/ServerSocket.java
+++ b/src/share/classes/java/net/ServerSocket.java
@@ -64,11 +64,6 @@
     private SocketImpl impl;
 
     /**
-     * Are we using an older SocketImpl?
-     */
-    private boolean oldImpl = false;
-
-    /**
      * Package-private constructor to create a ServerSocket associated with
      * the given SocketImpl.
      */
@@ -258,33 +253,10 @@
         return impl;
     }
 
-    private void checkOldImpl() {
-        if (impl == null)
-            return;
-        // SocketImpl.connect() is a protected method, therefore we need to use
-        // getDeclaredMethod, therefore we need permission to access the member
-        try {
-            AccessController.doPrivileged(
-                new PrivilegedExceptionAction<Void>() {
-                    public Void run() throws NoSuchMethodException {
-                        impl.getClass().getDeclaredMethod("connect",
-                                                          SocketAddress.class,
-                                                          int.class);
-                        return null;
-                    }
-                });
-        } catch (java.security.PrivilegedActionException e) {
-            oldImpl = true;
-        }
-    }
-
     private void setImpl() {
         if (factory != null) {
             impl = factory.createSocketImpl();
-            checkOldImpl();
         } else {
-            // No need to do a checkOldImpl() here, we know it's an up to date
-            // SocketImpl!
             impl = new SocksSocketImpl();
         }
         if (impl != null)
@@ -357,7 +329,7 @@
     public void bind(SocketAddress endpoint, int backlog) throws IOException {
         if (isClosed())
             throw new SocketException("Socket is closed");
-        if (!oldImpl && isBound())
+        if (isBound())
             throw new SocketException("Already bound");
         if (endpoint == null)
             endpoint = new InetSocketAddress(0);
@@ -614,8 +586,7 @@
      * @since 1.4
      */
     public boolean isBound() {
-        // Before 1.3 ServerSockets were always bound during creation
-        return bound || oldImpl;
+        return bound;
     }
 
     /**
diff --git a/src/share/classes/java/net/Socket.java b/src/share/classes/java/net/Socket.java
--- a/src/share/classes/java/net/Socket.java
+++ b/src/share/classes/java/net/Socket.java
@@ -69,11 +69,6 @@
     SocketImpl impl;
 
     /**
-     * Are we using an older SocketImpl?
-     */
-    private boolean oldImpl = false;
-
-    /**
      * Creates an unconnected socket, with the
      * system-default type of SocketImpl.
      *
@@ -164,7 +159,6 @@
     protected Socket(SocketImpl impl) throws SocketException {
         this.impl = impl;
         if (impl != null) {
-            checkOldImpl();
             this.impl.setSocket(this);
         }
     }
@@ -461,34 +455,6 @@
         }
     }
 
-    private void checkOldImpl() {
-        if (impl == null)
-            return;
-        // SocketImpl.connect() is a protected method, therefore we need to use
-        // getDeclaredMethod, therefore we need permission to access the member
-
-        oldImpl = AccessController.doPrivileged
-                                (new PrivilegedAction<Boolean>() {
-            public Boolean run() {
-                Class<?> clazz = impl.getClass();
-                while (true) {
-                    try {
-                        clazz.getDeclaredMethod("connect", SocketAddress.class, int.class);
-                        return Boolean.FALSE;
-                    } catch (NoSuchMethodException e) {
-                        clazz = clazz.getSuperclass();
-                        // java.net.SocketImpl class will always have this abstract method.
-                        // If we have not found it by now in the hierarchy then it does not
-                        // exist, we are an old style impl.
-                        if (clazz.equals(java.net.SocketImpl.class)) {
-                            return Boolean.TRUE;
-                        }
-                    }
-                }
-            }
-        });
-    }
-
     /**
      * Sets impl to the system-default type of SocketImpl.
      * @since 1.4
@@ -496,10 +462,7 @@
     void setImpl() {
         if (factory != null) {
             impl = factory.createSocketImpl();
-            checkOldImpl();
         } else {
-            // No need to do a checkOldImpl() here, we know it's an up to date
-            // SocketImpl!
             impl = new SocksSocketImpl();
         }
         if (impl != null)
@@ -565,7 +528,7 @@
         if (isClosed())
             throw new SocketException("Socket is closed");
 
-        if (!oldImpl && isConnected())
+        if (isConnected())
             throw new SocketException("already connected");
 
         if (!(endpoint instanceof InetSocketAddress))
@@ -585,15 +548,7 @@
         }
         if (!created)
             createImpl(true);
-        if (!oldImpl)
-            impl.connect(epoint, timeout);
-        else if (timeout == 0) {
-            if (epoint.isUnresolved())
-                impl.connect(addr.getHostName(), port);
-            else
-                impl.connect(addr, port);
-        } else
-            throw new UnsupportedOperationException("SocketImpl.connect(addr, timeout)");
+	impl.connect(epoint, timeout);
         connected = true;
         /*
          * If the socket was not bound before the connect, it is now because
@@ -623,7 +578,7 @@
     public void bind(SocketAddress bindpoint) throws IOException {
         if (isClosed())
             throw new SocketException("Socket is closed");
-        if (!oldImpl && isBound())
+        if (isBound())
             throw new SocketException("Already bound");
 
         if (bindpoint != null && (!(bindpoint instanceof InetSocketAddress)))
@@ -1578,8 +1533,7 @@
      * @since 1.4
      */
     public boolean isConnected() {
-        // Before 1.3 Sockets were always connected during creation
-        return connected || oldImpl;
+        return connected;
     }
 
     /**
@@ -1595,8 +1549,7 @@
      * @see #bind
      */
     public boolean isBound() {
-        // Before 1.3 Sockets were always bound during creation
-        return bound || oldImpl;
+        return bound;
     }
 
     /**
diff --git a/test/java/net/Socket/OldImpl.java b/test/java/net/Socket/OldImpl.java
deleted file mode 100644
--- a/test/java/net/Socket/OldImpl.java
+++ /dev/null
@@ -1,105 +0,0 @@
-/*
- * Copyright (c) 2005, 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
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-import java.io.*;
-import java.net.*;
-
-
-/**
- * @test
- * @bug 5089488
- * @summary  java.net.Socket checks for old-style impls
- */
-
-public class OldImpl {
-
-    /**
-     * A no-op SocketImpl descendant.
-     */
-    static class FunkySocketImpl extends SocketImpl {
-        protected void accept(SocketImpl impl) throws IOException {
-        }
-
-        protected int available(){
-            return 0;
-        }
-
-        protected void bind(InetAddress host, int port){
-        }
-
-        protected void close(){
-        }
-
-        protected void connect(InetAddress address, int port){
-        }
-
-        protected void connect(String host, int port){
-        }
-
-        protected void connect(SocketAddress a,int b){
-        }
-
-        protected void create(boolean stream){
-        }
-
-        protected InputStream getInputStream(){
-            return null;
-        }
-
-        protected OutputStream getOutputStream(){
-            return null;
-        }
-
-        protected void listen(int backlog){
-        }
-
-        public Object getOption(int optID){
-            return null;
-        }
-
-        public void setOption(int optID, Object value){
-        }
-
-        protected void sendUrgentData(int i){
-        }
-    }
-
-    static class FunkyWunkySocketImpl extends FunkySocketImpl {}
-
-    /**
-     * A no-op Socket descendant.
-     */
-    static class FunkySocket extends Socket {
-        public FunkySocket(SocketImpl impl) throws IOException {
-            super(impl);
-        }
-    }
-
-    public static void main(String args[]) throws Exception {
-        FunkyWunkySocketImpl socketImpl = new FunkyWunkySocketImpl();
-        FunkySocket socko = new FunkySocket(socketImpl);
-        if (socko.isBound()) {
-            throw new RuntimeException ("socket is not really bound");
-        }
-    }
-}
diff --git a/test/java/net/Socket/OldSocketImpl.jar b/test/java/net/Socket/OldSocketImpl.jar
deleted file mode 100644
index 6a646ba8631ab1af9697a1cc3bf43dfc38697b78..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391
GIT binary patch
literal 0
Hc$@<O00001

diff --git a/test/java/net/Socket/OldSocketImpl.java b/test/java/net/Socket/OldSocketImpl.java
deleted file mode 100644
--- a/test/java/net/Socket/OldSocketImpl.java
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- * Copyright (c) 2006, 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
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-import java.io.*;
-import java.net.*;
-
-class OldSocketImpl extends SocketImpl  {
-    public static void main(String[] args) throws Exception {
-        Socket.setSocketImplFactory(new SocketImplFactory() {
-                public SocketImpl createSocketImpl() {
-                    return new OldSocketImpl();
-                }
-        });
-        Socket socket = new Socket("localhost", 23);
-    }
-
-    public void setOption(int optID, Object value) throws SocketException { }
-
-    public Object getOption(int optID) throws SocketException {
-        return null;
-    }
-
-    protected void create(boolean stream) throws IOException { }
-
-    protected void connect(String host, int port) throws IOException { }
-
-    protected void connect(InetAddress address, int port) throws IOException { }
-
-    // Not in 1.3...
-    // protected void connect(SocketAddress address, int timeout) throws IOException { }
-
-    protected void bind(InetAddress host, int port) throws IOException { }
-
-    protected void listen(int backlog) throws IOException { }
-
-    protected void accept(SocketImpl s) throws IOException { }
-
-    protected InputStream getInputStream() throws IOException {
-        return null;
-    }
-
-    protected OutputStream getOutputStream() throws IOException {
-        return null;
-    }
-
-    protected int available() throws IOException {
-        return 0;
-    }
-
-    protected void close() throws IOException { }
-
-    protected void sendUrgentData (int data) throws SocketException { }
-
-}
diff --git a/test/java/net/Socket/OldSocketImpl.sh b/test/java/net/Socket/OldSocketImpl.sh
deleted file mode 100644
--- a/test/java/net/Socket/OldSocketImpl.sh
+++ /dev/null
@@ -1,61 +0,0 @@
-#
-# Copyright (c) 2006, 2012, 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
-# under the terms of the GNU General Public License version 2 only, as
-# published by the Free Software Foundation.
-#
-# This code is distributed in the hope that it will be useful, but WITHOUT
-# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
-# version 2 for more details (a copy is included in the LICENSE file that
-# accompanied this code).
-#
-# You should have received a copy of the GNU General Public License version
-# 2 along with this work; if not, write to the Free Software Foundation,
-# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
-#
-# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
-# or visit www.oracle.com if you need additional information or have any
-# questions.
-#
-
-# @test
-# @bug 6449565
-# @run shell/timeout=140 OldSocketImpl.sh
-# @summary Pre-1.4 SocketImpl no longer supported
-
-OS=`uname -s`
-case "$OS" in
-  SunOS | Linux | Darwin | AIX )
-    PS=":"
-    FS="/"
-    ;;
-  CYGWIN* )
-    PS=";"
-    FS="/"
-    ;;
-  Windows* )
-    PS=";"
-    FS="\\"
-    ;;
-  * )
-    echo "Unrecognized system!"
-    exit 1;
-    ;;
-esac
-
-# no need to compile the test. It is already compiled
-# with 1.3 and in OldStyleImpl.jar
-
-# run
-${TESTJAVA}${FS}bin${FS}java ${TESTVMOPTS} -cp ${TESTSRC}${FS}OldSocketImpl.jar OldSocketImpl
-result=$?
-if [ "$result" -ne "0" ]; then
-    exit 1
-fi
-
-# no failures, exit.
-exit 0
-

Reply via email to