Skip to content

Commit c50fb26

Browse files
Apply Nullable/NotNullByDefault annotations (#289)
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. --------- Co-authored-by: Norman Maurer <[email protected]>
1 parent e3e82d1 commit c50fb26

35 files changed

+167
-41
lines changed

pom.xml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -468,5 +468,17 @@
468468
<version>1.75</version>
469469
<scope>test</scope>
470470
</dependency>
471+
<dependency>
472+
<groupId>org.jetbrains</groupId>
473+
<artifactId>annotations</artifactId>
474+
<version>24.1.0</version>
475+
<scope>provided</scope>
476+
</dependency>
477+
<dependency>
478+
<groupId>com.google.code.findbugs</groupId>
479+
<artifactId>jsr305</artifactId>
480+
<version>3.0.2</version>
481+
<scope>provided</scope>
482+
</dependency>
471483
</dependencies>
472484
</project>

src/main/java/io/netty/incubator/codec/http3/DefaultHttp3Headers.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import io.netty.handler.codec.DefaultHeaders;
2020
import io.netty.util.AsciiString;
2121
import io.netty.util.ByteProcessor;
22+
import org.jetbrains.annotations.Nullable;
2223

2324
import static io.netty.incubator.codec.http3.Http3Headers.PseudoHeaderName.hasPseudoHeaderFormat;
2425
import static io.netty.util.AsciiString.CASE_INSENSITIVE_HASHER;
@@ -35,7 +36,7 @@ public boolean process(byte value) {
3536
};
3637
static final NameValidator<CharSequence> HTTP3_NAME_VALIDATOR = new NameValidator<CharSequence>() {
3738
@Override
38-
public void validateName(CharSequence name) {
39+
public void validateName(@Nullable CharSequence name) {
3940
if (name == null || name.length() == 0) {
4041
throw new Http3HeadersValidationException(String.format("empty headers are not allowed [%s]", name));
4142
}

src/main/java/io/netty/incubator/codec/http3/Http3.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import io.netty.incubator.codec.quic.QuicStreamType;
2727
import io.netty.util.AttributeKey;
2828
import io.netty.util.concurrent.Future;
29+
import org.jetbrains.annotations.Nullable;
2930

3031
/**
3132
* Contains utility methods that help to bootstrap server / clients with HTTP3 support.
@@ -53,6 +54,7 @@ private Http3() { }
5354
* @param channel the channel for the HTTP/3 connection.
5455
* @return the control stream.
5556
*/
57+
@Nullable
5658
public static QuicStreamChannel getLocalControlStream(Channel channel) {
5759
return channel.attr(HTTP3_CONTROL_STREAM_KEY).get();
5860
}
@@ -78,6 +80,7 @@ static void setLocalControlStream(Channel channel, QuicStreamChannel controlStre
7880
channel.attr(HTTP3_CONTROL_STREAM_KEY).set(controlStreamChannel);
7981
}
8082

83+
@Nullable
8184
static QpackAttributes getQpackAttributes(Channel channel) {
8285
return channel.attr(QPACK_ATTRIBUTES_KEY).get();
8386
}

src/main/java/io/netty/incubator/codec/http3/Http3ClientConnectionHandler.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import io.netty.channel.ChannelHandler;
1919
import io.netty.channel.ChannelHandlerContext;
2020
import io.netty.incubator.codec.quic.QuicStreamChannel;
21+
import org.jetbrains.annotations.Nullable;
2122

2223
import java.util.function.LongFunction;
2324

@@ -49,10 +50,10 @@ public Http3ClientConnectionHandler() {
4950
* remote peer or {@code null} if the default settings should be used.
5051
* @param disableQpackDynamicTable If QPACK dynamic table should be disabled.
5152
*/
52-
public Http3ClientConnectionHandler(ChannelHandler inboundControlStreamHandler,
53-
LongFunction<ChannelHandler> pushStreamHandlerFactory,
54-
LongFunction<ChannelHandler> unknownInboundStreamHandlerFactory,
55-
Http3SettingsFrame localSettings, boolean disableQpackDynamicTable) {
53+
public Http3ClientConnectionHandler(@Nullable ChannelHandler inboundControlStreamHandler,
54+
@Nullable LongFunction<ChannelHandler> pushStreamHandlerFactory,
55+
@Nullable LongFunction<ChannelHandler> unknownInboundStreamHandlerFactory,
56+
@Nullable Http3SettingsFrame localSettings, boolean disableQpackDynamicTable) {
5657
super(false, inboundControlStreamHandler, unknownInboundStreamHandlerFactory, localSettings,
5758
disableQpackDynamicTable);
5859
this.pushStreamHandlerFactory = pushStreamHandlerFactory;

src/main/java/io/netty/incubator/codec/http3/Http3CodecUtils.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import io.netty.util.CharsetUtil;
2727
import io.netty.util.internal.ObjectUtil;
2828
import io.netty.util.internal.StringUtil;
29+
import org.jetbrains.annotations.Nullable;
2930

3031
import static io.netty.channel.ChannelFutureListener.CLOSE_ON_FAILURE;
3132
import static io.netty.incubator.codec.http3.Http3ErrorCode.H3_INTERNAL_ERROR;
@@ -243,7 +244,7 @@ static void connectionError(ChannelHandlerContext ctx, Http3Exception exception,
243244
* @param fireException {@code true} if we should also fire the {@link Http3Exception} through the pipeline.
244245
*/
245246
static void connectionError(ChannelHandlerContext ctx, Http3ErrorCode errorCode,
246-
String msg, boolean fireException) {
247+
@Nullable String msg, boolean fireException) {
247248
if (fireException) {
248249
ctx.fireExceptionCaught(new Http3Exception(errorCode, msg));
249250
}
@@ -270,7 +271,7 @@ static void closeOnFailure(ChannelFuture future) {
270271
* @param errorCode the {@link Http3ErrorCode} that caused the error.
271272
* @param msg the message that should be used as reason for the error, may be {@code null}.
272273
*/
273-
static void connectionError(Channel channel, Http3ErrorCode errorCode, String msg) {
274+
static void connectionError(Channel channel, Http3ErrorCode errorCode, @Nullable String msg) {
274275
final QuicChannel quicChannel;
275276

276277
if (channel instanceof QuicChannel) {
@@ -306,6 +307,7 @@ static void readIfNoAutoRead(ChannelHandlerContext ctx) {
306307
* @param ch for which the {@link Http3ConnectionHandler} is to be retrieved.
307308
* @return {@link Http3ConnectionHandler} if available, else close the connection and return {@code null}.
308309
*/
310+
@Nullable
309311
static Http3ConnectionHandler getConnectionHandlerOrClose(QuicChannel ch) {
310312
Http3ConnectionHandler connectionHandler = ch.pipeline().get(Http3ConnectionHandler.class);
311313
if (connectionHandler == null) {

src/main/java/io/netty/incubator/codec/http3/Http3ConnectionHandler.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import io.netty.incubator.codec.quic.QuicChannel;
2323
import io.netty.incubator.codec.quic.QuicStreamChannel;
2424
import io.netty.incubator.codec.quic.QuicStreamType;
25+
import org.jetbrains.annotations.Nullable;
2526

2627
import java.util.function.LongFunction;
2728

@@ -58,9 +59,9 @@ public abstract class Http3ConnectionHandler extends ChannelInboundHandlerAdapte
5859
* remote peer or {@code null} if the default settings should be used.
5960
* @param disableQpackDynamicTable If QPACK dynamic table should be disabled.
6061
*/
61-
Http3ConnectionHandler(boolean server, ChannelHandler inboundControlStreamHandler,
62-
LongFunction<ChannelHandler> unknownInboundStreamHandlerFactory,
63-
Http3SettingsFrame localSettings, boolean disableQpackDynamicTable) {
62+
Http3ConnectionHandler(boolean server, @Nullable ChannelHandler inboundControlStreamHandler,
63+
@Nullable LongFunction<ChannelHandler> unknownInboundStreamHandlerFactory,
64+
@Nullable Http3SettingsFrame localSettings, boolean disableQpackDynamicTable) {
6465
this.unknownInboundStreamHandlerFactory = unknownInboundStreamHandlerFactory;
6566
this.disableQpackDynamicTable = disableQpackDynamicTable;
6667
if (localSettings == null) {

src/main/java/io/netty/incubator/codec/http3/Http3ControlStreamInboundHandler.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import io.netty.util.ReferenceCountUtil;
2727
import io.netty.util.concurrent.Future;
2828
import io.netty.util.concurrent.GenericFutureListener;
29+
import org.jetbrains.annotations.Nullable;
2930

3031
import java.nio.channels.ClosedChannelException;
3132

@@ -50,7 +51,8 @@ final class Http3ControlStreamInboundHandler extends Http3FrameTypeInboundValida
5051
private Long receivedGoawayId;
5152
private Long receivedMaxPushId;
5253

53-
Http3ControlStreamInboundHandler(boolean server, ChannelHandler controlFrameHandler, QpackEncoder qpackEncoder,
54+
Http3ControlStreamInboundHandler(boolean server, @Nullable ChannelHandler controlFrameHandler,
55+
QpackEncoder qpackEncoder,
5456
Http3ControlStreamOutboundHandler remoteControlStreamHandler) {
5557
super(Http3ControlStreamFrame.class);
5658
this.server = server;

src/main/java/io/netty/incubator/codec/http3/Http3ControlStreamOutboundHandler.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import io.netty.channel.socket.ChannelInputShutdownEvent;
2323
import io.netty.util.ReferenceCountUtil;
2424
import io.netty.util.internal.ObjectUtil;
25+
import org.jetbrains.annotations.Nullable;
2526

2627
import static io.netty.incubator.codec.http3.Http3CodecUtils.closeOnFailure;
2728

@@ -45,6 +46,7 @@ final class Http3ControlStreamOutboundHandler
4546
*
4647
* @return the id.
4748
*/
49+
@Nullable
4850
Long sentMaxPushId() {
4951
return sentMaxPushId;
5052
}

src/main/java/io/netty/incubator/codec/http3/Http3Exception.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
package io.netty.incubator.codec.http3;
1717

1818
import io.netty.util.internal.ObjectUtil;
19+
import org.jetbrains.annotations.Nullable;
1920

2021
/**
2122
* An exception related to violate the HTTP3 spec.
@@ -29,7 +30,7 @@ public final class Http3Exception extends Exception {
2930
* @param errorCode the {@link Http3ErrorCode} that caused this exception.
3031
* @param message the message to include.
3132
*/
32-
public Http3Exception(Http3ErrorCode errorCode, String message) {
33+
public Http3Exception(Http3ErrorCode errorCode, @Nullable String message) {
3334
super(message);
3435
this.errorCode = ObjectUtil.checkNotNull(errorCode, "errorCode");
3536
}
@@ -41,7 +42,7 @@ public Http3Exception(Http3ErrorCode errorCode, String message) {
4142
* @param message the message to include.
4243
* @param cause the {@link Throwable} to wrap.
4344
*/
44-
public Http3Exception(Http3ErrorCode errorCode, String message, Throwable cause) {
45+
public Http3Exception(Http3ErrorCode errorCode, String message, @Nullable Throwable cause) {
4546
super(message, cause);
4647
this.errorCode = ObjectUtil.checkNotNull(errorCode, "errorCode");
4748
}

src/main/java/io/netty/incubator/codec/http3/Http3FrameCodec.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import io.netty.util.ReferenceCountUtil;
2929
import io.netty.util.concurrent.Future;
3030
import io.netty.util.concurrent.GenericFutureListener;
31+
import org.jetbrains.annotations.Nullable;
3132

3233
import java.net.SocketAddress;
3334
import java.util.List;
@@ -349,6 +350,7 @@ private boolean enforceMaxPayloadLength(
349350
return in.readableBytes() >= payLoadLength;
350351
}
351352

353+
@Nullable
352354
private Http3SettingsFrame decodeSettings(ChannelHandlerContext ctx, ByteBuf in, int payLoadLength) {
353355
Http3SettingsFrame settingsFrame = new DefaultHttp3SettingsFrame();
354356
while (payLoadLength > 0) {

0 commit comments

Comments
 (0)