Use @SuppressJava6Requirement for animal sniffer plugin to ensure we always guard correctly (#9655)

Motivation:

We can use the `@SuppressJava6Requirement` annotation to be more precise about when we use Java6+ APIs. This helps us to ensure we always protect these places.

Modifications:

Make use of `@SuppressJava6Requirement` explicit

Result:

Fixes https://github.com/netty/netty/issues/2509.
This commit is contained in:
Norman Maurer 2019-10-14 15:54:49 +02:00 committed by GitHub
parent 833f11be75
commit 6c05d16967
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
31 changed files with 161 additions and 120 deletions

View File

@ -18,6 +18,8 @@ package io.netty.handler.codec.spdy;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufAllocator;
import io.netty.buffer.Unpooled;
import io.netty.util.internal.PlatformDependent;
import io.netty.util.internal.SuppressJava6Requirement;
import java.util.zip.Deflater;
@ -70,11 +72,17 @@ class SpdyHeaderBlockZlibEncoder extends SpdyHeaderBlockRawEncoder {
}
}
@SuppressJava6Requirement(reason = "Guarded by java version check")
private boolean compressInto(ByteBuf compressed) {
byte[] out = compressed.array();
int off = compressed.arrayOffset() + compressed.writerIndex();
int toWrite = compressed.writableBytes();
int numBytes = compressor.deflate(out, off, toWrite, Deflater.SYNC_FLUSH);
final int numBytes;
if (PlatformDependent.javaVersion() >= 7) {
numBytes = compressor.deflate(out, off, toWrite, Deflater.SYNC_FLUSH);
} else {
numBytes = compressor.deflate(out, off, toWrite);
}
compressed.writerIndex(compressed.writerIndex() + numBytes);
return numBytes == toWrite;
}

View File

