Java 8 Migration: remove uneccessary if statement (#8755)
Motivation: As netty 4.x supported Java 6 we had various if statements to check for java versions < 8. We can remove these now. Modification: Remove unnecessary if statements that check for java versions < 8. Result: Cleanup code.
This commit is contained in:
parent
310f31b392
commit
7b6336f1fd
@ -130,26 +130,18 @@ final class PooledUnsafeHeapByteBuf extends PooledHeapByteBuf {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ByteBuf setZero(int index, int length) {
|
public ByteBuf setZero(int index, int length) {
|
||||||
if (PlatformDependent.javaVersion() >= 7) {
|
checkIndex(index, length);
|
||||||
checkIndex(index, length);
|
UnsafeByteBufUtil.setZero(memory, idx(index), length);
|
||||||
// Only do on java7+ as the needed Unsafe call was only added there.
|
return this;
|
||||||
UnsafeByteBufUtil.setZero(memory, idx(index), length);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
return super.setZero(index, length);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ByteBuf writeZero(int length) {
|
public ByteBuf writeZero(int length) {
|
||||||
if (PlatformDependent.javaVersion() >= 7) {
|
ensureWritable(length);
|
||||||
// Only do on java7+ as the needed Unsafe call was only added there.
|
int wIndex = writerIndex;
|
||||||
ensureWritable(length);
|
UnsafeByteBufUtil.setZero(memory, idx(wIndex), length);
|
||||||
int wIndex = writerIndex;
|
writerIndex = wIndex + length;
|
||||||
UnsafeByteBufUtil.setZero(memory, idx(wIndex), length);
|
return this;
|
||||||
writerIndex = wIndex + length;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
return super.writeZero(length);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -243,26 +243,18 @@ class UnpooledUnsafeHeapByteBuf extends UnpooledHeapByteBuf {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ByteBuf setZero(int index, int length) {
|
public ByteBuf setZero(int index, int length) {
|
||||||
if (PlatformDependent.javaVersion() >= 7) {
|
checkIndex(index, length);
|
||||||
// Only do on java7+ as the needed Unsafe call was only added there.
|
UnsafeByteBufUtil.setZero(array, index, length);
|
||||||
checkIndex(index, length);
|
return this;
|
||||||
UnsafeByteBufUtil.setZero(array, index, length);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
return super.setZero(index, length);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ByteBuf writeZero(int length) {
|
public ByteBuf writeZero(int length) {
|
||||||
if (PlatformDependent.javaVersion() >= 7) {
|
ensureWritable(length);
|
||||||
// Only do on java7+ as the needed Unsafe call was only added there.
|
int wIndex = writerIndex;
|
||||||
ensureWritable(length);
|
UnsafeByteBufUtil.setZero(array, wIndex, length);
|
||||||
int wIndex = writerIndex;
|
writerIndex = wIndex + length;
|
||||||
UnsafeByteBufUtil.setZero(array, wIndex, length);
|
return this;
|
||||||
writerIndex = wIndex + length;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
return super.writeZero(length);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -23,14 +23,7 @@ abstract class SpdyHeaderBlockEncoder {
|
|||||||
|
|
||||||
static SpdyHeaderBlockEncoder newInstance(
|
static SpdyHeaderBlockEncoder newInstance(
|
||||||
SpdyVersion version, int compressionLevel, int windowBits, int memLevel) {
|
SpdyVersion version, int compressionLevel, int windowBits, int memLevel) {
|
||||||
|
return new SpdyHeaderBlockZlibEncoder(version, compressionLevel);
|
||||||
if (PlatformDependent.javaVersion() >= 7) {
|
|
||||||
return new SpdyHeaderBlockZlibEncoder(
|
|
||||||
version, compressionLevel);
|
|
||||||
} else {
|
|
||||||
return new SpdyHeaderBlockJZlibEncoder(
|
|
||||||
version, compressionLevel, windowBits, memLevel);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract ByteBuf encode(ByteBufAllocator alloc, SpdyHeadersFrame frame) throws Exception;
|
abstract ByteBuf encode(ByteBufAllocator alloc, SpdyHeadersFrame frame) throws Exception;
|
||||||
|
@ -52,16 +52,13 @@ abstract class ByteBufChecksum implements Checksum {
|
|||||||
};
|
};
|
||||||
|
|
||||||
private static Method updateByteBuffer(Checksum checksum) {
|
private static Method updateByteBuffer(Checksum checksum) {
|
||||||
if (PlatformDependent.javaVersion() >= 8) {
|
try {
|
||||||
try {
|
Method method = checksum.getClass().getDeclaredMethod("update", ByteBuffer.class);
|
||||||
Method method = checksum.getClass().getDeclaredMethod("update", ByteBuffer.class);
|
method.invoke(method, ByteBuffer.allocate(1));
|
||||||
method.invoke(method, ByteBuffer.allocate(1));
|
return method;
|
||||||
return method;
|
} catch (Throwable ignore) {
|
||||||
} catch (Throwable ignore) {
|
return null;
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static ByteBufChecksum wrapChecksum(Checksum checksum) {
|
static ByteBufChecksum wrapChecksum(Checksum checksum) {
|
||||||
|
@ -34,14 +34,13 @@ public final class ZlibCodecFactory {
|
|||||||
private static final boolean supportsWindowSizeAndMemLevel;
|
private static final boolean supportsWindowSizeAndMemLevel;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
noJdkZlibDecoder = SystemPropertyUtil.getBoolean("io.netty.noJdkZlibDecoder",
|
noJdkZlibDecoder = SystemPropertyUtil.getBoolean("io.netty.noJdkZlibDecoder", false);
|
||||||
PlatformDependent.javaVersion() < 7);
|
|
||||||
logger.debug("-Dio.netty.noJdkZlibDecoder: {}", noJdkZlibDecoder);
|
logger.debug("-Dio.netty.noJdkZlibDecoder: {}", noJdkZlibDecoder);
|
||||||
|
|
||||||
noJdkZlibEncoder = SystemPropertyUtil.getBoolean("io.netty.noJdkZlibEncoder", false);
|
noJdkZlibEncoder = SystemPropertyUtil.getBoolean("io.netty.noJdkZlibEncoder", false);
|
||||||
logger.debug("-Dio.netty.noJdkZlibEncoder: {}", noJdkZlibEncoder);
|
logger.debug("-Dio.netty.noJdkZlibEncoder: {}", noJdkZlibEncoder);
|
||||||
|
|
||||||
supportsWindowSizeAndMemLevel = noJdkZlibDecoder || PlatformDependent.javaVersion() >= 7;
|
supportsWindowSizeAndMemLevel = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -52,7 +51,7 @@ public final class ZlibCodecFactory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static ZlibEncoder newZlibEncoder(int compressionLevel) {
|
public static ZlibEncoder newZlibEncoder(int compressionLevel) {
|
||||||
if (PlatformDependent.javaVersion() < 7 || noJdkZlibEncoder) {
|
if (noJdkZlibEncoder) {
|
||||||
return new JZlibEncoder(compressionLevel);
|
return new JZlibEncoder(compressionLevel);
|
||||||
} else {
|
} else {
|
||||||
return new JdkZlibEncoder(compressionLevel);
|
return new JdkZlibEncoder(compressionLevel);
|
||||||
@ -60,7 +59,7 @@ public final class ZlibCodecFactory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static ZlibEncoder newZlibEncoder(ZlibWrapper wrapper) {
|
public static ZlibEncoder newZlibEncoder(ZlibWrapper wrapper) {
|
||||||
if (PlatformDependent.javaVersion() < 7 || noJdkZlibEncoder) {
|
if (noJdkZlibEncoder) {
|
||||||
return new JZlibEncoder(wrapper);
|
return new JZlibEncoder(wrapper);
|
||||||
} else {
|
} else {
|
||||||
return new JdkZlibEncoder(wrapper);
|
return new JdkZlibEncoder(wrapper);
|
||||||
@ -68,7 +67,7 @@ public final class ZlibCodecFactory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static ZlibEncoder newZlibEncoder(ZlibWrapper wrapper, int compressionLevel) {
|
public static ZlibEncoder newZlibEncoder(ZlibWrapper wrapper, int compressionLevel) {
|
||||||
if (PlatformDependent.javaVersion() < 7 || noJdkZlibEncoder) {
|
if (noJdkZlibEncoder) {
|
||||||
return new JZlibEncoder(wrapper, compressionLevel);
|
return new JZlibEncoder(wrapper, compressionLevel);
|
||||||
} else {
|
} else {
|
||||||
return new JdkZlibEncoder(wrapper, compressionLevel);
|
return new JdkZlibEncoder(wrapper, compressionLevel);
|
||||||
@ -76,7 +75,7 @@ public final class ZlibCodecFactory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static ZlibEncoder newZlibEncoder(ZlibWrapper wrapper, int compressionLevel, int windowBits, int memLevel) {
|
public static ZlibEncoder newZlibEncoder(ZlibWrapper wrapper, int compressionLevel, int windowBits, int memLevel) {
|
||||||
if (PlatformDependent.javaVersion() < 7 || noJdkZlibEncoder ||
|
if (noJdkZlibEncoder ||
|
||||||
windowBits != DEFAULT_JDK_WINDOW_SIZE || memLevel != DEFAULT_JDK_MEM_LEVEL) {
|
windowBits != DEFAULT_JDK_WINDOW_SIZE || memLevel != DEFAULT_JDK_MEM_LEVEL) {
|
||||||
return new JZlibEncoder(wrapper, compressionLevel, windowBits, memLevel);
|
return new JZlibEncoder(wrapper, compressionLevel, windowBits, memLevel);
|
||||||
} else {
|
} else {
|
||||||
@ -85,7 +84,7 @@ public final class ZlibCodecFactory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static ZlibEncoder newZlibEncoder(byte[] dictionary) {
|
public static ZlibEncoder newZlibEncoder(byte[] dictionary) {
|
||||||
if (PlatformDependent.javaVersion() < 7 || noJdkZlibEncoder) {
|
if (noJdkZlibEncoder) {
|
||||||
return new JZlibEncoder(dictionary);
|
return new JZlibEncoder(dictionary);
|
||||||
} else {
|
} else {
|
||||||
return new JdkZlibEncoder(dictionary);
|
return new JdkZlibEncoder(dictionary);
|
||||||
@ -93,7 +92,7 @@ public final class ZlibCodecFactory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static ZlibEncoder newZlibEncoder(int compressionLevel, byte[] dictionary) {
|
public static ZlibEncoder newZlibEncoder(int compressionLevel, byte[] dictionary) {
|
||||||
if (PlatformDependent.javaVersion() < 7 || noJdkZlibEncoder) {
|
if (noJdkZlibEncoder) {
|
||||||
return new JZlibEncoder(compressionLevel, dictionary);
|
return new JZlibEncoder(compressionLevel, dictionary);
|
||||||
} else {
|
} else {
|
||||||
return new JdkZlibEncoder(compressionLevel, dictionary);
|
return new JdkZlibEncoder(compressionLevel, dictionary);
|
||||||
@ -101,7 +100,7 @@ public final class ZlibCodecFactory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static ZlibEncoder newZlibEncoder(int compressionLevel, int windowBits, int memLevel, byte[] dictionary) {
|
public static ZlibEncoder newZlibEncoder(int compressionLevel, int windowBits, int memLevel, byte[] dictionary) {
|
||||||
if (PlatformDependent.javaVersion() < 7 || noJdkZlibEncoder ||
|
if (noJdkZlibEncoder ||
|
||||||
windowBits != DEFAULT_JDK_WINDOW_SIZE || memLevel != DEFAULT_JDK_MEM_LEVEL) {
|
windowBits != DEFAULT_JDK_WINDOW_SIZE || memLevel != DEFAULT_JDK_MEM_LEVEL) {
|
||||||
return new JZlibEncoder(compressionLevel, windowBits, memLevel, dictionary);
|
return new JZlibEncoder(compressionLevel, windowBits, memLevel, dictionary);
|
||||||
} else {
|
} else {
|
||||||
@ -110,7 +109,7 @@ public final class ZlibCodecFactory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static ZlibDecoder newZlibDecoder() {
|
public static ZlibDecoder newZlibDecoder() {
|
||||||
if (PlatformDependent.javaVersion() < 7 || noJdkZlibDecoder) {
|
if (noJdkZlibDecoder) {
|
||||||
return new JZlibDecoder();
|
return new JZlibDecoder();
|
||||||
} else {
|
} else {
|
||||||
return new JdkZlibDecoder(true);
|
return new JdkZlibDecoder(true);
|
||||||
@ -118,7 +117,7 @@ public final class ZlibCodecFactory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static ZlibDecoder newZlibDecoder(ZlibWrapper wrapper) {
|
public static ZlibDecoder newZlibDecoder(ZlibWrapper wrapper) {
|
||||||
if (PlatformDependent.javaVersion() < 7 || noJdkZlibDecoder) {
|
if (noJdkZlibDecoder) {
|
||||||
return new JZlibDecoder(wrapper);
|
return new JZlibDecoder(wrapper);
|
||||||
} else {
|
} else {
|
||||||
return new JdkZlibDecoder(wrapper, true);
|
return new JdkZlibDecoder(wrapper, true);
|
||||||
@ -126,7 +125,7 @@ public final class ZlibCodecFactory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static ZlibDecoder newZlibDecoder(byte[] dictionary) {
|
public static ZlibDecoder newZlibDecoder(byte[] dictionary) {
|
||||||
if (PlatformDependent.javaVersion() < 7 || noJdkZlibDecoder) {
|
if (noJdkZlibDecoder) {
|
||||||
return new JZlibDecoder(dictionary);
|
return new JZlibDecoder(dictionary);
|
||||||
} else {
|
} else {
|
||||||
return new JdkZlibDecoder(dictionary);
|
return new JdkZlibDecoder(dictionary);
|
||||||
|
@ -1114,7 +1114,7 @@ public final class NetUtil {
|
|||||||
* @return the host string
|
* @return the host string
|
||||||
*/
|
*/
|
||||||
public static String getHostname(InetSocketAddress addr) {
|
public static String getHostname(InetSocketAddress addr) {
|
||||||
return PlatformDependent.javaVersion() >= 7 ? addr.getHostString() : addr.getHostName();
|
return addr.getHostString();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -441,12 +441,6 @@ public final class NativeLibraryLoader {
|
|||||||
private static final class NoexecVolumeDetector {
|
private static final class NoexecVolumeDetector {
|
||||||
|
|
||||||
private static boolean canExecuteExecutable(File file) throws IOException {
|
private static boolean canExecuteExecutable(File file) throws IOException {
|
||||||
if (PlatformDependent.javaVersion() < 7) {
|
|
||||||
// Pre-JDK7, the Java API did not directly support POSIX permissions; instead of implementing a custom
|
|
||||||
// work-around, assume true, which disables the check.
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// If we can already execute, there is nothing to do.
|
// If we can already execute, there is nothing to do.
|
||||||
if (file.canExecute()) {
|
if (file.canExecute()) {
|
||||||
return true;
|
return true;
|
||||||
|
@ -40,7 +40,6 @@ import java.util.List;
|
|||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Queue;
|
import java.util.Queue;
|
||||||
import java.util.concurrent.ConcurrentLinkedDeque;
|
import java.util.concurrent.ConcurrentLinkedDeque;
|
||||||
import java.util.concurrent.LinkedBlockingDeque;
|
|
||||||
import java.util.concurrent.atomic.AtomicLong;
|
import java.util.concurrent.atomic.AtomicLong;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
@ -867,11 +866,7 @@ public final class PlatformDependent {
|
|||||||
* Returns a new concurrent {@link Deque}.
|
* Returns a new concurrent {@link Deque}.
|
||||||
*/
|
*/
|
||||||
public static <C> Deque<C> newConcurrentDeque() {
|
public static <C> Deque<C> newConcurrentDeque() {
|
||||||
if (javaVersion() < 7) {
|
return new ConcurrentLinkedDeque<>();
|
||||||
return new LinkedBlockingDeque<>();
|
|
||||||
} else {
|
|
||||||
return new ConcurrentLinkedDeque<>();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean isWindows0() {
|
private static boolean isWindows0() {
|
||||||
|
@ -186,14 +186,7 @@ public final class SocketUtils {
|
|||||||
return AccessController.doPrivileged(new PrivilegedAction<InetAddress>() {
|
return AccessController.doPrivileged(new PrivilegedAction<InetAddress>() {
|
||||||
@Override
|
@Override
|
||||||
public InetAddress run() {
|
public InetAddress run() {
|
||||||
if (PlatformDependent.javaVersion() >= 7) {
|
return InetAddress.getLoopbackAddress();
|
||||||
return InetAddress.getLoopbackAddress();
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
return InetAddress.getByName(null);
|
|
||||||
} catch (UnknownHostException e) {
|
|
||||||
throw new IllegalStateException(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -54,15 +54,8 @@ public final class ThrowableUtil {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean haveSuppressed() {
|
|
||||||
return PlatformDependent.javaVersion() >= 7;
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressJava6Requirement(reason = "Throwable addSuppressed is only available for >= 7. Has check for < 7.")
|
@SuppressJava6Requirement(reason = "Throwable addSuppressed is only available for >= 7. Has check for < 7.")
|
||||||
public static void addSuppressed(Throwable target, Throwable suppressed) {
|
public static void addSuppressed(Throwable target, Throwable suppressed) {
|
||||||
if (!haveSuppressed()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
target.addSuppressed(suppressed);
|
target.addSuppressed(suppressed);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,9 +32,7 @@ public class NativeLibraryLoaderTest {
|
|||||||
fail();
|
fail();
|
||||||
} catch (UnsatisfiedLinkError error) {
|
} catch (UnsatisfiedLinkError error) {
|
||||||
assertTrue(error.getCause() instanceof FileNotFoundException);
|
assertTrue(error.getCause() instanceof FileNotFoundException);
|
||||||
if (PlatformDependent.javaVersion() >= 7) {
|
verifySuppressedException(error, UnsatisfiedLinkError.class);
|
||||||
verifySuppressedException(error, UnsatisfiedLinkError.class);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -45,9 +43,7 @@ public class NativeLibraryLoaderTest {
|
|||||||
fail();
|
fail();
|
||||||
} catch (UnsatisfiedLinkError error) {
|
} catch (UnsatisfiedLinkError error) {
|
||||||
assertTrue(error.getCause() instanceof FileNotFoundException);
|
assertTrue(error.getCause() instanceof FileNotFoundException);
|
||||||
if (PlatformDependent.javaVersion() >= 7) {
|
verifySuppressedException(error, ClassNotFoundException.class);
|
||||||
verifySuppressedException(error, ClassNotFoundException.class);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,7 +44,7 @@ final class Conscrypt {
|
|||||||
* Indicates whether or not conscrypt is available on the current system.
|
* Indicates whether or not conscrypt is available on the current system.
|
||||||
*/
|
*/
|
||||||
static boolean isAvailable() {
|
static boolean isAvailable() {
|
||||||
return IS_CONSCRYPT_SSLENGINE != null && PlatformDependent.javaVersion() >= 8;
|
return IS_CONSCRYPT_SSLENGINE != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
static boolean isEngineSupported(SSLEngine engine) {
|
static boolean isEngineSupported(SSLEngine engine) {
|
||||||
|
@ -94,7 +94,7 @@ final class OpenSslTlsv13X509ExtendedTrustManager extends X509ExtendedTrustManag
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SSLSession getHandshakeSession() {
|
public SSLSession getHandshakeSession() {
|
||||||
if (PlatformDependent.javaVersion() >= 7 && session instanceof ExtendedOpenSslSession) {
|
if (session instanceof ExtendedOpenSslSession) {
|
||||||
final ExtendedOpenSslSession extendedOpenSslSession = (ExtendedOpenSslSession) session;
|
final ExtendedOpenSslSession extendedOpenSslSession = (ExtendedOpenSslSession) session;
|
||||||
return new ExtendedOpenSslSession(extendedOpenSslSession) {
|
return new ExtendedOpenSslSession(extendedOpenSslSession) {
|
||||||
@Override
|
@Override
|
||||||
|
@ -599,7 +599,7 @@ public abstract class ReferenceCountedOpenSslContext extends SslContext implemen
|
|||||||
}
|
}
|
||||||
|
|
||||||
static boolean useExtendedTrustManager(X509TrustManager trustManager) {
|
static boolean useExtendedTrustManager(X509TrustManager trustManager) {
|
||||||
return PlatformDependent.javaVersion() >= 7 && trustManager instanceof X509ExtendedTrustManager;
|
return trustManager instanceof X509ExtendedTrustManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -673,31 +673,29 @@ public abstract class ReferenceCountedOpenSslContext extends SslContext implemen
|
|||||||
if (cause instanceof CertificateNotYetValidException) {
|
if (cause instanceof CertificateNotYetValidException) {
|
||||||
return CertificateVerifier.X509_V_ERR_CERT_NOT_YET_VALID;
|
return CertificateVerifier.X509_V_ERR_CERT_NOT_YET_VALID;
|
||||||
}
|
}
|
||||||
if (PlatformDependent.javaVersion() >= 7) {
|
if (cause instanceof CertificateRevokedException) {
|
||||||
if (cause instanceof CertificateRevokedException) {
|
return CertificateVerifier.X509_V_ERR_CERT_REVOKED;
|
||||||
return CertificateVerifier.X509_V_ERR_CERT_REVOKED;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// The X509TrustManagerImpl uses a Validator which wraps a CertPathValidatorException into
|
// The X509TrustManagerImpl uses a Validator which wraps a CertPathValidatorException into
|
||||||
// an CertificateException. So we need to handle the wrapped CertPathValidatorException to be
|
// an CertificateException. So we need to handle the wrapped CertPathValidatorException to be
|
||||||
// able to send the correct alert.
|
// able to send the correct alert.
|
||||||
Throwable wrapped = cause.getCause();
|
Throwable wrapped = cause.getCause();
|
||||||
while (wrapped != null) {
|
while (wrapped != null) {
|
||||||
if (wrapped instanceof CertPathValidatorException) {
|
if (wrapped instanceof CertPathValidatorException) {
|
||||||
CertPathValidatorException ex = (CertPathValidatorException) wrapped;
|
CertPathValidatorException ex = (CertPathValidatorException) wrapped;
|
||||||
CertPathValidatorException.Reason reason = ex.getReason();
|
CertPathValidatorException.Reason reason = ex.getReason();
|
||||||
if (reason == CertPathValidatorException.BasicReason.EXPIRED) {
|
if (reason == CertPathValidatorException.BasicReason.EXPIRED) {
|
||||||
return CertificateVerifier.X509_V_ERR_CERT_HAS_EXPIRED;
|
return CertificateVerifier.X509_V_ERR_CERT_HAS_EXPIRED;
|
||||||
}
|
}
|
||||||
if (reason == CertPathValidatorException.BasicReason.NOT_YET_VALID) {
|
if (reason == CertPathValidatorException.BasicReason.NOT_YET_VALID) {
|
||||||
return CertificateVerifier.X509_V_ERR_CERT_NOT_YET_VALID;
|
return CertificateVerifier.X509_V_ERR_CERT_NOT_YET_VALID;
|
||||||
}
|
}
|
||||||
if (reason == CertPathValidatorException.BasicReason.REVOKED) {
|
if (reason == CertPathValidatorException.BasicReason.REVOKED) {
|
||||||
return CertificateVerifier.X509_V_ERR_CERT_REVOKED;
|
return CertificateVerifier.X509_V_ERR_CERT_REVOKED;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
wrapped = wrapped.getCause();
|
|
||||||
}
|
}
|
||||||
|
wrapped = wrapped.getCause();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Could not detect a specific error code to use, so fallback to a default code.
|
// Could not detect a specific error code to use, so fallback to a default code.
|
||||||
|
@ -246,82 +246,78 @@ public class ReferenceCountedOpenSslEngine extends SSLEngine implements Referenc
|
|||||||
this.alloc = checkNotNull(alloc, "alloc");
|
this.alloc = checkNotNull(alloc, "alloc");
|
||||||
apn = (OpenSslApplicationProtocolNegotiator) context.applicationProtocolNegotiator();
|
apn = (OpenSslApplicationProtocolNegotiator) context.applicationProtocolNegotiator();
|
||||||
clientMode = context.isClient();
|
clientMode = context.isClient();
|
||||||
if (PlatformDependent.javaVersion() >= 7) {
|
session = new ExtendedOpenSslSession(new DefaultOpenSslSession(context.sessionContext())) {
|
||||||
session = new ExtendedOpenSslSession(new DefaultOpenSslSession(context.sessionContext())) {
|
private String[] peerSupportedSignatureAlgorithms;
|
||||||
private String[] peerSupportedSignatureAlgorithms;
|
private List requestedServerNames;
|
||||||
private List requestedServerNames;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List getRequestedServerNames() {
|
public List getRequestedServerNames() {
|
||||||
if (clientMode) {
|
if (clientMode) {
|
||||||
return Java8SslUtils.getSniHostNames(sniHostNames);
|
return Java8SslUtils.getSniHostNames(sniHostNames);
|
||||||
} else {
|
} else {
|
||||||
synchronized (ReferenceCountedOpenSslEngine.this) {
|
synchronized (ReferenceCountedOpenSslEngine.this) {
|
||||||
if (requestedServerNames == null) {
|
if (requestedServerNames == null) {
|
||||||
if (isDestroyed()) {
|
if (isDestroyed()) {
|
||||||
|
requestedServerNames = Collections.emptyList();
|
||||||
|
} else {
|
||||||
|
String name = SSL.getSniHostname(ssl);
|
||||||
|
if (name == null) {
|
||||||
requestedServerNames = Collections.emptyList();
|
requestedServerNames = Collections.emptyList();
|
||||||
} else {
|
} else {
|
||||||
String name = SSL.getSniHostname(ssl);
|
// Convert to bytes as we do not want to do any strict validation of the
|
||||||
if (name == null) {
|
// SNIHostName while creating it.
|
||||||
requestedServerNames = Collections.emptyList();
|
requestedServerNames =
|
||||||
} else {
|
Java8SslUtils.getSniHostName(
|
||||||
// Convert to bytes as we do not want to do any strict validation of the
|
SSL.getSniHostname(ssl).getBytes(CharsetUtil.UTF_8));
|
||||||
// SNIHostName while creating it.
|
|
||||||
requestedServerNames =
|
|
||||||
Java8SslUtils.getSniHostName(
|
|
||||||
SSL.getSniHostname(ssl).getBytes(CharsetUtil.UTF_8));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return requestedServerNames;
|
|
||||||
}
|
}
|
||||||
|
return requestedServerNames;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String[] getPeerSupportedSignatureAlgorithms() {
|
public String[] getPeerSupportedSignatureAlgorithms() {
|
||||||
synchronized (ReferenceCountedOpenSslEngine.this) {
|
synchronized (ReferenceCountedOpenSslEngine.this) {
|
||||||
if (peerSupportedSignatureAlgorithms == null) {
|
if (peerSupportedSignatureAlgorithms == null) {
|
||||||
if (isDestroyed()) {
|
if (isDestroyed()) {
|
||||||
|
peerSupportedSignatureAlgorithms = EmptyArrays.EMPTY_STRINGS;
|
||||||
|
} else {
|
||||||
|
String[] algs = SSL.getSigAlgs(ssl);
|
||||||
|
if (algs == null) {
|
||||||
peerSupportedSignatureAlgorithms = EmptyArrays.EMPTY_STRINGS;
|
peerSupportedSignatureAlgorithms = EmptyArrays.EMPTY_STRINGS;
|
||||||
} else {
|
} else {
|
||||||
String[] algs = SSL.getSigAlgs(ssl);
|
Set<String> algorithmList = new LinkedHashSet<>(algs.length);
|
||||||
if (algs == null) {
|
for (String alg: algs) {
|
||||||
peerSupportedSignatureAlgorithms = EmptyArrays.EMPTY_STRINGS;
|
String converted = SignatureAlgorithmConverter.toJavaName(alg);
|
||||||
} else {
|
|
||||||
Set<String> algorithmList = new LinkedHashSet<>(algs.length);
|
|
||||||
for (String alg: algs) {
|
|
||||||
String converted = SignatureAlgorithmConverter.toJavaName(alg);
|
|
||||||
|
|
||||||
if (converted != null) {
|
if (converted != null) {
|
||||||
algorithmList.add(converted);
|
algorithmList.add(converted);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
peerSupportedSignatureAlgorithms = algorithmList.toArray(new String[0]);
|
|
||||||
}
|
}
|
||||||
|
peerSupportedSignatureAlgorithms = algorithmList.toArray(new String[0]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return peerSupportedSignatureAlgorithms.clone();
|
|
||||||
}
|
}
|
||||||
|
return peerSupportedSignatureAlgorithms.clone();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<byte[]> getStatusResponses() {
|
public List<byte[]> getStatusResponses() {
|
||||||
byte[] ocspResponse = null;
|
byte[] ocspResponse = null;
|
||||||
if (enableOcsp && clientMode) {
|
if (enableOcsp && clientMode) {
|
||||||
synchronized (ReferenceCountedOpenSslEngine.this) {
|
synchronized (ReferenceCountedOpenSslEngine.this) {
|
||||||
if (!isDestroyed()) {
|
if (!isDestroyed()) {
|
||||||
ocspResponse = SSL.getOcspResponse(ssl);
|
ocspResponse = SSL.getOcspResponse(ssl);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return ocspResponse == null ?
|
|
||||||
Collections.<byte[]>emptyList() : Collections.singletonList(ocspResponse);
|
|
||||||
}
|
}
|
||||||
};
|
return ocspResponse == null ?
|
||||||
} else {
|
Collections.<byte[]>emptyList() : Collections.singletonList(ocspResponse);
|
||||||
session = new DefaultOpenSslSession(context.sessionContext());
|
}
|
||||||
}
|
};
|
||||||
engineMap = context.engineMap;
|
engineMap = context.engineMap;
|
||||||
enableOcsp = context.enableOcsp;
|
enableOcsp = context.enableOcsp;
|
||||||
// context.keyCertChain will only be non-null if we do not use the KeyManagerFactory. In this case
|
// context.keyCertChain will only be non-null if we do not use the KeyManagerFactory. In this case
|
||||||
|
@ -168,13 +168,10 @@ public final class ReferenceCountedOpenSslServerContext extends ReferenceCounted
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (PlatformDependent.javaVersion() >= 8) {
|
// IMPORTANT: The callbacks set for hostname matching must be static to prevent memory leak as
|
||||||
// Only do on Java8+ as SNIMatcher is not supported in earlier releases.
|
// otherwise the context can never be collected. This is because the JNI code holds
|
||||||
// IMPORTANT: The callbacks set for hostname matching must be static to prevent memory leak as
|
// a global reference to the matcher.
|
||||||
// otherwise the context can never be collected. This is because the JNI code holds
|
SSLContext.setSniHostnameMatcher(ctx, new OpenSslSniHostnameMatcher(engineMap));
|
||||||
// a global reference to the matcher.
|
|
||||||
SSLContext.setSniHostnameMatcher(ctx, new OpenSslSniHostnameMatcher(engineMap));
|
|
||||||
}
|
|
||||||
} catch (SSLException e) {
|
} catch (SSLException e) {
|
||||||
throw e;
|
throw e;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
@ -1133,8 +1133,7 @@ public class SslHandler extends ByteToMessageDecoder implements ChannelOutboundH
|
|||||||
}
|
}
|
||||||
|
|
||||||
// also match against SctpChannel via String matching as it may not present.
|
// also match against SctpChannel via String matching as it may not present.
|
||||||
if (PlatformDependent.javaVersion() >= 7
|
if ("com.sun.nio.sctp.SctpChannel".equals(clazz.getSuperclass().getName())) {
|
||||||
&& "com.sun.nio.sctp.SctpChannel".equals(clazz.getSuperclass().getName())) {
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
} catch (Throwable cause) {
|
} catch (Throwable cause) {
|
||||||
|
@ -135,12 +135,10 @@ public abstract class SimpleTrustManagerFactory extends TrustManagerFactory {
|
|||||||
TrustManager[] trustManagers = this.trustManagers;
|
TrustManager[] trustManagers = this.trustManagers;
|
||||||
if (trustManagers == null) {
|
if (trustManagers == null) {
|
||||||
trustManagers = parent.engineGetTrustManagers();
|
trustManagers = parent.engineGetTrustManagers();
|
||||||
if (PlatformDependent.javaVersion() >= 7) {
|
for (int i = 0; i < trustManagers.length; i++) {
|
||||||
for (int i = 0; i < trustManagers.length; i++) {
|
final TrustManager tm = trustManagers[i];
|
||||||
final TrustManager tm = trustManagers[i];
|
if (tm instanceof X509TrustManager && !(tm instanceof X509ExtendedTrustManager)) {
|
||||||
if (tm instanceof X509TrustManager && !(tm instanceof X509ExtendedTrustManager)) {
|
trustManagers[i] = new X509TrustManagerWrapper((X509TrustManager) tm);
|
||||||
trustManagers[i] = new X509TrustManagerWrapper((X509TrustManager) tm);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.trustManagers = trustManagers;
|
this.trustManagers = trustManagers;
|
||||||
|
@ -1038,7 +1038,6 @@ public class OpenSslEngineTest extends SSLEngineTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSNIMatchersDoesNotThrow() throws Exception {
|
public void testSNIMatchersDoesNotThrow() throws Exception {
|
||||||
assumeTrue(PlatformDependent.javaVersion() >= 8);
|
|
||||||
SelfSignedCertificate ssc = new SelfSignedCertificate();
|
SelfSignedCertificate ssc = new SelfSignedCertificate();
|
||||||
serverSslCtx = SslContextBuilder.forServer(ssc.certificate(), ssc.privateKey())
|
serverSslCtx = SslContextBuilder.forServer(ssc.certificate(), ssc.privateKey())
|
||||||
.sslProvider(sslServerProvider())
|
.sslProvider(sslServerProvider())
|
||||||
@ -1059,7 +1058,6 @@ public class OpenSslEngineTest extends SSLEngineTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSNIMatchersWithSNINameWithUnderscore() throws Exception {
|
public void testSNIMatchersWithSNINameWithUnderscore() throws Exception {
|
||||||
assumeTrue(PlatformDependent.javaVersion() >= 8);
|
|
||||||
byte[] name = "rb8hx3pww30y3tvw0mwy.v1_1".getBytes(CharsetUtil.UTF_8);
|
byte[] name = "rb8hx3pww30y3tvw0mwy.v1_1".getBytes(CharsetUtil.UTF_8);
|
||||||
SelfSignedCertificate ssc = new SelfSignedCertificate();
|
SelfSignedCertificate ssc = new SelfSignedCertificate();
|
||||||
serverSslCtx = SslContextBuilder.forServer(ssc.certificate(), ssc.privateKey())
|
serverSslCtx = SslContextBuilder.forServer(ssc.certificate(), ssc.privateKey())
|
||||||
@ -1138,10 +1136,7 @@ public class OpenSslEngineTest extends SSLEngineTest {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected SSLEngine wrapEngine(SSLEngine engine) {
|
protected SSLEngine wrapEngine(SSLEngine engine) {
|
||||||
if (PlatformDependent.javaVersion() >= 8) {
|
return Java8SslTestUtils.wrapSSLEngineForTesting(engine);
|
||||||
return Java8SslTestUtils.wrapSSLEngineForTesting(engine);
|
|
||||||
}
|
|
||||||
return engine;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ReferenceCountedOpenSslEngine unwrapEngine(SSLEngine engine) {
|
ReferenceCountedOpenSslEngine unwrapEngine(SSLEngine engine) {
|
||||||
|
@ -83,13 +83,11 @@ public class SniClientTest {
|
|||||||
|
|
||||||
@Test(timeout = 30000)
|
@Test(timeout = 30000)
|
||||||
public void testSniSNIMatcherMatchesClient() throws Exception {
|
public void testSniSNIMatcherMatchesClient() throws Exception {
|
||||||
Assume.assumeTrue(PlatformDependent.javaVersion() >= 8);
|
|
||||||
SniClientJava8TestUtil.testSniClient(serverProvider, clientProvider, true);
|
SniClientJava8TestUtil.testSniClient(serverProvider, clientProvider, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(timeout = 30000, expected = SSLException.class)
|
@Test(timeout = 30000, expected = SSLException.class)
|
||||||
public void testSniSNIMatcherDoesNotMatchClient() throws Exception {
|
public void testSniSNIMatcherDoesNotMatchClient() throws Exception {
|
||||||
Assume.assumeTrue(PlatformDependent.javaVersion() >= 8);
|
|
||||||
SniClientJava8TestUtil.testSniClient(serverProvider, clientProvider, false);
|
SniClientJava8TestUtil.testSniClient(serverProvider, clientProvider, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -111,10 +109,7 @@ public class SniClientTest {
|
|||||||
.build();
|
.build();
|
||||||
} else {
|
} else {
|
||||||
// The used OpenSSL version does support a KeyManagerFactory, so use it.
|
// The used OpenSSL version does support a KeyManagerFactory, so use it.
|
||||||
KeyManagerFactory kmf = PlatformDependent.javaVersion() >= 8 ?
|
KeyManagerFactory kmf = SniClientJava8TestUtil.newSniX509KeyManagerFactory(cert, sniHostName);
|
||||||
SniClientJava8TestUtil.newSniX509KeyManagerFactory(cert, sniHostName) :
|
|
||||||
SslContext.buildKeyManagerFactory(
|
|
||||||
new X509Certificate[] { cert.cert() }, cert.key(), null, null);
|
|
||||||
|
|
||||||
sslServerContext = SslContextBuilder.forServer(kmf)
|
sslServerContext = SslContextBuilder.forServer(kmf)
|
||||||
.sslProvider(sslServerProvider)
|
.sslProvider(sslServerProvider)
|
||||||
@ -137,9 +132,7 @@ public class SniClientTest {
|
|||||||
}
|
}
|
||||||
}).bind(address).syncUninterruptibly().channel();
|
}).bind(address).syncUninterruptibly().channel();
|
||||||
|
|
||||||
TrustManagerFactory tmf = PlatformDependent.javaVersion() >= 8 ?
|
TrustManagerFactory tmf = SniClientJava8TestUtil.newSniX509TrustmanagerFactory(sniHostName);
|
||||||
SniClientJava8TestUtil.newSniX509TrustmanagerFactory(sniHostName) :
|
|
||||||
InsecureTrustManagerFactory.INSTANCE;
|
|
||||||
sslClientContext = SslContextBuilder.forClient().trustManager(tmf)
|
sslClientContext = SslContextBuilder.forClient().trustManager(tmf)
|
||||||
.sslProvider(sslClientProvider).build();
|
.sslProvider(sslClientProvider).build();
|
||||||
Bootstrap cb = new Bootstrap();
|
Bootstrap cb = new Bootstrap();
|
||||||
@ -154,10 +147,8 @@ public class SniClientTest {
|
|||||||
handler.handshakeFuture().syncUninterruptibly();
|
handler.handshakeFuture().syncUninterruptibly();
|
||||||
Assert.assertNull(handler.engine().getHandshakeSession());
|
Assert.assertNull(handler.engine().getHandshakeSession());
|
||||||
|
|
||||||
if (PlatformDependent.javaVersion() >= 8) {
|
SniClientJava8TestUtil.assertSSLSession(
|
||||||
SniClientJava8TestUtil.assertSSLSession(
|
handler.engine().getUseClientMode(), handler.engine().getSession(), sniHostName);
|
||||||
handler.engine().getUseClientMode(), handler.engine().getSession(), sniHostName);
|
|
||||||
}
|
|
||||||
} finally {
|
} finally {
|
||||||
if (cc != null) {
|
if (cc != null) {
|
||||||
cc.close().syncUninterruptibly();
|
cc.close().syncUninterruptibly();
|
||||||
|
@ -45,10 +45,7 @@ public class DefaultAuthoritativeDnsServerCache implements AuthoritativeDnsServe
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean equals(InetSocketAddress entry, InetSocketAddress otherEntry) {
|
protected boolean equals(InetSocketAddress entry, InetSocketAddress otherEntry) {
|
||||||
if (PlatformDependent.javaVersion() >= 7) {
|
return entry.getHostString().equalsIgnoreCase(otherEntry.getHostString());
|
||||||
return entry.getHostString().equalsIgnoreCase(otherEntry.getHostString());
|
|
||||||
}
|
|
||||||
return entry.getHostName().equalsIgnoreCase(otherEntry.getHostName());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -101,7 +98,7 @@ public class DefaultAuthoritativeDnsServerCache implements AuthoritativeDnsServe
|
|||||||
checkNotNull(address, "address");
|
checkNotNull(address, "address");
|
||||||
checkNotNull(loop, "loop");
|
checkNotNull(loop, "loop");
|
||||||
|
|
||||||
if (PlatformDependent.javaVersion() >= 7 && address.getHostString() == null) {
|
if (address.getHostString() == null) {
|
||||||
// We only cache addresses that have also a host string as we will need it later when trying to replace
|
// We only cache addresses that have also a host string as we will need it later when trying to replace
|
||||||
// unresolved entries in the cache.
|
// unresolved entries in the cache.
|
||||||
return;
|
return;
|
||||||
|
@ -400,8 +400,7 @@ abstract class DnsResolveContext<T> {
|
|||||||
final DnsQueryLifecycleObserver queryLifecycleObserver,
|
final DnsQueryLifecycleObserver queryLifecycleObserver,
|
||||||
final Promise<List<T>> promise,
|
final Promise<List<T>> promise,
|
||||||
final Throwable cause) {
|
final Throwable cause) {
|
||||||
final String nameServerName = PlatformDependent.javaVersion() >= 7 ?
|
final String nameServerName = nameServerAddr.getHostString();
|
||||||
nameServerAddr.getHostString() : nameServerAddr.getHostName();
|
|
||||||
assert nameServerName != null;
|
assert nameServerName != null;
|
||||||
|
|
||||||
// Placeholder so we will not try to finish the original query yet.
|
// Placeholder so we will not try to finish the original query yet.
|
||||||
|
@ -1281,8 +1281,7 @@ public class DnsNameResolverTest {
|
|||||||
|
|
||||||
// Java7 will strip of the "." so we need to adjust the expected dnsname. Both are valid in terms of the RFC
|
// Java7 will strip of the "." so we need to adjust the expected dnsname. Both are valid in terms of the RFC
|
||||||
// so its ok.
|
// so its ok.
|
||||||
String expectedDnsName = PlatformDependent.javaVersion() == 7 ?
|
String expectedDnsName = "dns4.some.record.netty.io.";
|
||||||
"dns4.some.record.netty.io" : "dns4.some.record.netty.io.";
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
resolver.resolveAll(hostname).syncUninterruptibly();
|
resolver.resolveAll(hostname).syncUninterruptibly();
|
||||||
|
@ -43,17 +43,15 @@ public final class UnixChannelUtil {
|
|||||||
|
|
||||||
public static InetSocketAddress computeRemoteAddr(InetSocketAddress remoteAddr, InetSocketAddress osRemoteAddr) {
|
public static InetSocketAddress computeRemoteAddr(InetSocketAddress remoteAddr, InetSocketAddress osRemoteAddr) {
|
||||||
if (osRemoteAddr != null) {
|
if (osRemoteAddr != null) {
|
||||||
if (PlatformDependent.javaVersion() >= 7) {
|
try {
|
||||||
try {
|
// Only try to construct a new InetSocketAddress if we using java >= 7 as getHostString() does not
|
||||||
// Only try to construct a new InetSocketAddress if we using java >= 7 as getHostString() does not
|
// exists in earlier releases and so the retrieval of the hostname could block the EventLoop if a
|
||||||
// exists in earlier releases and so the retrieval of the hostname could block the EventLoop if a
|
// reverse lookup would be needed.
|
||||||
// reverse lookup would be needed.
|
return new InetSocketAddress(InetAddress.getByAddress(remoteAddr.getHostString(),
|
||||||
return new InetSocketAddress(InetAddress.getByAddress(remoteAddr.getHostString(),
|
osRemoteAddr.getAddress().getAddress()),
|
||||||
osRemoteAddr.getAddress().getAddress()),
|
osRemoteAddr.getPort());
|
||||||
osRemoteAddr.getPort());
|
} catch (UnknownHostException ignore) {
|
||||||
} catch (UnknownHostException ignore) {
|
// Should never happen but fallback to osRemoteAddr anyway.
|
||||||
// Should never happen but fallback to osRemoteAddr anyway.
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return osRemoteAddr;
|
return osRemoteAddr;
|
||||||
}
|
}
|
||||||
|
@ -104,9 +104,6 @@ public final class NioDatagramChannel
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static void checkJavaVersion() {
|
private static void checkJavaVersion() {
|
||||||
if (PlatformDependent.javaVersion() < 7) {
|
|
||||||
throw new UnsupportedOperationException("Only supported on java 7+.");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -194,11 +191,7 @@ public final class NioDatagramChannel
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void doBind0(SocketAddress localAddress) throws Exception {
|
private void doBind0(SocketAddress localAddress) throws Exception {
|
||||||
if (PlatformDependent.javaVersion() >= 7) {
|
SocketUtils.bind(javaChannel(), localAddress);
|
||||||
SocketUtils.bind(javaChannel(), localAddress);
|
|
||||||
} else {
|
|
||||||
javaChannel().socket().bind(localAddress);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -210,7 +210,7 @@ class NioDatagramChannelConfig extends DefaultDatagramChannelConfig {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <T> boolean setOption(ChannelOption<T> option, T value) {
|
public <T> boolean setOption(ChannelOption<T> option, T value) {
|
||||||
if (PlatformDependent.javaVersion() >= 7 && option instanceof NioChannelOption) {
|
if (option instanceof NioChannelOption) {
|
||||||
return NioChannelOption.setOption(javaChannel, (NioChannelOption<T>) option, value);
|
return NioChannelOption.setOption(javaChannel, (NioChannelOption<T>) option, value);
|
||||||
}
|
}
|
||||||
return super.setOption(option, value);
|
return super.setOption(option, value);
|
||||||
@ -218,7 +218,7 @@ class NioDatagramChannelConfig extends DefaultDatagramChannelConfig {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <T> T getOption(ChannelOption<T> option) {
|
public <T> T getOption(ChannelOption<T> option) {
|
||||||
if (PlatformDependent.javaVersion() >= 7 && option instanceof NioChannelOption) {
|
if (option instanceof NioChannelOption) {
|
||||||
return NioChannelOption.getOption(javaChannel, (NioChannelOption<T>) option);
|
return NioChannelOption.getOption(javaChannel, (NioChannelOption<T>) option);
|
||||||
}
|
}
|
||||||
return super.getOption(option);
|
return super.getOption(option);
|
||||||
@ -227,9 +227,6 @@ class NioDatagramChannelConfig extends DefaultDatagramChannelConfig {
|
|||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@Override
|
@Override
|
||||||
public Map<ChannelOption<?>, Object> getOptions() {
|
public Map<ChannelOption<?>, Object> getOptions() {
|
||||||
if (PlatformDependent.javaVersion() >= 7) {
|
return getOptions(super.getOptions(), NioChannelOption.getOptions(javaChannel));
|
||||||
return getOptions(super.getOptions(), NioChannelOption.getOptions(javaChannel));
|
|
||||||
}
|
|
||||||
return super.getOptions();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -137,11 +137,7 @@ public class NioServerSocketChannel extends AbstractNioMessageChannel
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void doBind(SocketAddress localAddress) throws Exception {
|
protected void doBind(SocketAddress localAddress) throws Exception {
|
||||||
if (PlatformDependent.javaVersion() >= 7) {
|
javaChannel().bind(localAddress, config.getBacklog());
|
||||||
javaChannel().bind(localAddress, config.getBacklog());
|
|
||||||
} else {
|
|
||||||
javaChannel().socket().bind(localAddress, config.getBacklog());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -215,7 +211,7 @@ public class NioServerSocketChannel extends AbstractNioMessageChannel
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <T> boolean setOption(ChannelOption<T> option, T value) {
|
public <T> boolean setOption(ChannelOption<T> option, T value) {
|
||||||
if (PlatformDependent.javaVersion() >= 7 && option instanceof NioChannelOption) {
|
if (option instanceof NioChannelOption) {
|
||||||
return NioChannelOption.setOption(jdkChannel(), (NioChannelOption<T>) option, value);
|
return NioChannelOption.setOption(jdkChannel(), (NioChannelOption<T>) option, value);
|
||||||
}
|
}
|
||||||
return super.setOption(option, value);
|
return super.setOption(option, value);
|
||||||
@ -223,7 +219,7 @@ public class NioServerSocketChannel extends AbstractNioMessageChannel
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <T> T getOption(ChannelOption<T> option) {
|
public <T> T getOption(ChannelOption<T> option) {
|
||||||
if (PlatformDependent.javaVersion() >= 7 && option instanceof NioChannelOption) {
|
if (option instanceof NioChannelOption) {
|
||||||
return NioChannelOption.getOption(jdkChannel(), (NioChannelOption<T>) option);
|
return NioChannelOption.getOption(jdkChannel(), (NioChannelOption<T>) option);
|
||||||
}
|
}
|
||||||
return super.getOption(option);
|
return super.getOption(option);
|
||||||
@ -232,10 +228,7 @@ public class NioServerSocketChannel extends AbstractNioMessageChannel
|
|||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@Override
|
@Override
|
||||||
public Map<ChannelOption<?>, Object> getOptions() {
|
public Map<ChannelOption<?>, Object> getOptions() {
|
||||||
if (PlatformDependent.javaVersion() >= 7) {
|
return getOptions(super.getOptions(), NioChannelOption.getOptions(jdkChannel()));
|
||||||
return getOptions(super.getOptions(), NioChannelOption.getOptions(jdkChannel()));
|
|
||||||
}
|
|
||||||
return super.getOptions();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private ServerSocketChannel jdkChannel() {
|
private ServerSocketChannel jdkChannel() {
|
||||||
|
@ -156,11 +156,7 @@ public class NioSocketChannel extends AbstractNioByteChannel implements io.netty
|
|||||||
@UnstableApi
|
@UnstableApi
|
||||||
@Override
|
@Override
|
||||||
protected final void doShutdownOutput() throws Exception {
|
protected final void doShutdownOutput() throws Exception {
|
||||||
if (PlatformDependent.javaVersion() >= 7) {
|
javaChannel().shutdownOutput();
|
||||||
javaChannel().shutdownOutput();
|
|
||||||
} else {
|
|
||||||
javaChannel().socket().shutdownOutput();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -272,11 +268,7 @@ public class NioSocketChannel extends AbstractNioByteChannel implements io.netty
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void shutdownInput0() throws Exception {
|
private void shutdownInput0() throws Exception {
|
||||||
if (PlatformDependent.javaVersion() >= 7) {
|
javaChannel().shutdownInput();
|
||||||
javaChannel().shutdownInput();
|
|
||||||
} else {
|
|
||||||
javaChannel().socket().shutdownInput();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -295,11 +287,7 @@ public class NioSocketChannel extends AbstractNioByteChannel implements io.netty
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void doBind0(SocketAddress localAddress) throws Exception {
|
private void doBind0(SocketAddress localAddress) throws Exception {
|
||||||
if (PlatformDependent.javaVersion() >= 7) {
|
SocketUtils.bind(javaChannel(), localAddress);
|
||||||
SocketUtils.bind(javaChannel(), localAddress);
|
|
||||||
} else {
|
|
||||||
SocketUtils.bind(javaChannel().socket(), localAddress);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -483,7 +471,7 @@ public class NioSocketChannel extends AbstractNioByteChannel implements io.netty
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <T> boolean setOption(ChannelOption<T> option, T value) {
|
public <T> boolean setOption(ChannelOption<T> option, T value) {
|
||||||
if (PlatformDependent.javaVersion() >= 7 && option instanceof NioChannelOption) {
|
if (option instanceof NioChannelOption) {
|
||||||
return NioChannelOption.setOption(jdkChannel(), (NioChannelOption<T>) option, value);
|
return NioChannelOption.setOption(jdkChannel(), (NioChannelOption<T>) option, value);
|
||||||
}
|
}
|
||||||
return super.setOption(option, value);
|
return super.setOption(option, value);
|
||||||
@ -491,7 +479,7 @@ public class NioSocketChannel extends AbstractNioByteChannel implements io.netty
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <T> T getOption(ChannelOption<T> option) {
|
public <T> T getOption(ChannelOption<T> option) {
|
||||||
if (PlatformDependent.javaVersion() >= 7 && option instanceof NioChannelOption) {
|
if (option instanceof NioChannelOption) {
|
||||||
return NioChannelOption.getOption(jdkChannel(), (NioChannelOption<T>) option);
|
return NioChannelOption.getOption(jdkChannel(), (NioChannelOption<T>) option);
|
||||||
}
|
}
|
||||||
return super.getOption(option);
|
return super.getOption(option);
|
||||||
@ -500,10 +488,7 @@ public class NioSocketChannel extends AbstractNioByteChannel implements io.netty
|
|||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@Override
|
@Override
|
||||||
public Map<ChannelOption<?>, Object> getOptions() {
|
public Map<ChannelOption<?>, Object> getOptions() {
|
||||||
if (PlatformDependent.javaVersion() >= 7) {
|
return getOptions(super.getOptions(), NioChannelOption.getOptions(jdkChannel()));
|
||||||
return getOptions(super.getOptions(), NioChannelOption.getOptions(jdkChannel()));
|
|
||||||
}
|
|
||||||
return super.getOptions();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void setMaxBytesPerGatheringWrite(int maxBytesPerGatheringWrite) {
|
void setMaxBytesPerGatheringWrite(int maxBytesPerGatheringWrite) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user