8165180: Provide a shared secret to access non-public ServerSocket constructor

Reviewed-by: chegar
This commit is contained in:
Mandy Chung 2016-08-31 15:20:31 -07:00
parent 4a0362efff
commit b5172ce65e
3 changed files with 80 additions and 0 deletions

View file

@ -25,8 +25,13 @@
package java.net;
import jdk.internal.misc.JavaNetSocketAccess;
import jdk.internal.misc.SharedSecrets;
import java.io.FileDescriptor;
import java.io.IOException;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.nio.channels.ServerSocketChannel;
import java.security.AccessController;
import java.security.PrivilegedExceptionAction;
@ -1011,4 +1016,27 @@ class ServerSocket implements java.io.Closeable {
return options;
}
}
static {
SharedSecrets.setJavaNetSocketAccess(
new JavaNetSocketAccess() {
@Override
public ServerSocket newServerSocket(SocketImpl impl) {
return new ServerSocket(impl);
}
@Override
public SocketImpl newSocketImpl(Class<? extends SocketImpl> implClass) {
try {
Constructor<? extends SocketImpl> ctor =
implClass.getDeclaredConstructor();
return ctor.newInstance();
} catch (NoSuchMethodException | InstantiationException |
IllegalAccessException | InvocationTargetException e) {
throw new AssertionError(e);
}
}
}
);
}
}