From ca259e495359f8ec70b01c633eea5d402611b7c2 Mon Sep 17 00:00:00 2001 From: Simona Tankova Date: Mon, 19 Feb 2024 21:03:09 +0200 Subject: [PATCH 1/3] Apply Nullable/NotNullByDefault annotations Motivation: Nullable/NotNullByDefault annotations give an idea of what to expect from the API. Plus, they provide a better IDE integration. This PR is based on the work done in netty/netty#12878 Modification: Nullable/NotNullByDefault annotations are applied where necessary. Result: The change extends the API with nullability expectations. Plus, it provides a better IDE integration. --- pom.xml | 12 ++++++ .../codec/http3/DefaultHttp3Headers.java | 3 +- .../io/netty/incubator/codec/http3/Http3.java | 3 ++ .../http3/Http3ClientConnectionHandler.java | 9 ++-- .../codec/http3/Http3CodecUtils.java | 6 ++- .../codec/http3/Http3ConnectionHandler.java | 7 +-- .../Http3ControlStreamInboundHandler.java | 4 +- .../Http3ControlStreamOutboundHandler.java | 2 + .../incubator/codec/http3/Http3Exception.java | 5 ++- .../codec/http3/Http3FrameCodec.java | 2 + .../http3/Http3FrameToHttpObjectCodec.java | 3 +- .../http3/Http3FrameValidationUtils.java | 3 ++ .../incubator/codec/http3/Http3Headers.java | 7 +++ ...ttp3RequestStreamEncodeStateValidator.java | 2 + .../Http3RequestStreamInboundHandler.java | 2 + .../http3/Http3ServerConnectionHandler.java | 7 +-- .../http3/Http3ServerPushStreamManager.java | 9 ++-- .../codec/http3/Http3SettingsFrame.java | 4 ++ ...directionalStreamInboundClientHandler.java | 5 ++- ...tp3UnidirectionalStreamInboundHandler.java | 3 +- ...directionalStreamInboundServerHandler.java | 3 +- .../codec/http3/HttpConversionUtil.java | 8 ++-- .../codec/http3/QpackEncoderDynamicTable.java | 7 +-- .../codec/http3/QpackEncoderHandler.java | 4 +- .../incubator/codec/http3/QpackException.java | 4 +- .../http3/internal/NotNullByDefault.java | 43 +++++++++++++++++++ .../codec/http3/internal/package-info.java | 21 +++++++++ .../incubator/codec/http3/package-info.java | 4 ++ ...ctHttp3FrameTypeValidationHandlerTest.java | 2 + .../codec/http3/EmbeddedQuicChannel.java | 4 ++ .../http3/EmbeddedQuicStreamChannel.java | 6 ++- .../Http3FrameToHttpObjectCodecTest.java | 4 ++ ...tp3RequestStreamValidationHandlerTest.java | 3 +- .../Http3ServerPushStreamManagerTest.java | 9 ++-- ...nidirectionalStreamInboundHandlerTest.java | 6 ++- .../codec/http3/QpackEncoderDecoderTest.java | 4 +- 36 files changed, 189 insertions(+), 41 deletions(-) create mode 100644 src/main/java/io/netty/incubator/codec/http3/internal/NotNullByDefault.java create mode 100644 src/main/java/io/netty/incubator/codec/http3/internal/package-info.java diff --git a/pom.xml b/pom.xml index 78b7f9cb..2af911d2 100644 --- a/pom.xml +++ b/pom.xml @@ -468,5 +468,17 @@ 1.75 test + + org.jetbrains + annotations + 24.1.0 + provided + + + com.google.code.findbugs + jsr305 + 3.0.2 + provided + diff --git a/src/main/java/io/netty/incubator/codec/http3/DefaultHttp3Headers.java b/src/main/java/io/netty/incubator/codec/http3/DefaultHttp3Headers.java index babdd754..38798903 100644 --- a/src/main/java/io/netty/incubator/codec/http3/DefaultHttp3Headers.java +++ b/src/main/java/io/netty/incubator/codec/http3/DefaultHttp3Headers.java @@ -19,6 +19,7 @@ import io.netty.handler.codec.DefaultHeaders; import io.netty.util.AsciiString; import io.netty.util.ByteProcessor; +import org.jetbrains.annotations.Nullable; import static io.netty.incubator.codec.http3.Http3Headers.PseudoHeaderName.hasPseudoHeaderFormat; import static io.netty.util.AsciiString.CASE_INSENSITIVE_HASHER; @@ -35,7 +36,7 @@ public boolean process(byte value) { }; static final NameValidator HTTP3_NAME_VALIDATOR = new NameValidator() { @Override - public void validateName(CharSequence name) { + public void validateName(@Nullable CharSequence name) { if (name == null || name.length() == 0) { throw new Http3HeadersValidationException(String.format("empty headers are not allowed [%s]", name)); } diff --git a/src/main/java/io/netty/incubator/codec/http3/Http3.java b/src/main/java/io/netty/incubator/codec/http3/Http3.java index 265c58b3..d934244b 100644 --- a/src/main/java/io/netty/incubator/codec/http3/Http3.java +++ b/src/main/java/io/netty/incubator/codec/http3/Http3.java @@ -26,6 +26,7 @@ import io.netty.incubator.codec.quic.QuicStreamType; import io.netty.util.AttributeKey; import io.netty.util.concurrent.Future; +import org.jetbrains.annotations.Nullable; /** * Contains utility methods that help to bootstrap server / clients with HTTP3 support. @@ -53,6 +54,7 @@ private Http3() { } * @param channel the channel for the HTTP/3 connection. * @return the control stream. */ + @Nullable public static QuicStreamChannel getLocalControlStream(Channel channel) { return channel.attr(HTTP3_CONTROL_STREAM_KEY).get(); } @@ -78,6 +80,7 @@ static void setLocalControlStream(Channel channel, QuicStreamChannel controlStre channel.attr(HTTP3_CONTROL_STREAM_KEY).set(controlStreamChannel); } + @Nullable static QpackAttributes getQpackAttributes(Channel channel) { return channel.attr(QPACK_ATTRIBUTES_KEY).get(); } diff --git a/src/main/java/io/netty/incubator/codec/http3/Http3ClientConnectionHandler.java b/src/main/java/io/netty/incubator/codec/http3/Http3ClientConnectionHandler.java index 3d13006f..5cb3649f 100644 --- a/src/main/java/io/netty/incubator/codec/http3/Http3ClientConnectionHandler.java +++ b/src/main/java/io/netty/incubator/codec/http3/Http3ClientConnectionHandler.java @@ -18,6 +18,7 @@ import io.netty.channel.ChannelHandler; import io.netty.channel.ChannelHandlerContext; import io.netty.incubator.codec.quic.QuicStreamChannel; +import org.jetbrains.annotations.Nullable; import java.util.function.LongFunction; @@ -49,10 +50,10 @@ public Http3ClientConnectionHandler() { * remote peer or {@code null} if the default settings should be used. * @param disableQpackDynamicTable If QPACK dynamic table should be disabled. */ - public Http3ClientConnectionHandler(ChannelHandler inboundControlStreamHandler, - LongFunction pushStreamHandlerFactory, - LongFunction unknownInboundStreamHandlerFactory, - Http3SettingsFrame localSettings, boolean disableQpackDynamicTable) { + public Http3ClientConnectionHandler(@Nullable ChannelHandler inboundControlStreamHandler, + @Nullable LongFunction pushStreamHandlerFactory, + @Nullable LongFunction unknownInboundStreamHandlerFactory, + @Nullable Http3SettingsFrame localSettings, boolean disableQpackDynamicTable) { super(false, inboundControlStreamHandler, unknownInboundStreamHandlerFactory, localSettings, disableQpackDynamicTable); this.pushStreamHandlerFactory = pushStreamHandlerFactory; diff --git a/src/main/java/io/netty/incubator/codec/http3/Http3CodecUtils.java b/src/main/java/io/netty/incubator/codec/http3/Http3CodecUtils.java index 9940d9c5..b807687b 100644 --- a/src/main/java/io/netty/incubator/codec/http3/Http3CodecUtils.java +++ b/src/main/java/io/netty/incubator/codec/http3/Http3CodecUtils.java @@ -26,6 +26,7 @@ import io.netty.util.CharsetUtil; import io.netty.util.internal.ObjectUtil; import io.netty.util.internal.StringUtil; +import org.jetbrains.annotations.Nullable; import static io.netty.channel.ChannelFutureListener.CLOSE_ON_FAILURE; import static io.netty.incubator.codec.http3.Http3ErrorCode.H3_INTERNAL_ERROR; @@ -243,7 +244,7 @@ static void connectionError(ChannelHandlerContext ctx, Http3Exception exception, * @param fireException {@code true} if we should also fire the {@link Http3Exception} through the pipeline. */ static void connectionError(ChannelHandlerContext ctx, Http3ErrorCode errorCode, - String msg, boolean fireException) { + @Nullable String msg, boolean fireException) { if (fireException) { ctx.fireExceptionCaught(new Http3Exception(errorCode, msg)); } @@ -270,7 +271,7 @@ static void closeOnFailure(ChannelFuture future) { * @param errorCode the {@link Http3ErrorCode} that caused the error. * @param msg the message that should be used as reason for the error, may be {@code null}. */ - static void connectionError(Channel channel, Http3ErrorCode errorCode, String msg) { + static void connectionError(Channel channel, Http3ErrorCode errorCode, @Nullable String msg) { final QuicChannel quicChannel; if (channel instanceof QuicChannel) { @@ -306,6 +307,7 @@ static void readIfNoAutoRead(ChannelHandlerContext ctx) { * @param ch for which the {@link Http3ConnectionHandler} is to be retrieved. * @return {@link Http3ConnectionHandler} if available, else close the connection and return {@code null}. */ + @Nullable static Http3ConnectionHandler getConnectionHandlerOrClose(QuicChannel ch) { Http3ConnectionHandler connectionHandler = ch.pipeline().get(Http3ConnectionHandler.class); if (connectionHandler == null) { diff --git a/src/main/java/io/netty/incubator/codec/http3/Http3ConnectionHandler.java b/src/main/java/io/netty/incubator/codec/http3/Http3ConnectionHandler.java index 548c9ab2..dbe67735 100644 --- a/src/main/java/io/netty/incubator/codec/http3/Http3ConnectionHandler.java +++ b/src/main/java/io/netty/incubator/codec/http3/Http3ConnectionHandler.java @@ -22,6 +22,7 @@ import io.netty.incubator.codec.quic.QuicChannel; import io.netty.incubator.codec.quic.QuicStreamChannel; import io.netty.incubator.codec.quic.QuicStreamType; +import org.jetbrains.annotations.Nullable; import java.util.function.LongFunction; @@ -58,9 +59,9 @@ public abstract class Http3ConnectionHandler extends ChannelInboundHandlerAdapte * remote peer or {@code null} if the default settings should be used. * @param disableQpackDynamicTable If QPACK dynamic table should be disabled. */ - Http3ConnectionHandler(boolean server, ChannelHandler inboundControlStreamHandler, - LongFunction unknownInboundStreamHandlerFactory, - Http3SettingsFrame localSettings, boolean disableQpackDynamicTable) { + Http3ConnectionHandler(boolean server, @Nullable ChannelHandler inboundControlStreamHandler, + @Nullable LongFunction unknownInboundStreamHandlerFactory, + @Nullable Http3SettingsFrame localSettings, boolean disableQpackDynamicTable) { this.unknownInboundStreamHandlerFactory = unknownInboundStreamHandlerFactory; this.disableQpackDynamicTable = disableQpackDynamicTable; if (localSettings == null) { diff --git a/src/main/java/io/netty/incubator/codec/http3/Http3ControlStreamInboundHandler.java b/src/main/java/io/netty/incubator/codec/http3/Http3ControlStreamInboundHandler.java index 4a371775..c25f6c1d 100644 --- a/src/main/java/io/netty/incubator/codec/http3/Http3ControlStreamInboundHandler.java +++ b/src/main/java/io/netty/incubator/codec/http3/Http3ControlStreamInboundHandler.java @@ -26,6 +26,7 @@ import io.netty.util.ReferenceCountUtil; import io.netty.util.concurrent.Future; import io.netty.util.concurrent.GenericFutureListener; +import org.jetbrains.annotations.Nullable; import java.nio.channels.ClosedChannelException; @@ -50,7 +51,8 @@ final class Http3ControlStreamInboundHandler extends Http3FrameTypeInboundValida private Long receivedGoawayId; private Long receivedMaxPushId; - Http3ControlStreamInboundHandler(boolean server, ChannelHandler controlFrameHandler, QpackEncoder qpackEncoder, + Http3ControlStreamInboundHandler(boolean server, @Nullable ChannelHandler controlFrameHandler, + QpackEncoder qpackEncoder, Http3ControlStreamOutboundHandler remoteControlStreamHandler) { super(Http3ControlStreamFrame.class); this.server = server; diff --git a/src/main/java/io/netty/incubator/codec/http3/Http3ControlStreamOutboundHandler.java b/src/main/java/io/netty/incubator/codec/http3/Http3ControlStreamOutboundHandler.java index 8a4a24b3..2c28b035 100644 --- a/src/main/java/io/netty/incubator/codec/http3/Http3ControlStreamOutboundHandler.java +++ b/src/main/java/io/netty/incubator/codec/http3/Http3ControlStreamOutboundHandler.java @@ -22,6 +22,7 @@ import io.netty.channel.socket.ChannelInputShutdownEvent; import io.netty.util.ReferenceCountUtil; import io.netty.util.internal.ObjectUtil; +import org.jetbrains.annotations.Nullable; import static io.netty.incubator.codec.http3.Http3CodecUtils.closeOnFailure; @@ -45,6 +46,7 @@ final class Http3ControlStreamOutboundHandler * * @return the id. */ + @Nullable Long sentMaxPushId() { return sentMaxPushId; } diff --git a/src/main/java/io/netty/incubator/codec/http3/Http3Exception.java b/src/main/java/io/netty/incubator/codec/http3/Http3Exception.java index 7d994724..ca12ebba 100644 --- a/src/main/java/io/netty/incubator/codec/http3/Http3Exception.java +++ b/src/main/java/io/netty/incubator/codec/http3/Http3Exception.java @@ -16,6 +16,7 @@ package io.netty.incubator.codec.http3; import io.netty.util.internal.ObjectUtil; +import org.jetbrains.annotations.Nullable; /** * An exception related to violate the HTTP3 spec. @@ -29,7 +30,7 @@ public final class Http3Exception extends Exception { * @param errorCode the {@link Http3ErrorCode} that caused this exception. * @param message the message to include. */ - public Http3Exception(Http3ErrorCode errorCode, String message) { + public Http3Exception(Http3ErrorCode errorCode, @Nullable String message) { super(message); this.errorCode = ObjectUtil.checkNotNull(errorCode, "errorCode"); } @@ -41,7 +42,7 @@ public Http3Exception(Http3ErrorCode errorCode, String message) { * @param message the message to include. * @param cause the {@link Throwable} to wrap. */ - public Http3Exception(Http3ErrorCode errorCode, String message, Throwable cause) { + public Http3Exception(Http3ErrorCode errorCode, String message, @Nullable Throwable cause) { super(message, cause); this.errorCode = ObjectUtil.checkNotNull(errorCode, "errorCode"); } diff --git a/src/main/java/io/netty/incubator/codec/http3/Http3FrameCodec.java b/src/main/java/io/netty/incubator/codec/http3/Http3FrameCodec.java index 33ff29d3..6f837250 100644 --- a/src/main/java/io/netty/incubator/codec/http3/Http3FrameCodec.java +++ b/src/main/java/io/netty/incubator/codec/http3/Http3FrameCodec.java @@ -28,6 +28,7 @@ import io.netty.util.ReferenceCountUtil; import io.netty.util.concurrent.Future; import io.netty.util.concurrent.GenericFutureListener; +import org.jetbrains.annotations.Nullable; import java.net.SocketAddress; import java.util.List; @@ -349,6 +350,7 @@ private boolean enforceMaxPayloadLength( return in.readableBytes() >= payLoadLength; } + @Nullable private Http3SettingsFrame decodeSettings(ChannelHandlerContext ctx, ByteBuf in, int payLoadLength) { Http3SettingsFrame settingsFrame = new DefaultHttp3SettingsFrame(); while (payLoadLength > 0) { diff --git a/src/main/java/io/netty/incubator/codec/http3/Http3FrameToHttpObjectCodec.java b/src/main/java/io/netty/incubator/codec/http3/Http3FrameToHttpObjectCodec.java index c7b5058e..e52a519c 100644 --- a/src/main/java/io/netty/incubator/codec/http3/Http3FrameToHttpObjectCodec.java +++ b/src/main/java/io/netty/incubator/codec/http3/Http3FrameToHttpObjectCodec.java @@ -42,6 +42,7 @@ import io.netty.handler.codec.http.LastHttpContent; import io.netty.incubator.codec.quic.QuicStreamChannel; import io.netty.util.concurrent.PromiseCombiner; +import org.jetbrains.annotations.Nullable; import java.net.SocketAddress; @@ -221,7 +222,7 @@ private static ChannelPromise writeWithOptionalCombiner( ChannelHandlerContext ctx, Object msg, ChannelPromise outerPromise, - PromiseCombiner combiner, + @Nullable PromiseCombiner combiner, boolean unvoidPromise ) { if (unvoidPromise) { diff --git a/src/main/java/io/netty/incubator/codec/http3/Http3FrameValidationUtils.java b/src/main/java/io/netty/incubator/codec/http3/Http3FrameValidationUtils.java index a41f472f..18cf24f8 100644 --- a/src/main/java/io/netty/incubator/codec/http3/Http3FrameValidationUtils.java +++ b/src/main/java/io/netty/incubator/codec/http3/Http3FrameValidationUtils.java @@ -19,6 +19,7 @@ import io.netty.channel.ChannelPromise; import io.netty.util.ReferenceCountUtil; import io.netty.util.internal.StringUtil; +import org.jetbrains.annotations.Nullable; final class Http3FrameValidationUtils { @@ -44,6 +45,7 @@ private static boolean isValid(Class frameType, Object msg) { * @param Expected type. * @return {@code msg} as expected frame type or {@code null} if it can not be converted to the expected type. */ + @Nullable static T validateFrameWritten(Class expectedFrameType, Object msg) { if (isValid(expectedFrameType, msg)) { return cast(msg); @@ -60,6 +62,7 @@ static T validateFrameWritten(Class expectedFrameType, Object msg) { * @param Expected type. * @return {@code msg} as expected frame type or {@code null} if it can not be converted to the expected type. */ + @Nullable static T validateFrameRead(Class expectedFrameType, Object msg) { if (isValid(expectedFrameType, msg)) { return cast(msg); diff --git a/src/main/java/io/netty/incubator/codec/http3/Http3Headers.java b/src/main/java/io/netty/incubator/codec/http3/Http3Headers.java index 2da38bcc..0a5711d2 100644 --- a/src/main/java/io/netty/incubator/codec/http3/Http3Headers.java +++ b/src/main/java/io/netty/incubator/codec/http3/Http3Headers.java @@ -17,6 +17,7 @@ import io.netty.handler.codec.Headers; import io.netty.util.AsciiString; +import org.jetbrains.annotations.Nullable; import java.util.Iterator; import java.util.Map.Entry; @@ -106,6 +107,7 @@ public static boolean isPseudoHeader(CharSequence name) { * @param name the header name. * @return corresponding {@link PseudoHeaderName} if any, {@code null} otherwise. */ + @Nullable public static PseudoHeaderName getPseudoHeader(CharSequence name) { return PSEUDO_HEADERS.get(name); } @@ -180,6 +182,7 @@ public boolean isRequestOnly() { * * @return the value of the header. */ + @Nullable CharSequence method(); /** @@ -187,6 +190,7 @@ public boolean isRequestOnly() { * * @return the value of the header. */ + @Nullable CharSequence scheme(); /** @@ -194,6 +198,7 @@ public boolean isRequestOnly() { * * @return the value of the header. */ + @Nullable CharSequence authority(); /** @@ -201,6 +206,7 @@ public boolean isRequestOnly() { * * @return the value of the header. */ + @Nullable CharSequence path(); /** @@ -208,6 +214,7 @@ public boolean isRequestOnly() { * * @return the value of the header. */ + @Nullable CharSequence status(); /** diff --git a/src/main/java/io/netty/incubator/codec/http3/Http3RequestStreamEncodeStateValidator.java b/src/main/java/io/netty/incubator/codec/http3/Http3RequestStreamEncodeStateValidator.java index bb11e65c..c6a132cd 100644 --- a/src/main/java/io/netty/incubator/codec/http3/Http3RequestStreamEncodeStateValidator.java +++ b/src/main/java/io/netty/incubator/codec/http3/Http3RequestStreamEncodeStateValidator.java @@ -19,6 +19,7 @@ import io.netty.channel.ChannelOutboundHandlerAdapter; import io.netty.channel.ChannelPromise; import io.netty.handler.codec.http.HttpStatusClass; +import org.jetbrains.annotations.Nullable; import static io.netty.incubator.codec.http3.Http3FrameValidationUtils.frameTypeUnexpected; @@ -75,6 +76,7 @@ public boolean terminated() { * @param frame to evaluate. * @return Next {@link State} or {@code null} if the frame is invalid. */ + @Nullable static State evaluateFrame(State state, Http3RequestStreamFrame frame) { if (frame instanceof Http3PushPromiseFrame || frame instanceof Http3UnknownFrame) { // always allow push promise frames. diff --git a/src/main/java/io/netty/incubator/codec/http3/Http3RequestStreamInboundHandler.java b/src/main/java/io/netty/incubator/codec/http3/Http3RequestStreamInboundHandler.java index 62661e76..80832d27 100644 --- a/src/main/java/io/netty/incubator/codec/http3/Http3RequestStreamInboundHandler.java +++ b/src/main/java/io/netty/incubator/codec/http3/Http3RequestStreamInboundHandler.java @@ -22,6 +22,7 @@ import io.netty.incubator.codec.quic.QuicStreamChannel; import io.netty.util.internal.logging.InternalLogger; import io.netty.util.internal.logging.InternalLoggerFactory; +import org.jetbrains.annotations.Nullable; /** * {@link ChannelInboundHandlerAdapter} which makes it easy to handle @@ -129,6 +130,7 @@ protected void handleHttp3Exception(@SuppressWarnings("unused") ChannelHandlerCo * @param ctx the {@link ChannelHandlerContext} of this handler. * @return the control stream. */ + @Nullable protected final QuicStreamChannel controlStream(ChannelHandlerContext ctx) { return Http3.getLocalControlStream(ctx.channel().parent()); } diff --git a/src/main/java/io/netty/incubator/codec/http3/Http3ServerConnectionHandler.java b/src/main/java/io/netty/incubator/codec/http3/Http3ServerConnectionHandler.java index 4ce1b989..5e015d1a 100644 --- a/src/main/java/io/netty/incubator/codec/http3/Http3ServerConnectionHandler.java +++ b/src/main/java/io/netty/incubator/codec/http3/Http3ServerConnectionHandler.java @@ -20,6 +20,7 @@ import io.netty.channel.ChannelPipeline; import io.netty.incubator.codec.quic.QuicStreamChannel; import io.netty.util.internal.ObjectUtil; +import org.jetbrains.annotations.Nullable; import java.util.function.LongFunction; @@ -58,9 +59,9 @@ public Http3ServerConnectionHandler(ChannelHandler requestStreamHandler) { * @param disableQpackDynamicTable If QPACK dynamic table should be disabled. */ public Http3ServerConnectionHandler(ChannelHandler requestStreamHandler, - ChannelHandler inboundControlStreamHandler, - LongFunction unknownInboundStreamHandlerFactory, - Http3SettingsFrame localSettings, boolean disableQpackDynamicTable) { + @Nullable ChannelHandler inboundControlStreamHandler, + @Nullable LongFunction unknownInboundStreamHandlerFactory, + @Nullable Http3SettingsFrame localSettings, boolean disableQpackDynamicTable) { super(true, inboundControlStreamHandler, unknownInboundStreamHandlerFactory, localSettings, disableQpackDynamicTable); this.requestStreamHandler = ObjectUtil.checkNotNull(requestStreamHandler, "requestStreamHandler"); diff --git a/src/main/java/io/netty/incubator/codec/http3/Http3ServerPushStreamManager.java b/src/main/java/io/netty/incubator/codec/http3/Http3ServerPushStreamManager.java index dd1258a9..d9aff4bd 100644 --- a/src/main/java/io/netty/incubator/codec/http3/Http3ServerPushStreamManager.java +++ b/src/main/java/io/netty/incubator/codec/http3/Http3ServerPushStreamManager.java @@ -27,6 +27,7 @@ import io.netty.util.ReferenceCountUtil; import io.netty.util.concurrent.Future; import io.netty.util.concurrent.Promise; +import org.jetbrains.annotations.Nullable; import java.util.concurrent.ConcurrentMap; import java.util.concurrent.atomic.AtomicLongFieldUpdater; @@ -139,7 +140,7 @@ public long reserveNextPushId() { * @param handler the {@link ChannelHandler} to add. Can be {@code null}. * @return the {@link Future} that will be notified once the push-stream was opened. */ - public Future newPushStream(long pushId, ChannelHandler handler) { + public Future newPushStream(long pushId, @Nullable ChannelHandler handler) { final Promise promise = channel.eventLoop().newPromise(); newPushStream(pushId, handler, promise); return promise; @@ -154,7 +155,7 @@ public Future newPushStream(long pushId, ChannelHandler handl * @param handler the {@link ChannelHandler} to add. Can be {@code null}. * @param promise to indicate creation of the push stream. */ - public void newPushStream(long pushId, ChannelHandler handler, Promise promise) { + public void newPushStream(long pushId, @Nullable ChannelHandler handler, Promise promise) { validatePushId(pushId); channel.createStream(QuicStreamType.UNIDIRECTIONAL, pushStreamInitializer(pushId, handler), promise); setupCancelPushIfStreamCreationFails(pushId, promise, channel); @@ -170,7 +171,7 @@ public void newPushStream(long pushId, ChannelHandler handler, Promise bootstrapConfigurator, Promise promise) { validatePushId(pushId); @@ -208,7 +209,7 @@ private void validatePushId(long pushId) { } } - private Http3PushStreamServerInitializer pushStreamInitializer(long pushId, ChannelHandler handler) { + private Http3PushStreamServerInitializer pushStreamInitializer(long pushId, @Nullable ChannelHandler handler) { final Http3PushStreamServerInitializer initializer; if (handler instanceof Http3PushStreamServerInitializer) { initializer = (Http3PushStreamServerInitializer) handler; diff --git a/src/main/java/io/netty/incubator/codec/http3/Http3SettingsFrame.java b/src/main/java/io/netty/incubator/codec/http3/Http3SettingsFrame.java index ee15f8e3..c75f6f5d 100644 --- a/src/main/java/io/netty/incubator/codec/http3/Http3SettingsFrame.java +++ b/src/main/java/io/netty/incubator/codec/http3/Http3SettingsFrame.java @@ -15,6 +15,8 @@ */ package io.netty.incubator.codec.http3; +import org.jetbrains.annotations.Nullable; + import java.util.Map; /** @@ -49,6 +51,7 @@ default long type() { * @param key the key of the setting. * @return the value of the setting or {@code null} if none was found with the given key. */ + @Nullable Long get(long key); /** @@ -70,5 +73,6 @@ default Long getOrDefault(long key, long defaultValue) { * @param value the value of the setting. * @return the previous stored valued for the given key or {@code null} if none was stored before. */ + @Nullable Long put(long key, Long value); } diff --git a/src/main/java/io/netty/incubator/codec/http3/Http3UnidirectionalStreamInboundClientHandler.java b/src/main/java/io/netty/incubator/codec/http3/Http3UnidirectionalStreamInboundClientHandler.java index f9a41a3a..e7c5930a 100644 --- a/src/main/java/io/netty/incubator/codec/http3/Http3UnidirectionalStreamInboundClientHandler.java +++ b/src/main/java/io/netty/incubator/codec/http3/Http3UnidirectionalStreamInboundClientHandler.java @@ -19,6 +19,7 @@ import io.netty.channel.ChannelHandler; import io.netty.channel.ChannelHandlerContext; import io.netty.incubator.codec.http3.Http3FrameCodec.Http3FrameCodecFactory; +import org.jetbrains.annotations.Nullable; import java.util.function.LongFunction; import java.util.function.Supplier; @@ -30,8 +31,8 @@ final class Http3UnidirectionalStreamInboundClientHandler extends Http3Unidirect Http3FrameCodecFactory codecFactory, Http3ControlStreamInboundHandler localControlStreamHandler, Http3ControlStreamOutboundHandler remoteControlStreamHandler, - LongFunction unknownStreamHandlerFactory, - LongFunction pushStreamHandlerFactory, + @Nullable LongFunction unknownStreamHandlerFactory, + @Nullable LongFunction pushStreamHandlerFactory, Supplier qpackEncoderHandlerFactory, Supplier qpackDecoderHandlerFactory) { super(codecFactory, localControlStreamHandler, remoteControlStreamHandler, unknownStreamHandlerFactory, qpackEncoderHandlerFactory, qpackDecoderHandlerFactory); diff --git a/src/main/java/io/netty/incubator/codec/http3/Http3UnidirectionalStreamInboundHandler.java b/src/main/java/io/netty/incubator/codec/http3/Http3UnidirectionalStreamInboundHandler.java index 70c5e7b0..ecaf9a5d 100644 --- a/src/main/java/io/netty/incubator/codec/http3/Http3UnidirectionalStreamInboundHandler.java +++ b/src/main/java/io/netty/incubator/codec/http3/Http3UnidirectionalStreamInboundHandler.java @@ -24,6 +24,7 @@ import io.netty.incubator.codec.http3.Http3FrameCodec.Http3FrameCodecFactory; import io.netty.util.AttributeKey; import io.netty.util.ReferenceCountUtil; +import org.jetbrains.annotations.Nullable; import java.util.List; import java.util.function.LongFunction; @@ -55,7 +56,7 @@ abstract class Http3UnidirectionalStreamInboundHandler extends ByteToMessageDeco Http3UnidirectionalStreamInboundHandler(Http3FrameCodecFactory codecFactory, Http3ControlStreamInboundHandler localControlStreamHandler, Http3ControlStreamOutboundHandler remoteControlStreamHandler, - LongFunction unknownStreamHandlerFactory, + @Nullable LongFunction unknownStreamHandlerFactory, Supplier qpackEncoderHandlerFactory, Supplier qpackDecoderHandlerFactory) { this.codecFactory = codecFactory; diff --git a/src/main/java/io/netty/incubator/codec/http3/Http3UnidirectionalStreamInboundServerHandler.java b/src/main/java/io/netty/incubator/codec/http3/Http3UnidirectionalStreamInboundServerHandler.java index eb7d380a..d8370a67 100644 --- a/src/main/java/io/netty/incubator/codec/http3/Http3UnidirectionalStreamInboundServerHandler.java +++ b/src/main/java/io/netty/incubator/codec/http3/Http3UnidirectionalStreamInboundServerHandler.java @@ -19,6 +19,7 @@ import io.netty.channel.ChannelHandler; import io.netty.channel.ChannelHandlerContext; import io.netty.incubator.codec.http3.Http3FrameCodec.Http3FrameCodecFactory; +import org.jetbrains.annotations.Nullable; import java.util.function.LongFunction; import java.util.function.Supplier; @@ -28,7 +29,7 @@ final class Http3UnidirectionalStreamInboundServerHandler extends Http3Unidirect Http3UnidirectionalStreamInboundServerHandler(Http3FrameCodecFactory codecFactory, Http3ControlStreamInboundHandler localControlStreamHandler, Http3ControlStreamOutboundHandler remoteControlStreamHandler, - LongFunction unknownStreamHandlerFactory, + @Nullable LongFunction unknownStreamHandlerFactory, Supplier qpackEncoderHandlerFactory, Supplier qpackDecoderHandlerFactory) { super(codecFactory, localControlStreamHandler, remoteControlStreamHandler, unknownStreamHandlerFactory, diff --git a/src/main/java/io/netty/incubator/codec/http3/HttpConversionUtil.java b/src/main/java/io/netty/incubator/codec/http3/HttpConversionUtil.java index fffe7b63..71989281 100644 --- a/src/main/java/io/netty/incubator/codec/http3/HttpConversionUtil.java +++ b/src/main/java/io/netty/incubator/codec/http3/HttpConversionUtil.java @@ -35,6 +35,7 @@ import io.netty.handler.codec.http.HttpVersion; import io.netty.util.AsciiString; import io.netty.util.internal.InternalThreadLocalMap; +import org.jetbrains.annotations.Nullable; import java.net.URI; import java.util.Iterator; @@ -146,7 +147,7 @@ public AsciiString text() { * @return The HTTP/1.x status * @throws Http3Exception If there is a problem translating from HTTP/3 to HTTP/1.x */ - private static HttpResponseStatus parseStatus(long streamId, CharSequence status) throws Http3Exception { + private static HttpResponseStatus parseStatus(long streamId, @Nullable CharSequence status) throws Http3Exception { HttpResponseStatus result; try { result = parseLine(status); @@ -523,7 +524,7 @@ private static AsciiString toHttp3Path(URI uri) { } // package-private for testing only - static void setHttp3Authority(String authority, Http3Headers out) { + static void setHttp3Authority(@Nullable String authority, Http3Headers out) { // The authority MUST NOT include the deprecated "userinfo" subcomponent if (authority != null) { if (authority.isEmpty()) { @@ -639,7 +640,8 @@ void translateHeaders(Iterable> inputHeaders) } } - private static Http3Exception streamError(long streamId, Http3ErrorCode error, String msg, Throwable cause) { + private static Http3Exception streamError(long streamId, Http3ErrorCode error, String msg, + @Nullable Throwable cause) { return new Http3Exception(error, streamId + ": " + msg, cause); } } diff --git a/src/main/java/io/netty/incubator/codec/http3/QpackEncoderDynamicTable.java b/src/main/java/io/netty/incubator/codec/http3/QpackEncoderDynamicTable.java index 3ad8103f..72ed1320 100644 --- a/src/main/java/io/netty/incubator/codec/http3/QpackEncoderDynamicTable.java +++ b/src/main/java/io/netty/incubator/codec/http3/QpackEncoderDynamicTable.java @@ -16,6 +16,7 @@ package io.netty.incubator.codec.http3; import io.netty.util.AsciiString; +import org.jetbrains.annotations.Nullable; import static io.netty.incubator.codec.http3.QpackHeaderField.ENTRY_OVERHEAD; import static io.netty.incubator.codec.http3.QpackUtil.MAX_HEADER_TABLE_SIZE; @@ -299,7 +300,7 @@ int relativeIndexForEncoderInstructions(int entryIndex) { * exists, then the index is returned. If an entry with only matching name exists then {@code -index-1} is * returned. */ - int getEntryIndex(CharSequence name, CharSequence value) { + int getEntryIndex(@Nullable CharSequence name, @Nullable CharSequence value) { if (tail != head && name != null && value != null) { int h = AsciiString.hashCode(name); int i = index(h); @@ -334,7 +335,7 @@ int getEntryIndex(CharSequence name, CharSequence value) { * @return Required * insert count if the passed entry has to be referenced in a header block. */ - int addReferenceToEntry(CharSequence name, CharSequence value, int idx) { + int addReferenceToEntry(@Nullable CharSequence name, @Nullable CharSequence value, int idx) { if (tail != head && name != null && value != null) { int h = AsciiString.hashCode(name); int i = index(h); @@ -466,7 +467,7 @@ private static final class HeaderEntry extends QpackHeaderField { */ final int index; - HeaderEntry(int hash, CharSequence name, CharSequence value, int index, HeaderEntry nextSibling) { + HeaderEntry(int hash, CharSequence name, CharSequence value, int index, @Nullable HeaderEntry nextSibling) { super(name, value); this.index = index; this.hash = hash; diff --git a/src/main/java/io/netty/incubator/codec/http3/QpackEncoderHandler.java b/src/main/java/io/netty/incubator/codec/http3/QpackEncoderHandler.java index 3f98caa8..0cbe31bc 100644 --- a/src/main/java/io/netty/incubator/codec/http3/QpackEncoderHandler.java +++ b/src/main/java/io/netty/incubator/codec/http3/QpackEncoderHandler.java @@ -21,6 +21,7 @@ import io.netty.handler.codec.ByteToMessageDecoder; import io.netty.incubator.codec.quic.QuicStreamChannel; import io.netty.util.AsciiString; +import org.jetbrains.annotations.Nullable; import java.util.List; @@ -36,7 +37,7 @@ final class QpackEncoderHandler extends ByteToMessageDecoder { private final QpackDecoder qpackDecoder; private boolean discard; - QpackEncoderHandler(Long maxTableCapacity, QpackDecoder qpackDecoder) { + QpackEncoderHandler(@Nullable Long maxTableCapacity, QpackDecoder qpackDecoder) { checkInRange(maxTableCapacity == null ? 0 : maxTableCapacity, 0, MAX_UNSIGNED_INT, "maxTableCapacity"); huffmanDecoder = new QpackHuffmanDecoder(); this.qpackDecoder = qpackDecoder; @@ -222,6 +223,7 @@ private void handleDecodeFailure(ChannelHandlerContext ctx, QpackException cause connectionError(ctx, new Http3Exception(QPACK_ENCODER_STREAM_ERROR, message, cause), true); } + @Nullable private CharSequence decodeLiteralValue(ByteBuf in) throws QpackException { final boolean valueHuffEncoded = QpackUtil.firstByteEquals(in, (byte) 0b1000_0000); int valueLength = decodePrefixedIntegerAsInt(in, 7); diff --git a/src/main/java/io/netty/incubator/codec/http3/QpackException.java b/src/main/java/io/netty/incubator/codec/http3/QpackException.java index 015009fb..4138bb69 100644 --- a/src/main/java/io/netty/incubator/codec/http3/QpackException.java +++ b/src/main/java/io/netty/incubator/codec/http3/QpackException.java @@ -16,13 +16,15 @@ package io.netty.incubator.codec.http3; import io.netty.util.internal.ThrowableUtil; +import org.jetbrains.annotations.Nullable; /** * Exception thrown if an error happens during QPACK processing. */ public final class QpackException extends Exception { - private QpackException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) { + private QpackException(String message, @Nullable Throwable cause, boolean enableSuppression, + boolean writableStackTrace) { super(message, cause, enableSuppression, writableStackTrace); } diff --git a/src/main/java/io/netty/incubator/codec/http3/internal/NotNullByDefault.java b/src/main/java/io/netty/incubator/codec/http3/internal/NotNullByDefault.java new file mode 100644 index 00000000..7a5c3d41 --- /dev/null +++ b/src/main/java/io/netty/incubator/codec/http3/internal/NotNullByDefault.java @@ -0,0 +1,43 @@ +/* + * Copyright 2024 The Netty Project + * + * The Netty Project licenses this file to you under the Apache License, + * version 2.0 (the "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at: + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + */ +package io.netty.incubator.codec.http3.internal; + + +import org.jetbrains.annotations.NotNull; + +import javax.annotation.meta.TypeQualifierDefault; +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Specifies that all parameters and return values of methods within a package should be treated as non-null by + * default, unless explicitly annotated with a nullness annotation such as {@link org.jetbrains.annotations.Nullable}. + *