@ -22,6 +22,8 @@ import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelPromise;
import io.netty.channel.ChannelPromiseNotifier;
import io.netty.util.concurrent.EventExecutor;
import io.netty.util.internal.PlatformDependent;
import io.netty.util.internal.SuppressJava6Requirement;
import java.util.concurrent.TimeUnit;
import java.util.zip.CRC32;
@ -320,7 +322,11 @@ public class JdkZlibEncoder extends ZlibEncoder {
return ctx.writeAndFlush(footer, promise);
}
@SuppressJava6Requirement(reason = "Usage guarded by java version check")
private void deflate(ByteBuf out) {
if (PlatformDependent.javaVersion() < 7) {
deflateJdk6(out);
}
int numBytes;
do {
int writerIndex = out.writerIndex();
@ -330,6 +336,16 @@ public class JdkZlibEncoder extends ZlibEncoder {
} while (numBytes > 0);
}
private void deflateJdk6(ByteBuf out) {
int numBytes;
do {
int writerIndex = out.writerIndex();
numBytes = deflater.deflate(
out.array(), out.arrayOffset() + writerIndex, out.writableBytes());
out.writerIndex(writerIndex + numBytes);
} while (numBytes > 0);
}
@Override
public void handlerAdded(ChannelHandlerContext ctx) throws Exception {
this.ctx = ctx;

View File

@ -17,6 +17,7 @@ package io.netty.util.internal;
import java.util.concurrent.atomic.LongAdder;
@SuppressJava6Requirement(reason = "Usage guarded by java version check")
final class LongAdderCounter extends LongAdder implements LongCounter {
@Override

View File

@ -482,6 +482,7 @@ public final class NativeLibraryLoader {
private static final class NoexecVolumeDetector {
@SuppressJava6Requirement(reason = "Usage guarded by java version check")
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

View File

@ -132,6 +132,7 @@ public final class PlatformDependent {
if (javaVersion() >= 7) {
RANDOM_PROVIDER = new ThreadLocalRandomProvider() {
@Override
@SuppressJava6Requirement(reason = "Usage guarded by java version check")
public Random current() {
return java.util.concurrent.ThreadLocalRandom.current();
}
@ -964,6 +965,7 @@ public final class PlatformDependent {
/**
* Returns a new concurrent {@link Deque}.
*/
@SuppressJava6Requirement(reason = "Usage guarded by java version check")
public static <C> Deque<C> newConcurrentDeque() {
if (javaVersion() < 7) {
return new LinkedBlockingDeque<C>();

View File

@ -33,6 +33,7 @@ import static io.netty.util.internal.ObjectUtil.checkNotNull;
/**
* The {@link PlatformDependent} operations which requires access to {@code sun.misc.*}.
*/
@SuppressJava6Requirement(reason = "Unsafe access is guarded")
final class PlatformDependent0 {
private static final InternalLogger logger = InternalLoggerFactory.getInstance(PlatformDependent0.class);

View File

@ -88,6 +88,7 @@ public final class SocketUtils {
}
}
@SuppressJava6Requirement(reason = "Usage guarded by java version check")
public static void bind(final SocketChannel socketChannel, final SocketAddress address) throws IOException {
try {
AccessController.doPrivileged(new PrivilegedExceptionAction<Void>() {
@ -115,6 +116,7 @@ public final class SocketUtils {
}
}
@SuppressJava6Requirement(reason = "Usage guarded by java version check")
public static void bind(final DatagramChannel networkChannel, final SocketAddress address) throws IOException {
try {
AccessController.doPrivileged(new PrivilegedExceptionAction<Void>() {
@ -182,6 +184,7 @@ public final class SocketUtils {
});
}
@SuppressJava6Requirement(reason = "Usage guarded by java version check")
public static InetAddress loopbackAddress() {
return AccessController.doPrivileged(new PrivilegedAction<InetAddress>() {
@Override

View File

@ -25,7 +25,7 @@ import java.lang.annotation.Target;
* Annotation to suppress the Java 6 source code requirement checks for a method.
*/
@Retention(RetentionPolicy.CLASS)
@Target({ ElementType.METHOD, ElementType.CONSTRUCTOR })
@Target({ ElementType.METHOD, ElementType.CONSTRUCTOR, ElementType.TYPE })
public @interface SuppressJava6Requirement {
String reason();

View File

@ -15,6 +15,8 @@
*/
package io.netty.handler.ssl;
import io.netty.util.internal.SuppressJava6Requirement;
import javax.net.ssl.ExtendedSSLSession;
import javax.net.ssl.SSLException;
import javax.net.ssl.SSLPeerUnverifiedException;
@ -29,6 +31,7 @@ import java.util.List;
* Delegates all operations to a wrapped {@link OpenSslSession} except the methods defined by {@link ExtendedSSLSession}
* itself.
*/
@SuppressJava6Requirement(reason = "Usage guarded by java version check")
abstract class ExtendedOpenSslSession extends ExtendedSSLSession implements OpenSslSession {
// TODO: use OpenSSL API to actually fetch the real data but for now just do what Conscrypt does:

View File

@ -15,6 +15,8 @@
*/
package io.netty.handler.ssl;
import io.netty.util.internal.SuppressJava6Requirement;
import javax.net.ssl.SSLParameters;
import java.security.AlgorithmConstraints;
@ -29,6 +31,7 @@ final class Java7SslParametersUtils {
* {@link AlgorithmConstraints} in the code. This helps us to not get into trouble when using it in java
* version < 7 and especially when using on android.
*/
@SuppressJava6Requirement(reason = "Usage guarded by java version check")
static void setAlgorithmConstraints(SSLParameters sslParameters, Object algorithmConstraints) {
sslParameters.setAlgorithmConstraints((AlgorithmConstraints) algorithmConstraints);
}

View File

@ -15,6 +15,8 @@
*/
package io.netty.handler.ssl;
import io.netty.util.internal.SuppressJava6Requirement;
import javax.net.ssl.SNIHostName;
import javax.net.ssl.SNIMatcher;
import javax.net.ssl.SNIServerName;
@ -25,6 +27,7 @@ import java.util.Collections;
import java.util.Iterator;
import java.util.List;
@SuppressJava6Requirement(reason = "Usage guarded by java version check")
final class Java8SslUtils {
private Java8SslUtils() { }

View File

@ -16,6 +16,7 @@
package io.netty.handler.ssl;
import io.netty.util.internal.StringUtil;
import io.netty.util.internal.SuppressJava6Requirement;
import javax.net.ssl.SSLEngine;
import javax.net.ssl.SSLEngineResult;
@ -30,6 +31,7 @@ import static io.netty.handler.ssl.SslUtils.toSSLHandshakeException;
import static io.netty.handler.ssl.JdkApplicationProtocolNegotiator.ProtocolSelectionListener;
import static io.netty.handler.ssl.JdkApplicationProtocolNegotiator.ProtocolSelector;
@SuppressJava6Requirement(reason = "Usage guarded by java version check")
final class Java9SslEngine extends JdkSslEngine {
private final ProtocolSelectionListener selectionListener;
private final AlpnSelector alpnSelector;

View File

@ -27,9 +27,11 @@ import java.util.function.BiFunction;
import io.netty.util.internal.EmptyArrays;
import io.netty.util.internal.PlatformDependent;
import io.netty.util.internal.SuppressJava6Requirement;
import io.netty.util.internal.logging.InternalLogger;
import io.netty.util.internal.logging.InternalLoggerFactory;
@SuppressJava6Requirement(reason = "Usage guarded by java version check")
final class Java9SslUtils {
private static final InternalLogger logger = InternalLoggerFactory.getInstance(Java9SslUtils.class);
private static final Method SET_APPLICATION_PROTOCOLS;

View File

@ -15,6 +15,8 @@
*/
package io.netty.handler.ssl;
import io.netty.util.internal.SuppressJava6Requirement;
import java.nio.ByteBuffer;
import javax.net.ssl.SSLEngine;
@ -145,6 +147,7 @@ class JdkSslEngine extends SSLEngine implements ApplicationProtocolAccessor {
engine.setEnabledProtocols(strings);
}
@SuppressJava6Requirement(reason = "Can only be called when running on JDK7+")
@Override
public SSLSession getHandshakeSession() {
return engine.getHandshakeSession();

View File

@ -16,6 +16,7 @@
package io.netty.handler.ssl;
import io.netty.util.internal.PlatformDependent;
import io.netty.util.internal.SuppressJava6Requirement;
import javax.net.ssl.SSLEngine;
import javax.net.ssl.SSLPeerUnverifiedException;
@ -35,6 +36,7 @@ import java.util.List;
* default {@link X509ExtendedTrustManager} implementations provided by the JDK that can not handle a protocol version
* of {@code TLSv1.3}.
*/
@SuppressJava6Requirement(reason = "Usage guarded by java version check")
final class OpenSslTlsv13X509ExtendedTrustManager extends X509ExtendedTrustManager {
private final X509ExtendedTrustManager tm;

View File

@ -15,6 +15,8 @@
*/
package io.netty.handler.ssl;
import io.netty.util.internal.SuppressJava6Requirement;
import javax.security.auth.x500.X500Principal;
import java.io.ByteArrayInputStream;
import java.math.BigInteger;
@ -81,7 +83,7 @@ final class OpenSslX509Certificate extends X509Certificate {
}
// No @Override annotation as it was only introduced in Java8.
@Override
@SuppressJava6Requirement(reason = "Can only be called from Java8 as class is package-private")
public void verify(PublicKey key, Provider sigProvider)
throws CertificateException, NoSuchAlgorithmException, InvalidKeyException, SignatureException {
unwrap().verify(key, sigProvider);

View File

@ -17,6 +17,7 @@ package io.netty.handler.ssl;
import io.netty.util.internal.EmptyArrays;
import io.netty.util.internal.PlatformDependent;
import io.netty.util.internal.SuppressJava6Requirement;
import io.netty.util.internal.logging.InternalLogger;
import io.netty.util.internal.logging.InternalLoggerFactory;
@ -39,6 +40,7 @@ import java.security.cert.X509Certificate;
* This is really a "hack" until there is an official API as requested on the in
* <a href="https://bugs.openjdk.java.net/projects/JDK/issues/JDK-8210843">JDK-8210843</a>.
*/
@SuppressJava6Requirement(reason = "Usage guarded by java version check")
final class OpenSslX509TrustManagerWrapper {
private static final InternalLogger LOGGER = InternalLoggerFactory
.getInstance(OpenSslX509TrustManagerWrapper.class);
@ -163,6 +165,7 @@ final class OpenSslX509TrustManagerWrapper {
this.tmOffset = tmOffset;
}
@SuppressJava6Requirement(reason = "Usage guarded by java version check")
@Override
public X509TrustManager wrapIfNeeded(X509TrustManager manager) {
if (!(manager instanceof X509ExtendedTrustManager)) {

View File

@ -16,6 +16,7 @@
package io.netty.handler.ssl;
import io.netty.internal.tcnative.CertificateCallback;
import io.netty.util.internal.SuppressJava6Requirement;
import io.netty.util.internal.logging.InternalLogger;
import io.netty.util.internal.logging.InternalLoggerFactory;
import io.netty.internal.tcnative.SSL;
@ -155,13 +156,7 @@ public final class ReferenceCountedOpenSslClientContext extends ReferenceCounted
//
// See https://github.com/netty/netty/issues/5372
// Use this to prevent an error when running on java < 7
if (useExtendedTrustManager(manager)) {
SSLContext.setCertVerifyCallback(ctx,
new ExtendedTrustManagerVerifyCallback(engineMap, (X509ExtendedTrustManager) manager));
} else {
SSLContext.setCertVerifyCallback(ctx, new TrustManagerVerifyCallback(engineMap, manager));
}
setVerifyCallback(ctx, engineMap, manager);
} catch (Exception e) {
if (keyMaterialProvider != null) {
keyMaterialProvider.destroy();
@ -178,6 +173,17 @@ public final class ReferenceCountedOpenSslClientContext extends ReferenceCounted
}
}
@SuppressJava6Requirement(reason = "Guarded by java version check")
private static void setVerifyCallback(long ctx, OpenSslEngineMap engineMap, X509TrustManager manager) {
// Use this to prevent an error when running on java < 7
if (useExtendedTrustManager(manager)) {
SSLContext.setCertVerifyCallback(ctx,
new ExtendedTrustManagerVerifyCallback(engineMap, (X509ExtendedTrustManager) manager));
} else {
SSLContext.setCertVerifyCallback(ctx, new TrustManagerVerifyCallback(engineMap, manager));
}
}
// No cache is currently supported for client side mode.
static final class OpenSslClientSessionContext extends OpenSslSessionContext {
OpenSslClientSessionContext(ReferenceCountedOpenSslContext context, OpenSslKeyMaterialProvider provider) {
@ -234,6 +240,7 @@ public final class ReferenceCountedOpenSslClientContext extends ReferenceCounted
}
}
@SuppressJava6Requirement(reason = "Usage guarded by java version check")
private static final class ExtendedTrustManagerVerifyCallback extends AbstractCertificateVerifier {
private final X509ExtendedTrustManager manager;

View File

@ -29,6 +29,7 @@ import io.netty.util.ResourceLeakTracker;
import io.netty.util.internal.ObjectUtil;
import io.netty.util.internal.PlatformDependent;
import io.netty.util.internal.StringUtil;
import io.netty.util.internal.SuppressJava6Requirement;
import io.netty.util.internal.SystemPropertyUtil;
import io.netty.util.internal.UnstableApi;
import io.netty.util.internal.logging.InternalLogger;
@ -637,6 +638,7 @@ public abstract class ReferenceCountedOpenSslContext extends SslContext implemen
}
}
@SuppressJava6Requirement(reason = "Guarded by java version check")
static boolean useExtendedTrustManager(X509TrustManager trustManager) {
return PlatformDependent.javaVersion() >= 7 && trustManager instanceof X509ExtendedTrustManager;
}
@ -715,6 +717,16 @@ public abstract class ReferenceCountedOpenSslContext extends SslContext implemen
return CertificateVerifier.X509_V_ERR_CERT_NOT_YET_VALID;
}
if (PlatformDependent.javaVersion() >= 7) {
return translateToError(cause);
}
// Could not detect a specific error code to use, so fallback to a default code.
return CertificateVerifier.X509_V_ERR_UNSPECIFIED;
}
}
@SuppressJava6Requirement(reason = "Usage guarded by java version check")
private static int translateToError(Throwable cause) {
if (cause instanceof CertificateRevokedException) {
return CertificateVerifier.X509_V_ERR_CERT_REVOKED;
}
@ -739,12 +751,8 @@ public abstract class ReferenceCountedOpenSslContext extends SslContext implemen
}
wrapped = wrapped.getCause();
}
}
// Could not detect a specific error code to use, so fallback to a default code.
return CertificateVerifier.X509_V_ERR_UNSPECIFIED;
}
}
abstract void verify(ReferenceCountedOpenSslEngine engine, X509Certificate[] peerCerts,
String auth) throws Exception;

View File

@ -28,6 +28,7 @@ import io.netty.util.ResourceLeakTracker;
import io.netty.util.internal.EmptyArrays;
import io.netty.util.internal.PlatformDependent;
import io.netty.util.internal.StringUtil;
import io.netty.util.internal.SuppressJava6Requirement;
import io.netty.util.internal.UnstableApi;
import io.netty.util.internal.logging.InternalLogger;
import io.netty.util.internal.logging.InternalLoggerFactory;
@ -1952,6 +1953,7 @@ public class ReferenceCountedOpenSslEngine extends SSLEngine implements Referenc
return false;
}
@SuppressJava6Requirement(reason = "Usage guarded by java version check")
@Override
public final synchronized SSLParameters getSSLParameters() {
SSLParameters sslParameters = super.getSSLParameters();
@ -1975,6 +1977,7 @@ public class ReferenceCountedOpenSslEngine extends SSLEngine implements Referenc
return sslParameters;
}
@SuppressJava6Requirement(reason = "Usage guarded by java version check")
@Override
public final synchronized void setSSLParameters(SSLParameters sslParameters) {
int version = PlatformDependent.javaVersion();

View File

@ -22,6 +22,7 @@ import io.netty.internal.tcnative.SSLContext;
import io.netty.internal.tcnative.SniHostNameMatcher;
import io.netty.util.CharsetUtil;
import io.netty.util.internal.PlatformDependent;
import io.netty.util.internal.SuppressJava6Requirement;
import io.netty.util.internal.logging.InternalLogger;
import io.netty.util.internal.logging.InternalLoggerFactory;
@ -147,13 +148,7 @@ public final class ReferenceCountedOpenSslServerContext extends ReferenceCounted
//
// See https://github.com/netty/netty/issues/5372
// Use this to prevent an error when running on java < 7
if (useExtendedTrustManager(manager)) {
SSLContext.setCertVerifyCallback(ctx, new ExtendedTrustManagerVerifyCallback(
engineMap, (X509ExtendedTrustManager) manager));
} else {
SSLContext.setCertVerifyCallback(ctx, new TrustManagerVerifyCallback(engineMap, manager));
}
setVerifyCallback(ctx, engineMap, manager);
X509Certificate[] issuers = manager.getAcceptedIssuers();
if (issuers != null && issuers.length > 0) {
@ -194,6 +189,17 @@ public final class ReferenceCountedOpenSslServerContext extends ReferenceCounted
}
}
@SuppressJava6Requirement(reason = "Guarded by java version check")
private static void setVerifyCallback(long ctx, OpenSslEngineMap engineMap, X509TrustManager manager) {
// Use this to prevent an error when running on java < 7
if (useExtendedTrustManager(manager)) {
SSLContext.setCertVerifyCallback(ctx, new ExtendedTrustManagerVerifyCallback(
engineMap, (X509ExtendedTrustManager) manager));
} else {
SSLContext.setCertVerifyCallback(ctx, new TrustManagerVerifyCallback(engineMap, manager));
}
}
private static final class OpenSslServerCertificateCallback implements CertificateCallback {
private final OpenSslEngineMap engineMap;
private final OpenSslKeyMaterialManager keyManagerHolder;
@ -236,6 +242,7 @@ public final class ReferenceCountedOpenSslServerContext extends ReferenceCounted
}
}
@SuppressJava6Requirement(reason = "Usage guarded by java version check")
private static final class ExtendedTrustManagerVerifyCallback extends AbstractCertificateVerifier {
private final X509ExtendedTrustManager manager;

View File

@ -16,6 +16,7 @@
package io.netty.handler.ssl.util;
import io.netty.util.internal.SuppressJava6Requirement;
import sun.security.x509.AlgorithmId;
import sun.security.x509.CertificateAlgorithmId;
import sun.security.x509.CertificateIssuerName;
@ -42,6 +43,7 @@ import static io.netty.handler.ssl.util.SelfSignedCertificate.*;
*/
final class OpenJdkSelfSignedCertGenerator {
@SuppressJava6Requirement(reason = "Usage guarded by dependency check")
static String[] generate(String fqdn, KeyPair keypair, SecureRandom random, Date notBefore, Date notAfter)
throws Exception {
PrivateKey key = keypair.getPrivate();

View File

@ -18,6 +18,7 @@ package io.netty.handler.ssl.util;
import io.netty.util.concurrent.FastThreadLocal;
import io.netty.util.internal.PlatformDependent;
import io.netty.util.internal.SuppressJava6Requirement;
import javax.net.ssl.ManagerFactoryParameters;
import javax.net.ssl.TrustManager;
@ -136,6 +137,15 @@ public abstract class SimpleTrustManagerFactory extends TrustManagerFactory {
if (trustManagers == null) {
trustManagers = parent.engineGetTrustManagers();
if (PlatformDependent.javaVersion() >= 7) {
wrapIfNeeded(trustManagers);
}
this.trustManagers = trustManagers;
}
return trustManagers.clone();
}
@SuppressJava6Requirement(reason = "Usage guarded by java version check")
private static void wrapIfNeeded(TrustManager[] trustManagers) {
for (int i = 0; i < trustManagers.length; i++) {
final TrustManager tm = trustManagers[i];
if (tm instanceof X509TrustManager && !(tm instanceof X509ExtendedTrustManager)) {
@ -143,9 +153,5 @@ public abstract class SimpleTrustManagerFactory extends TrustManagerFactory {
}
}
}
this.trustManagers = trustManagers;
}
return trustManagers.clone();
}
}
}

View File

@ -15,6 +15,8 @@
*/
package io.netty.handler.ssl.util;
import io.netty.util.internal.SuppressJava6Requirement;
import javax.net.ssl.SSLEngine;
import javax.net.ssl.X509ExtendedTrustManager;
import javax.net.ssl.X509TrustManager;
@ -24,6 +26,7 @@ import java.security.cert.X509Certificate;
import static io.netty.util.internal.ObjectUtil.*;
@SuppressJava6Requirement(reason = "Usage guarded by java version check")
final class X509TrustManagerWrapper extends X509ExtendedTrustManager {
private final X509TrustManager delegate;

71
pom.xml
View File

@ -819,78 +819,7 @@
<version>1.1</version>
</signature>
<ignores>
<ignore>sun.misc.Unsafe</ignore>
<ignore>sun.misc.Cleaner</ignore>
<ignore>sun.nio.ch.DirectBuffer</ignore>
<ignore>java.util.zip.Deflater</ignore>
<!-- Used for NIO -->
<ignore>java.nio.channels.DatagramChannel</ignore>
<ignore>java.nio.channels.MembershipKey</ignore>
<ignore>java.nio.channels.ServerSocketChannel</ignore>
<ignore>java.nio.channels.SocketChannel</ignore>
<ignore>java.net.StandardProtocolFamily</ignore>
<ignore>java.nio.channels.spi.SelectorProvider</ignore>
<ignore>java.net.SocketOption</ignore>
<ignore>java.net.StandardSocketOptions</ignore>
<ignore>java.nio.channels.NetworkChannel</ignore>
<!-- Self-signed certificate generation -->
<ignore>sun.security.x509.AlgorithmId</ignore>
<ignore>sun.security.x509.CertificateAlgorithmId</ignore>
<ignore>sun.security.x509.CertificateIssuerName</ignore>
<ignore>sun.security.x509.CertificateSerialNumber</ignore>
<ignore>sun.security.x509.CertificateSubjectName</ignore>
<ignore>sun.security.x509.CertificateValidity</ignore>
<ignore>sun.security.x509.CertificateVersion</ignore>
<ignore>sun.security.x509.CertificateX509Key</ignore>
<ignore>sun.security.x509.X500Name</ignore>
<ignore>sun.security.x509.X509CertInfo</ignore>
<ignore>sun.security.x509.X509CertImpl</ignore>
<!-- SSLSession implementation -->
<ignore>javax.net.ssl.SSLEngine</ignore>
<ignore>javax.net.ssl.ExtendedSSLSession</ignore>
<ignore>javax.net.ssl.X509ExtendedTrustManager</ignore>
<ignore>javax.net.ssl.SSLParameters</ignore>
<ignore>javax.net.ssl.SNIServerName</ignore>
<ignore>javax.net.ssl.SNIHostName</ignore>
<ignore>javax.net.ssl.SNIMatcher</ignore>
<ignore>java.security.AlgorithmConstraints</ignore>
<ignore>java.security.cert.CertificateRevokedException</ignore>
<ignore>java.security.cert.CertPathValidatorException</ignore>
<ignore>java.security.cert.CertPathValidatorException$Reason</ignore>
<ignore>java.security.cert.CertPathValidatorException$BasicReason</ignore>
<ignore>java.util.concurrent.ConcurrentLinkedDeque</ignore>
<ignore>java.util.concurrent.ThreadLocalRandom</ignore>
<!-- Compression -->
<ignore>java.util.zip.CRC32</ignore>
<ignore>java.util.zip.Adler32</ignore>
<!-- NioDatagramChannel implementation -->
<ignore>java.net.ProtocolFamily</ignore>
<!-- JDK 9 -->
<ignore>java.nio.ByteBuffer</ignore>
<ignore>java.nio.CharBuffer</ignore>
<!-- JDK 8 -->
<ignore>java.util.concurrent.atomic.LongAdder</ignore>
<ignore>java.util.function.BiFunction</ignore>
<ignore>java.security.cert.X509Certificate</ignore>
<!-- Resolver -->
<ignore>java.net.InetAddress</ignore>
<!-- NoexecVolumeDetector -->
<ignore>java.nio.file.attribute.PosixFilePermission</ignore>
<ignore>java.nio.file.Files</ignore>
<ignore>java.nio.file.LinkOption</ignore>
<ignore>java.nio.file.Path</ignore>
<ignore>java.io.File</ignore>
</ignores>
<annotations>
<annotation>io.netty.util.internal.SuppressJava6Requirement</annotation>

View File

@ -16,6 +16,8 @@
package io.netty.testsuite.transport.socket;
import io.netty.channel.socket.InternetProtocolFamily;
import io.netty.util.internal.PlatformDependent;
import io.netty.util.internal.SuppressJava6Requirement;
import org.junit.Assume;
import org.junit.BeforeClass;
@ -26,9 +28,13 @@ import java.nio.channels.spi.SelectorProvider;
public class DatagramUnicastIPv6Test extends DatagramUnicastTest {
@SuppressJava6Requirement(reason = "Guarded by java version check")
@BeforeClass
public static void assumeIpv6Supported() {
try {
if (PlatformDependent.javaVersion() < 7) {
throw new UnsupportedOperationException();
}
Channel channel = SelectorProvider.provider().openDatagramChannel(StandardProtocolFamily.INET6);
channel.close();
} catch (UnsupportedOperationException e) {

View File

@ -17,6 +17,7 @@ package io.netty.channel.socket.nio;
import io.netty.channel.ChannelException;
import io.netty.channel.ChannelOption;
import io.netty.util.internal.SuppressJava6Requirement;
import java.io.IOException;
import java.nio.channels.Channel;
@ -29,6 +30,7 @@ import java.util.Set;
* Provides {@link ChannelOption} over a given {@link java.net.SocketOption} which is then passed through the underlying
* {@link java.nio.channels.NetworkChannel}.
*/
@SuppressJava6Requirement(reason = "Usage explicit by the user")
public final class NioChannelOption<T> extends ChannelOption<T> {
private final java.net.SocketOption<T> option;
@ -53,6 +55,7 @@ public final class NioChannelOption<T> extends ChannelOption<T> {
// See https://github.com/netty/netty/issues/8166
// Internal helper methods to remove code duplication between Nio*Channel implementations.
@SuppressJava6Requirement(reason = "Usage guarded by java version check")
static <T> boolean setOption(Channel jdkChannel, NioChannelOption<T> option, T value) {
java.nio.channels.NetworkChannel channel = (java.nio.channels.NetworkChannel) jdkChannel;
if (!channel.supportedOptions().contains(option.option)) {
@ -71,6 +74,7 @@ public final class NioChannelOption<T> extends ChannelOption<T> {
}
}
@SuppressJava6Requirement(reason = "Usage guarded by java version check")
static <T> T getOption(Channel jdkChannel, NioChannelOption<T> option) {
java.nio.channels.NetworkChannel channel = (java.nio.channels.NetworkChannel) jdkChannel;
@ -89,6 +93,7 @@ public final class NioChannelOption<T> extends ChannelOption<T> {
}
}
@SuppressJava6Requirement(reason = "Usage guarded by java version check")
@SuppressWarnings("unchecked")
static ChannelOption[] getOptions(Channel jdkChannel) {
java.nio.channels.NetworkChannel channel = (java.nio.channels.NetworkChannel) jdkChannel;

View File

@ -33,6 +33,7 @@ import io.netty.channel.socket.InternetProtocolFamily;
import io.netty.util.internal.SocketUtils;
import io.netty.util.internal.PlatformDependent;
import io.netty.util.internal.StringUtil;
import io.netty.util.internal.SuppressJava6Requirement;
import java.io.IOException;
import java.net.InetAddress;
@ -88,6 +89,7 @@ public final class NioDatagramChannel
}
}
@SuppressJava6Requirement(reason = "Usage guarded by java version check")
private static DatagramChannel newSocket(SelectorProvider provider, InternetProtocolFamily ipFamily) {
if (ipFamily == null) {
return newSocket(provider);
@ -394,6 +396,7 @@ public final class NioDatagramChannel
return joinGroup(multicastAddress, networkInterface, source, newPromise());
}
@SuppressJava6Requirement(reason = "Usage guarded by java version check")
@Override
public ChannelFuture joinGroup(
InetAddress multicastAddress, NetworkInterface networkInterface,
@ -474,6 +477,7 @@ public final class NioDatagramChannel
return leaveGroup(multicastAddress, networkInterface, source, newPromise());
}
@SuppressJava6Requirement(reason = "Usage guarded by java version check")
@Override
public ChannelFuture leaveGroup(
InetAddress multicastAddress, NetworkInterface networkInterface, InetAddress source,
@ -527,6 +531,7 @@ public final class NioDatagramChannel
/**
* Block the given sourceToBlock address for the given multicastAddress on the given networkInterface
*/
@SuppressJava6Requirement(reason = "Usage guarded by java version check")
@Override
public ChannelFuture block(
InetAddress multicastAddress, NetworkInterface networkInterface,

View File

@ -24,6 +24,7 @@ import io.netty.channel.nio.AbstractNioMessageChannel;
import io.netty.channel.socket.DefaultServerSocketChannelConfig;
import io.netty.channel.socket.ServerSocketChannelConfig;
import io.netty.util.internal.PlatformDependent;
import io.netty.util.internal.SuppressJava6Requirement;
import io.netty.util.internal.logging.InternalLogger;
import io.netty.util.internal.logging.InternalLoggerFactory;
@ -126,6 +127,7 @@ public class NioServerSocketChannel extends AbstractNioMessageChannel
return SocketUtils.localSocketAddress(javaChannel().socket());
}
@SuppressJava6Requirement(reason = "Usage guarded by java version check")
@Override
protected void doBind(SocketAddress localAddress) throws Exception {
if (PlatformDependent.javaVersion() >= 7) {
@ -220,7 +222,6 @@ public class NioServerSocketChannel extends AbstractNioMessageChannel
return super.getOption(option);
}
@SuppressWarnings("unchecked")
@Override
public Map<ChannelOption<?>, Object> getOptions() {
if (PlatformDependent.javaVersion() >= 7) {

View File

@ -33,6 +33,7 @@ import io.netty.channel.socket.SocketChannelConfig;
import io.netty.util.concurrent.GlobalEventExecutor;
import io.netty.util.internal.PlatformDependent;
import io.netty.util.internal.SocketUtils;
import io.netty.util.internal.SuppressJava6Requirement;
import io.netty.util.internal.UnstableApi;
import io.netty.util.internal.logging.InternalLogger;
import io.netty.util.internal.logging.InternalLoggerFactory;
@ -152,6 +153,7 @@ public class NioSocketChannel extends AbstractNioByteChannel implements io.netty
return (InetSocketAddress) super.remoteAddress();
}
@SuppressJava6Requirement(reason = "Usage guarded by java version check")
@UnstableApi
@Override
protected final void doShutdownOutput() throws Exception {
@ -270,6 +272,7 @@ public class NioSocketChannel extends AbstractNioByteChannel implements io.netty
}
}
@SuppressJava6Requirement(reason = "Usage guarded by java version check")
private void shutdownInput0() throws Exception {
if (PlatformDependent.javaVersion() >= 7) {
javaChannel().shutdownInput();
@ -496,7 +499,6 @@ public class NioSocketChannel extends AbstractNioByteChannel implements io.netty
return super.getOption(option);
}
@SuppressWarnings("unchecked")
@Override
public Map<ChannelOption<?>, Object> getOptions() {
if (PlatformDependent.javaVersion() >= 7) {

View File

@ -16,6 +16,7 @@
package io.netty.channel.socket.nio;
import io.netty.channel.socket.InternetProtocolFamily;
import io.netty.util.internal.SuppressJava6Requirement;
import java.net.ProtocolFamily;
import java.net.StandardProtocolFamily;
@ -32,6 +33,7 @@ final class ProtocolFamilyConverter {
/**
* Convert the {@link InternetProtocolFamily}. This MUST only be called on jdk version >= 7.
*/
@SuppressJava6Requirement(reason = "Usage guarded by java version check")
public static ProtocolFamily convert(InternetProtocolFamily family) {
switch (family) {
case IPv4: