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

Ban @Nonnull and @NotNull annotations + cleanup #23755

Merged
merged 3 commits into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,12 @@
import com.google.common.collect.AbstractIterator;
import com.google.common.io.Closer;
import io.trino.client.JsonDecodingUtils.TypeDecoder;
import jakarta.annotation.Nonnull;
import org.gaul.modernizer_maven_annotations.SuppressModernizer;

import java.io.IOException;
import java.io.InputStream;
import java.io.UncheckedIOException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import static com.fasterxml.jackson.core.JsonParser.Feature.AUTO_CLOSE_SOURCE;
Expand Down Expand Up @@ -139,32 +137,24 @@ private void close()

public static ResultRows forJsonParser(JsonParser parser, List<Column> columns)
{
return new ResultRows() {
@Override
public @Nonnull Iterator<List<Object>> iterator()
{
try {
return new RowWiseIterator(parser, createTypeDecoders(columns));
}
catch (IOException e) {
throw new UncheckedIOException(e);
}
return () -> {
try {
return new RowWiseIterator(parser, createTypeDecoders(columns));
}
catch (IOException e) {
throw new UncheckedIOException(e);
}
};
}

public static ResultRows forInputStream(InputStream stream, TypeDecoder[] decoders)
{
return new ResultRows() {
@Override
public @Nonnull Iterator<List<Object>> iterator()
{
try {
return new RowWiseIterator(stream, decoders);
}
catch (IOException e) {
throw new UncheckedIOException(e);
}
return () -> {
try {
return new RowWiseIterator(stream, decoders);
}
catch (IOException e) {
throw new UncheckedIOException(e);
}
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
*/
package io.trino.client;

import jakarta.annotation.Nonnull;
import jakarta.annotation.Nullable;

import java.util.List;
Expand All @@ -35,7 +34,7 @@ private RawQueryData(Iterable<List<Object>> values)
this.iterable = values == null ? null : unmodifiableIterable(values);
}

public @Nonnull Iterable<List<Object>> getIterable()
public Iterable<List<Object>> getIterable()
{
checkState(iterable != null, "cannot return a null iterable");
return iterable;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
*/
package io.trino.client;

import jakarta.annotation.Nonnull;

import java.util.Iterator;
import java.util.List;

Expand All @@ -36,7 +34,7 @@ public boolean isNull()
}

@Override
public @Nonnull Iterator<List<Object>> iterator()
public Iterator<List<Object>> iterator()
{
return emptyIterator();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
*/
package io.trino.client;

import jakarta.annotation.Nonnull;
import jakarta.annotation.Nullable;

import java.io.Closeable;
Expand Down Expand Up @@ -45,7 +44,7 @@ public interface StatementClient
// For backward compatibility and migration path
QueryData currentData();

@Nonnull ResultRows currentRows();
ResultRows currentRows();

QueryStatusInfo finalStatusInfo();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import com.google.errorprone.annotations.ThreadSafe;
import io.airlift.units.Duration;
import io.trino.client.spooling.SegmentLoader;
import jakarta.annotation.Nonnull;
import jakarta.annotation.Nullable;
import okhttp3.Call;
import okhttp3.Headers;
Expand Down Expand Up @@ -255,7 +254,6 @@ public QueryStatusInfo currentStatusInfo()
}

@Override
@Nonnull
public ResultRows currentRows()
{
checkState(isRunning(), "current position is not valid (cursor past end)");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import io.trino.client.StatementClient;
import io.trino.client.StatementStats;
import io.trino.client.Warning;
import jakarta.annotation.Nonnull;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;

Expand Down Expand Up @@ -174,7 +173,6 @@ public QueryData currentData()
}

@Override
@Nonnull
public ResultRows currentRows()
{
return queryData.get();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@
import io.trino.tracing.ScopedSpan;
import io.trino.tracing.TrinoAttributes;
import io.trino.type.UnknownType;
import jakarta.annotation.Nonnull;

import java.util.AbstractMap.SimpleImmutableEntry;
import java.util.ArrayList;
Expand Down Expand Up @@ -301,7 +300,6 @@ public Plan plan(Analysis analysis, Stage stage, boolean collectPlanStatistics)
return new Plan(root, statsAndCosts);
}

@Nonnull
private PlanNode runOptimizer(PlanNode root, TableStatsProvider tableStatsProvider, PlanOptimizer optimizer)
{
PlanNode result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
import it.unimi.dsi.fastutil.longs.LongOpenCustomHashSet;
import it.unimi.dsi.fastutil.longs.LongOpenHashSet;
import it.unimi.dsi.fastutil.objects.ObjectOpenCustomHashSet;
import jakarta.annotation.Nonnull;

import java.lang.invoke.MethodHandle;
import java.math.BigInteger;
Expand Down Expand Up @@ -159,7 +158,6 @@ public boolean contains(long value)
}

@Override
@Nonnull
public LongIterator iterator()
{
PrimitiveIterator.OfInt iterator = bitmask.stream().iterator();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import io.trino.spi.type.MapType;
import io.trino.spi.type.Type;
import it.unimi.dsi.fastutil.ints.IntArrayList;
import jakarta.annotation.Nonnull;
import jakarta.annotation.Nullable;

import java.io.IOException;
Expand Down Expand Up @@ -65,12 +64,10 @@ public class MapColumnReader
private int readOffset;
private int nextBatchSize;

@Nonnull
private InputStreamSource<BooleanInputStream> presentStreamSource = missingStreamSource(BooleanInputStream.class);
@Nullable
private BooleanInputStream presentStream;

@Nonnull
private InputStreamSource<LongInputStream> lengthStreamSource = missingStreamSource(LongInputStream.class);
@Nullable
private LongInputStream lengthStream;
Expand Down
14 changes: 14 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2534,6 +2534,20 @@
<bannedImport>org.testng.asserts.**</bannedImport>
</bannedImports>
</RestrictImports>
<RestrictImports>
<reason>Trino assumes non-nullness by default, otherwise it's marked as @Nullable</reason>
<bannedImports>
<bannedImport>jakarta.annotation.Nonnull</bannedImport>
<bannedImport>org.jetbrains.annotations.NotNull</bannedImport>
</bannedImports>
<notFixable>
<in>io.trino.cache.ElementTypesAreNonnullByDefault</in>
<allowedImports>
<allowedImport>jakarta.annotation.Nonnull</allowedImport>
</allowedImports>
<because>Extending Guava's API</because>
</notFixable>
</RestrictImports>
<RestrictImports>
<bannedImports>
<bannedImport>com.google.api.client.util.Preconditions</bannedImport>
Expand Down
Loading