Skip to content

Commit

Permalink
Explicitly annotate some null-unmarked classes as @NullUnmarked.
Browse files Browse the repository at this point in the history
This is redundant for now, though it is arguably nice to be explicit. However, my actual motivation is that I expect to use a package-level `@NullMarked` annotation (contrary to my usual recommendation) in order to help external Java 8 users whose tools might be upset by the `@Target(..., MODULE)` that they are more likely to discover if `@NullMarked` appears on individual classes.

RELNOTES=n/a
PiperOrigin-RevId: 707946250
  • Loading branch information
cpovirk authored and Google Java Core Libraries committed Dec 19, 2024
1 parent 24e20e4 commit a0b90e7
Show file tree
Hide file tree
Showing 987 changed files with 2,086 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
import javax.annotation.CheckForNull;
import junit.framework.Assert;
import junit.framework.AssertionFailedError;
import org.jspecify.annotations.NullUnmarked;
import org.checkerframework.checker.nullness.qual.Nullable;

/**
Expand Down Expand Up @@ -81,6 +82,8 @@
*/
@GwtIncompatible
@J2ktIncompatible
@NullUnmarked
@SuppressWarnings("nullness")
public final class ClassSanityTester {

private static final Ordering<Invokable<?, ?>> BY_METHOD_NAME =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@
import java.util.concurrent.atomic.AtomicInteger;
import java.util.regex.Pattern;
import javax.annotation.CheckForNull;
import org.jspecify.annotations.NullUnmarked;
import org.checkerframework.checker.nullness.qual.Nullable;

/**
Expand All @@ -130,6 +131,8 @@
*/
@GwtIncompatible
@J2ktIncompatible
@NullUnmarked
@SuppressWarnings("nullness")
class FreshValueGenerator {

private static final ImmutableMap<Class<?>, Method> GENERATORS;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,14 @@
import java.util.Arrays;
import java.util.List;
import junit.framework.TestCase;
import org.jspecify.annotations.NullUnmarked;

/**
* Unit tests for {@link AbstractPackageSanityTests}.
*
* @author Ben Yu
*/
@NullUnmarked
public class AbstractPackageSanityTestsTest extends TestCase {
/*
* This is a public type so that the Android test runner can create an instance directly as it
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,13 +129,15 @@
import java.util.regex.MatchResult;
import java.util.regex.Pattern;
import junit.framework.TestCase;
import org.jspecify.annotations.NullUnmarked;
import org.checkerframework.checker.nullness.qual.Nullable;

/**
* Unit test for {@link ArbitraryInstances}.
*
* @author Ben Yu
*/
@NullUnmarked
public class ArbitraryInstancesTest extends TestCase {

public void testGet_primitives() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import java.util.Set;
import junit.framework.AssertionFailedError;
import junit.framework.TestCase;
import org.jspecify.annotations.NullUnmarked;
import org.checkerframework.checker.nullness.qual.Nullable;

/**
Expand All @@ -35,6 +36,7 @@
*/
@GwtCompatible
@SuppressWarnings("MissingTestCall")
@NullUnmarked
public class EqualsTesterTest extends TestCase {
private ValidTestObject reference;
private EqualsTester equalsTester;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,15 @@
import com.google.common.collect.ImmutableTable;
import junit.framework.AssertionFailedError;
import junit.framework.TestCase;
import org.jspecify.annotations.NullUnmarked;

/**
* Tests for {@link EquivalenceTester}.
*
* @author Gregory Kick
*/
@GwtCompatible
@NullUnmarked
public class EquivalenceTesterTest extends TestCase {
private EquivalenceTester<Object> tester;
private MockEquivalence equivalenceMock;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import junit.framework.TestCase;
import org.jspecify.annotations.NullUnmarked;
import org.checkerframework.checker.nullness.qual.Nullable;

/**
Expand All @@ -41,6 +42,7 @@
@GwtCompatible(emulated = true)
// We also want to test the TimeUnit overload (especially under GWT, where it's the only option).
@SuppressWarnings("SetAutoIncrementStep_Nanos")
@NullUnmarked
public class FakeTickerTest extends TestCase {

@GwtIncompatible // NullPointerTester
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,14 @@
import java.util.regex.MatchResult;
import java.util.regex.Pattern;
import junit.framework.TestCase;
import org.jspecify.annotations.NullUnmarked;

/**
* Tests for {@link FreshValueGenerator}.
*
* @author Ben Yu
*/
@NullUnmarked
public class FreshValueGeneratorTest extends TestCase {

@AndroidIncompatible // problem with equality of Type objects?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.atomic.AtomicBoolean;
import junit.framework.TestCase;
import org.jspecify.annotations.NullUnmarked;
import org.checkerframework.checker.nullness.qual.Nullable;

/**
Expand All @@ -36,6 +37,7 @@
*/
@AndroidIncompatible // depends on details of gc

@NullUnmarked
public class GcFinalizationTest extends TestCase {

// ----------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@

package com.google.common.testing;

import org.jspecify.annotations.NullUnmarked;

/** Test nulls for the entire package. */

@NullUnmarked
public class PackageSanityTests extends AbstractPackageSanityTests {}
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@

import com.google.common.testing.RelationshipTester.ItemReporter;
import junit.framework.TestCase;
import org.jspecify.annotations.NullUnmarked;

/**
* Tests for {@link RelationshipTester}.
*
* @author Ben Yu
*/
@NullUnmarked
public class RelationshipTesterTest extends TestCase {

public void testNulls() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@
import java.io.Serializable;
import junit.framework.AssertionFailedError;
import junit.framework.TestCase;
import org.jspecify.annotations.NullUnmarked;
import org.checkerframework.checker.nullness.qual.Nullable;

/**
* Tests for {@link SerializableTester}.
*
* @author Nick Kralevich
*/
@NullUnmarked
public class SerializableTesterTest extends TestCase {
public void testStringAssertions() {
String original = "hello world";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,14 @@

import com.google.common.annotations.GwtCompatible;
import junit.framework.TestCase;
import org.jspecify.annotations.NullUnmarked;
import org.checkerframework.checker.nullness.qual.Nullable;

/** @author Luiz-Otavio "Z" Zorzella */
/**
* @author Luiz-Otavio "Z" Zorzella
*/
@GwtCompatible
@NullUnmarked
public class TearDownStackTest extends TestCase {

private TearDownStack tearDownStack = new TearDownStack();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@
import java.util.logging.LogRecord;
import java.util.logging.Logger;
import junit.framework.TestCase;
import org.jspecify.annotations.NullUnmarked;

/**
* Unit test for {@link TestLogHandler}.
*
* @author kevinb
*/
@NullUnmarked
public class TestLogHandlerTest extends TestCase {

private TestLogHandler handler;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,14 @@
import java.util.List;
import java.util.Locale;
import java.util.Random;
import org.jspecify.annotations.NullUnmarked;

/**
* Benchmarks for the ASCII class.
*
* @author Kevin Bourrillion
*/
@NullUnmarked
public class AsciiBenchmark {
private static final String ALPHA = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
private static final String NONALPHA = "0123456789`~-_=+[]{}|;:',.<>/?!@#$%^&*()\"\\";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import java.util.Collections;
import java.util.List;
import java.util.Random;
import org.jspecify.annotations.NullUnmarked;

/**
* Benchmark for the {@link CharMatcher} class.
Expand All @@ -33,6 +34,7 @@
* @author Kevin Bourrillion
* @author David Richter
*/
@NullUnmarked
public class CharMatcherBenchmark {

// Caliper injects params automatically
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.jspecify.annotations.NullUnmarked;

@SuppressWarnings("unused") // Nested enums used reflectively in setUp.
@NullUnmarked
public class EnumsBenchmark {

@Param({"Small", "Medium", "Large"})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@
import com.google.caliper.Param;
import java.util.Arrays;
import java.util.Iterator;
import org.jspecify.annotations.NullUnmarked;

/**
* Benchmarks {@link Joiner} against some common implementations of delimiter-based string joining.
*
* @author Adomas Paltanavicius
*/
@NullUnmarked
public class JoinerBenchmark {

private static final String DELIMITER_STRING = ",";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@
import com.google.caliper.Param;
import com.google.caliper.api.SkipThisScenarioException;
import java.util.List;
import org.jspecify.annotations.NullUnmarked;

/**
* Quick and dirty benchmark of {@link Throwables#lazyStackTrace(Throwable)}. We benchmark a "caller
* finder" implementation that might be used in a logging framework.
*/
@NullUnmarked
public class LazyStackTraceBenchmark {
@Param({"20", "200", "2000"})
int stackDepth;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@
package com.google.common.base;

import com.google.caliper.Benchmark;
import org.jspecify.annotations.NullUnmarked;

/**
* Some microbenchmarks for the {@link com.google.common.base.Objects} class.
*
* @author Ben L. Titzer
*/
@NullUnmarked
public class ObjectsBenchmark {

private static final Integer I0 = -45;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@
import com.google.caliper.Benchmark;
import com.google.caliper.Param;
import com.google.common.collect.Iterables;
import org.jspecify.annotations.NullUnmarked;

/**
* Microbenchmark for {@link Splitter#on} with char vs String with length == 1.
*
* @author Paul Lindner
*/
@NullUnmarked
public class SplitterBenchmark {
// overall size of string
@Param({"1", "10", "100", "1000"})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@
import static java.util.concurrent.TimeUnit.NANOSECONDS;

import com.google.caliper.Benchmark;
import org.jspecify.annotations.NullUnmarked;

/**
* Simple benchmark: create, start, read. This does not currently report the most useful result
* because it's ambiguous to what extent the stopwatch benchmark is being affected by GC.
*
* @author Kevin Bourrillion
*/
@NullUnmarked
public class StopwatchBenchmark {
@Benchmark
long stopwatch(int reps) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@
import com.google.caliper.BeforeExperiment;
import com.google.caliper.Benchmark;
import com.google.caliper.Param;
import org.jspecify.annotations.NullUnmarked;

/**
* Microbenchmark for {@link com.google.common.base.Strings#repeat}
*
* @author Mike Cripps
*/
@NullUnmarked
public class StringsRepeatBenchmark {
@Param({"1", "5", "25", "125"})
int count;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@
import com.google.caliper.Param;
import java.util.Arrays;
import java.util.Collections;
import org.jspecify.annotations.NullUnmarked;

/**
* Some microbenchmarks for the {@link MoreObjects.ToStringHelper} class.
*
* @author Osvaldo Doederlein
*/
@NullUnmarked
public class ToStringHelperBenchmark {

@Param({"0", "1", "5"})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@
import com.google.caliper.Param;
import java.util.BitSet;
import java.util.Random;
import org.jspecify.annotations.NullUnmarked;

/** Benchmark for the {@link CharMatcher#whitespace} implementation. */
@NullUnmarked
public class WhitespaceMatcherBenchmark {
private static final int STRING_LENGTH = 10000;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.google.caliper.Benchmark;
import com.google.caliper.Param;
import com.google.common.cache.LocalCache.Segment;
import org.jspecify.annotations.NullUnmarked;
import org.checkerframework.checker.nullness.qual.Nullable;

/**
Expand All @@ -28,6 +29,7 @@
* @author Charles Fry
*/
@SuppressWarnings("CheckReturnValue")
@NullUnmarked
public class ChainBenchmark {

@Param({"1", "2", "3", "4", "5", "6"})
Expand Down
Loading

0 comments on commit a0b90e7

Please sign in to comment.