Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply Nullable/NotNullByDefault annotations #289

Merged
merged 4 commits into from
Mar 28, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -468,5 +468,17 @@
<version>1.75</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jetbrains</groupId>
<artifactId>annotations</artifactId>
<version>24.1.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.google.code.findbugs</groupId>
<artifactId>jsr305</artifactId>
<version>3.0.2</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -35,7 +36,7 @@ public boolean process(byte value) {
};
static final NameValidator<CharSequence> HTTP3_NAME_VALIDATOR = new NameValidator<CharSequence>() {
@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));
}
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/io/netty/incubator/codec/http3/Http3.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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();
}
Expand All @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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<ChannelHandler> pushStreamHandlerFactory,
LongFunction<ChannelHandler> unknownInboundStreamHandlerFactory,
Http3SettingsFrame localSettings, boolean disableQpackDynamicTable) {
public Http3ClientConnectionHandler(@Nullable ChannelHandler inboundControlStreamHandler,
@Nullable LongFunction<ChannelHandler> pushStreamHandlerFactory,
@Nullable LongFunction<ChannelHandler> unknownInboundStreamHandlerFactory,
@Nullable Http3SettingsFrame localSettings, boolean disableQpackDynamicTable) {
super(false, inboundControlStreamHandler, unknownInboundStreamHandlerFactory, localSettings,
disableQpackDynamicTable);
this.pushStreamHandlerFactory = pushStreamHandlerFactory;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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));
}
Expand All @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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<ChannelHandler> unknownInboundStreamHandlerFactory,
Http3SettingsFrame localSettings, boolean disableQpackDynamicTable) {
Http3ConnectionHandler(boolean server, @Nullable ChannelHandler inboundControlStreamHandler,
@Nullable LongFunction<ChannelHandler> unknownInboundStreamHandlerFactory,
@Nullable Http3SettingsFrame localSettings, boolean disableQpackDynamicTable) {
this.unknownInboundStreamHandlerFactory = unknownInboundStreamHandlerFactory;
this.disableQpackDynamicTable = disableQpackDynamicTable;
if (localSettings == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -45,6 +46,7 @@ final class Http3ControlStreamOutboundHandler
*
* @return the id.
*/
@Nullable
Long sentMaxPushId() {
return sentMaxPushId;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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");
}
Expand All @@ -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");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -221,7 +222,7 @@ private static ChannelPromise writeWithOptionalCombiner(
ChannelHandlerContext ctx,
Object msg,
ChannelPromise outerPromise,
PromiseCombiner combiner,
@Nullable PromiseCombiner combiner,
boolean unvoidPromise
) {
if (unvoidPromise) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -44,6 +45,7 @@ private static <T> boolean isValid(Class<T> frameType, Object msg) {
* @param <T> 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> T validateFrameWritten(Class<T> expectedFrameType, Object msg) {
if (isValid(expectedFrameType, msg)) {
return cast(msg);
Expand All @@ -60,6 +62,7 @@ static <T> T validateFrameWritten(Class<T> expectedFrameType, Object msg) {
* @param <T> 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> T validateFrameRead(Class<T> expectedFrameType, Object msg) {
if (isValid(expectedFrameType, msg)) {
return cast(msg);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -180,34 +182,39 @@ public boolean isRequestOnly() {
*
* @return the value of the header.
*/
@Nullable
CharSequence method();

/**
* Gets the {@link PseudoHeaderName#SCHEME} header or {@code null} if there is no such header
*
* @return the value of the header.
*/
@Nullable
CharSequence scheme();

/**
* Gets the {@link PseudoHeaderName#AUTHORITY} header or {@code null} if there is no such header
*
* @return the value of the header.
*/
@Nullable
CharSequence authority();

/**
* Gets the {@link PseudoHeaderName#PATH} header or {@code null} if there is no such header
*
* @return the value of the header.
*/
@Nullable
CharSequence path();

/**
* Gets the {@link PseudoHeaderName#STATUS} header or {@code null} if there is no such header
*
* @return the value of the header.
*/
@Nullable
CharSequence status();

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -58,9 +59,9 @@ public Http3ServerConnectionHandler(ChannelHandler requestStreamHandler) {
* @param disableQpackDynamicTable If QPACK dynamic table should be disabled.
*/
public Http3ServerConnectionHandler(ChannelHandler requestStreamHandler,
ChannelHandler inboundControlStreamHandler,
LongFunction<ChannelHandler> unknownInboundStreamHandlerFactory,
Http3SettingsFrame localSettings, boolean disableQpackDynamicTable) {
@Nullable ChannelHandler inboundControlStreamHandler,
@Nullable LongFunction<ChannelHandler> unknownInboundStreamHandlerFactory,
@Nullable Http3SettingsFrame localSettings, boolean disableQpackDynamicTable) {
super(true, inboundControlStreamHandler, unknownInboundStreamHandlerFactory, localSettings,
disableQpackDynamicTable);
this.requestStreamHandler = ObjectUtil.checkNotNull(requestStreamHandler, "requestStreamHandler");
Expand Down
Loading