+ * This annotation is applied at the package level and affects all types within the annotated package. + *

+ * Any nullness annotations explicitly applied to a parameter or return value within a package will override + * the default nullness behavior specified by {@link NotNullByDefault}. + */ +@Documented +@TypeQualifierDefault({ ElementType.PARAMETER, ElementType.METHOD }) +@Retention(RetentionPolicy.CLASS) +@Target(ElementType.PACKAGE) +@NotNull +public @interface NotNullByDefault { +} diff --git a/src/main/java/io/netty/incubator/codec/http3/internal/package-info.java b/src/main/java/io/netty/incubator/codec/http3/internal/package-info.java new file mode 100644 index 00000000..df3d01c2 --- /dev/null +++ b/src/main/java/io/netty/incubator/codec/http3/internal/package-info.java @@ -0,0 +1,21 @@ +/* + * Copyright 2024 The Netty Project + * + * The Netty Project licenses this file to you under the Apache License, + * version 2.0 (the "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at: + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + */ + +/** + * + */ + +package io.netty.incubator.codec.http3.internal; diff --git a/src/main/java/io/netty/incubator/codec/http3/package-info.java b/src/main/java/io/netty/incubator/codec/http3/package-info.java index 59df0a2e..5e14e002 100644 --- a/src/main/java/io/netty/incubator/codec/http3/package-info.java +++ b/src/main/java/io/netty/incubator/codec/http3/package-info.java @@ -17,4 +17,8 @@ /** * HTTP/3 implementation. */ + +@NotNullByDefault package io.netty.incubator.codec.http3; + +import io.netty.incubator.codec.http3.internal.NotNullByDefault; diff --git a/src/test/java/io/netty/incubator/codec/http3/AbstractHttp3FrameTypeValidationHandlerTest.java b/src/test/java/io/netty/incubator/codec/http3/AbstractHttp3FrameTypeValidationHandlerTest.java index 9e8a183b..e763e384 100644 --- a/src/test/java/io/netty/incubator/codec/http3/AbstractHttp3FrameTypeValidationHandlerTest.java +++ b/src/test/java/io/netty/incubator/codec/http3/AbstractHttp3FrameTypeValidationHandlerTest.java @@ -37,6 +37,7 @@ import static io.netty.incubator.codec.http3.Http3TestUtils.verifyClose; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assumptions.assumeTrue; @@ -76,6 +77,7 @@ protected void setUp(boolean server) { public void tearDown() { if (parent != null) { final QpackAttributes qpackAttributes = getQpackAttributes(parent); + assertNotNull(qpackAttributes); if (qpackAttributes.decoderStreamAvailable()) { assertFalse(((EmbeddedQuicStreamChannel) qpackAttributes.decoderStream()).finish()); } diff --git a/src/test/java/io/netty/incubator/codec/http3/EmbeddedQuicChannel.java b/src/test/java/io/netty/incubator/codec/http3/EmbeddedQuicChannel.java index 8ae886cf..7913cd3b 100644 --- a/src/test/java/io/netty/incubator/codec/http3/EmbeddedQuicChannel.java +++ b/src/test/java/io/netty/incubator/codec/http3/EmbeddedQuicChannel.java @@ -38,6 +38,7 @@ import io.netty.util.AttributeKey; import io.netty.util.concurrent.Future; import io.netty.util.concurrent.Promise; +import org.jetbrains.annotations.Nullable; import javax.net.ssl.SSLEngine; import java.util.Collection; @@ -89,6 +90,7 @@ public boolean isTimedOut() { } @Override + @Nullable public SSLEngine sslEngine() { return null; } @@ -147,11 +149,13 @@ public Future collectStats(Promise pro new UnsupportedOperationException("Collect stats not supported for embedded channel.")); } + @Nullable public EmbeddedQuicStreamChannel localControlStream() { return (EmbeddedQuicStreamChannel) Http3.getLocalControlStream(this); } @Override + @Nullable public QuicTransportParameters peerTransportParameters() { return null; } diff --git a/src/test/java/io/netty/incubator/codec/http3/EmbeddedQuicStreamChannel.java b/src/test/java/io/netty/incubator/codec/http3/EmbeddedQuicStreamChannel.java index 7f8ca23a..08f6b0fb 100644 --- a/src/test/java/io/netty/incubator/codec/http3/EmbeddedQuicStreamChannel.java +++ b/src/test/java/io/netty/incubator/codec/http3/EmbeddedQuicStreamChannel.java @@ -38,6 +38,7 @@ import io.netty.incubator.codec.quic.QuicStreamPriority; import io.netty.incubator.codec.quic.QuicStreamType; import io.netty.util.AttributeKey; +import org.jetbrains.annotations.Nullable; import java.net.SocketAddress; import java.util.Map; @@ -57,7 +58,7 @@ final class EmbeddedQuicStreamChannel extends EmbeddedChannel implements QuicStr this(null, false, QuicStreamType.BIDIRECTIONAL, 0, handlers); } - EmbeddedQuicStreamChannel(QuicChannel parent, boolean localCreated, QuicStreamType type, + EmbeddedQuicStreamChannel(@Nullable QuicChannel parent, boolean localCreated, QuicStreamType type, long id, ChannelHandler... handlers) { super(parent, DefaultChannelId.newInstance(), true, false, prependChannelConsumer(channel -> { @@ -97,6 +98,7 @@ public QuicStreamChannel read() { } @Override + @Nullable public QuicStreamPriority priority() { return null; } @@ -107,11 +109,13 @@ public ChannelFuture updatePriority(QuicStreamPriority priority, ChannelPromise } @Override + @Nullable public QuicStreamAddress localAddress() { return null; } @Override + @Nullable public QuicStreamAddress remoteAddress() { return null; } diff --git a/src/test/java/io/netty/incubator/codec/http3/Http3FrameToHttpObjectCodecTest.java b/src/test/java/io/netty/incubator/codec/http3/Http3FrameToHttpObjectCodecTest.java index d061f200..1e5e61a0 100644 --- a/src/test/java/io/netty/incubator/codec/http3/Http3FrameToHttpObjectCodecTest.java +++ b/src/test/java/io/netty/incubator/codec/http3/Http3FrameToHttpObjectCodecTest.java @@ -79,6 +79,7 @@ import java.util.stream.Stream; import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.notNullValue; import static org.hamcrest.CoreMatchers.nullValue; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.instanceOf; @@ -1057,13 +1058,16 @@ public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception stream.writeAndFlush(request); HttpResponse respHeaders = (HttpResponse) received.poll(20, TimeUnit.SECONDS); + assertThat(respHeaders, notNullValue()); assertThat(respHeaders.status(), is(HttpResponseStatus.OK)); assertThat(respHeaders, not(instanceOf(LastHttpContent.class))); HttpContent respBody = (HttpContent) received.poll(20, TimeUnit.SECONDS); + assertThat(respBody, notNullValue()); assertThat(respBody.content().toString(CharsetUtil.UTF_8), is("foo")); respBody.release(); LastHttpContent last = (LastHttpContent) received.poll(20, TimeUnit.SECONDS); + assertThat(last, notNullValue()); last.release(); } finally { group.shutdownGracefully(); diff --git a/src/test/java/io/netty/incubator/codec/http3/Http3RequestStreamValidationHandlerTest.java b/src/test/java/io/netty/incubator/codec/http3/Http3RequestStreamValidationHandlerTest.java index f5d34ec0..f65a3782 100644 --- a/src/test/java/io/netty/incubator/codec/http3/Http3RequestStreamValidationHandlerTest.java +++ b/src/test/java/io/netty/incubator/codec/http3/Http3RequestStreamValidationHandlerTest.java @@ -25,6 +25,7 @@ import io.netty.handler.codec.http.HttpResponseStatus; import io.netty.incubator.codec.quic.QuicStreamChannel; import io.netty.incubator.codec.quic.QuicStreamType; +import org.jetbrains.annotations.Nullable; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.MethodSource; @@ -502,7 +503,7 @@ private void testInformationalResponse(boolean server, boolean expectFail, Http3 assertFalse(channel.finish()); } - private void testHeadersFrame(Http3HeadersFrame headersFrame, Http3ErrorCode code) throws Exception { + private void testHeadersFrame(Http3HeadersFrame headersFrame, @Nullable Http3ErrorCode code) throws Exception { EmbeddedQuicStreamChannel channel = newServerStream(); try { assertTrue(channel.writeInbound(headersFrame)); diff --git a/src/test/java/io/netty/incubator/codec/http3/Http3ServerPushStreamManagerTest.java b/src/test/java/io/netty/incubator/codec/http3/Http3ServerPushStreamManagerTest.java index ab650b49..98d0a8ee 100644 --- a/src/test/java/io/netty/incubator/codec/http3/Http3ServerPushStreamManagerTest.java +++ b/src/test/java/io/netty/incubator/codec/http3/Http3ServerPushStreamManagerTest.java @@ -24,6 +24,7 @@ import io.netty.incubator.codec.quic.QuicStreamChannel; import io.netty.util.ReferenceCountUtil; import io.netty.util.concurrent.Promise; +import org.jetbrains.annotations.Nullable; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -140,7 +141,7 @@ public void pushStreamWithBootstrapWithHandler() throws Exception { assertTrue(pushStreamHandler.framesWritten.get(0) instanceof Http3HeadersFrame); } - private void pushStreamWithBootstrapCreateAndClose(ChannelHandler pushStreamHandler) throws Exception { + private void pushStreamWithBootstrapCreateAndClose(@Nullable ChannelHandler pushStreamHandler) throws Exception { pushStreamCreateAndClose(pushId -> newPushStreamWithBootstrap(pushStreamHandler, pushId)); } @@ -160,11 +161,13 @@ private void pushStreamCreateAndClose(PushStreamFactory pushStreamFactory) throw assertFalse(pushStream.isActive()); } - private EmbeddedQuicStreamChannel newPushStream(ChannelHandler pushStreamHandler, long pushId) throws Exception { + private EmbeddedQuicStreamChannel newPushStream(@Nullable ChannelHandler pushStreamHandler, + long pushId) throws Exception { return newPushStream(() -> (EmbeddedQuicStreamChannel) manager.newPushStream(pushId, pushStreamHandler).get()); } - private EmbeddedQuicStreamChannel newPushStreamWithBootstrap(ChannelHandler pushStreamHandler, long pushId) + private EmbeddedQuicStreamChannel newPushStreamWithBootstrap(@Nullable ChannelHandler pushStreamHandler, + long pushId) throws Exception { return newPushStream(() -> { final Promise promise = channel.eventLoop().newPromise(); diff --git a/src/test/java/io/netty/incubator/codec/http3/Http3UnidirectionalStreamInboundHandlerTest.java b/src/test/java/io/netty/incubator/codec/http3/Http3UnidirectionalStreamInboundHandlerTest.java index 9a0456eb..543e5b33 100644 --- a/src/test/java/io/netty/incubator/codec/http3/Http3UnidirectionalStreamInboundHandlerTest.java +++ b/src/test/java/io/netty/incubator/codec/http3/Http3UnidirectionalStreamInboundHandlerTest.java @@ -25,6 +25,7 @@ import io.netty.incubator.codec.quic.QuicStreamChannel; import io.netty.incubator.codec.quic.QuicStreamType; import io.netty.util.ReferenceCountUtil; +import org.jetbrains.annotations.Nullable; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.ValueSource; @@ -252,7 +253,8 @@ private EmbeddedChannel newChannel(boolean server) throws Exception { return newChannel(server, null); } - private EmbeddedChannel newChannel(boolean server, LongFunction unknownStreamHandlerFactory) + private EmbeddedChannel newChannel(boolean server, + @Nullable LongFunction unknownStreamHandlerFactory) throws Exception { Http3UnidirectionalStreamInboundHandler handler = newUniStreamInboundHandler(server, unknownStreamHandlerFactory); @@ -260,7 +262,7 @@ private EmbeddedChannel newChannel(boolean server, LongFunction } private Http3UnidirectionalStreamInboundHandler newUniStreamInboundHandler(boolean server, - LongFunction unknownStreamHandlerFactory) { + @Nullable LongFunction unknownStreamHandlerFactory) { return server ? new Http3UnidirectionalStreamInboundServerHandler((v, __, ___) -> new CodecHandler(), localControlStreamHandler, remoteControlStreamHandler, unknownStreamHandlerFactory, diff --git a/src/test/java/io/netty/incubator/codec/http3/QpackEncoderDecoderTest.java b/src/test/java/io/netty/incubator/codec/http3/QpackEncoderDecoderTest.java index 734c6565..4aeb3252 100644 --- a/src/test/java/io/netty/incubator/codec/http3/QpackEncoderDecoderTest.java +++ b/src/test/java/io/netty/incubator/codec/http3/QpackEncoderDecoderTest.java @@ -22,6 +22,7 @@ import io.netty.channel.ChannelOutboundHandlerAdapter; import io.netty.channel.ChannelPromise; import io.netty.util.AsciiString; +import org.jetbrains.annotations.Nullable; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Test; @@ -517,7 +518,8 @@ private static final class ForwardWriteToReadOnOtherHandler extends ChannelOutbo this(other, null); } - ForwardWriteToReadOnOtherHandler(ChannelInboundHandler other, BlockingQueue> suspendQueue) { + ForwardWriteToReadOnOtherHandler(ChannelInboundHandler other, + @Nullable BlockingQueue> suspendQueue) { this.other = other; this.suspendQueue = suspendQueue; } From fb1e7d14cb880968c2642f384cb6c30d31a36273 Mon Sep 17 00:00:00 2001 From: Simona Tankova Date: Sat, 2 Mar 2024 14:50:36 +0200 Subject: [PATCH 2/3] Move NotNullByDefault to its upper package in order to reduce its visibility --- .../{internal => }/NotNullByDefault.java | 2 +- .../codec/http3/internal/package-info.java | 21 ------------------- .../incubator/codec/http3/package-info.java | 1 - 3 files changed, 1 insertion(+), 23 deletions(-) rename src/main/java/io/netty/incubator/codec/http3/{internal => }/NotNullByDefault.java (97%) delete mode 100644 src/main/java/io/netty/incubator/codec/http3/internal/package-info.java diff --git a/src/main/java/io/netty/incubator/codec/http3/internal/NotNullByDefault.java b/src/main/java/io/netty/incubator/codec/http3/NotNullByDefault.java similarity index 97% rename from src/main/java/io/netty/incubator/codec/http3/internal/NotNullByDefault.java rename to src/main/java/io/netty/incubator/codec/http3/NotNullByDefault.java index 7a5c3d41..164f06cc 100644 --- a/src/main/java/io/netty/incubator/codec/http3/internal/NotNullByDefault.java +++ b/src/main/java/io/netty/incubator/codec/http3/NotNullByDefault.java @@ -13,7 +13,7 @@ * License for the specific language governing permissions and limitations * under the License. */ -package io.netty.incubator.codec.http3.internal; +package io.netty.incubator.codec.http3; import org.jetbrains.annotations.NotNull; diff --git a/src/main/java/io/netty/incubator/codec/http3/internal/package-info.java b/src/main/java/io/netty/incubator/codec/http3/internal/package-info.java deleted file mode 100644 index df3d01c2..00000000 --- a/src/main/java/io/netty/incubator/codec/http3/internal/package-info.java +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright 2024 The Netty Project - * - * The Netty Project licenses this file to you under the Apache License, - * version 2.0 (the "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at: - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ - -/** - * - */ - -package io.netty.incubator.codec.http3.internal; diff --git a/src/main/java/io/netty/incubator/codec/http3/package-info.java b/src/main/java/io/netty/incubator/codec/http3/package-info.java index 5e14e002..2ff7298a 100644 --- a/src/main/java/io/netty/incubator/codec/http3/package-info.java +++ b/src/main/java/io/netty/incubator/codec/http3/package-info.java @@ -21,4 +21,3 @@ @NotNullByDefault package io.netty.incubator.codec.http3; -import io.netty.incubator.codec.http3.internal.NotNullByDefault; From f51db800edfd49a2f5f42a260ee2f1b732f72cb7 Mon Sep 17 00:00:00 2001 From: Simona Tankova <82508193+simonatan@users.noreply.github.com> Date: Tue, 12 Mar 2024 15:58:16 +0200 Subject: [PATCH 3/3] Update src/main/java/io/netty/incubator/codec/http3/NotNullByDefault.java Co-authored-by: Norman Maurer --- .../java/io/netty/incubator/codec/http3/NotNullByDefault.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/io/netty/incubator/codec/http3/NotNullByDefault.java b/src/main/java/io/netty/incubator/codec/http3/NotNullByDefault.java index 164f06cc..5c33ad91 100644 --- a/src/main/java/io/netty/incubator/codec/http3/NotNullByDefault.java +++ b/src/main/java/io/netty/incubator/codec/http3/NotNullByDefault.java @@ -39,5 +39,5 @@ @Retention(RetentionPolicy.CLASS) @Target(ElementType.PACKAGE) @NotNull -public @interface NotNullByDefault { +@interface NotNullByDefault { }