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