Skip to content

Commit c39d244

Browse files
committed
Enable new ReturnMissingNullable Error Prone experimental suggestion.
I also added some missing Nullable annotations.
1 parent 8b84943 commit c39d244

11 files changed

Lines changed: 28 additions & 0 deletions

File tree

api/src/main/java/io/opencensus/stats/NoopStats.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import java.util.Collections;
3434
import java.util.List;
3535
import java.util.Map;
36+
import javax.annotation.Nullable;
3637
import javax.annotation.concurrent.GuardedBy;
3738
import javax.annotation.concurrent.Immutable;
3839
import javax.annotation.concurrent.ThreadSafe;
@@ -160,6 +161,7 @@ public void registerView(View newView) {
160161
}
161162

162163
@Override
164+
@Nullable
163165
public ViewData getView(View.Name name) {
164166
checkNotNull(name, "name");
165167
synchronized (views) {

api/src/test/java/io/opencensus/tags/TagContextTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import java.util.Collections;
2424
import java.util.Iterator;
2525
import java.util.List;
26+
import javax.annotation.Nullable;
2627
import org.junit.Test;
2728
import org.junit.runner.RunWith;
2829
import org.junit.runners.JUnit4;
@@ -94,6 +95,7 @@ private static final class SimpleTagContext extends TagContext {
9495
}
9596

9697
@Override
98+
@Nullable
9799
protected Iterator<Tag> getIterator() {
98100
return tags == null ? null : tags.iterator();
99101
}

api/src/test/java/io/opencensus/trace/AttributeValueTest.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import com.google.common.testing.EqualsTester;
2323
import io.opencensus.common.Function;
2424
import io.opencensus.common.Functions;
25+
import javax.annotation.Nullable;
2526
import org.junit.Test;
2627
import org.junit.runner.RunWith;
2728
import org.junit.runners.JUnit4;
@@ -35,20 +36,23 @@ public void stringAttributeValue() {
3536
attribute.match(
3637
new Function<String, Object>() {
3738
@Override
39+
@Nullable
3840
public Object apply(String stringValue) {
3941
assertThat(stringValue).isEqualTo("MyStringAttributeValue");
4042
return null;
4143
}
4244
},
4345
new Function<Boolean, Object>() {
4446
@Override
47+
@Nullable
4548
public Object apply(Boolean booleanValue) {
4649
fail("Expected a String");
4750
return null;
4851
}
4952
},
5053
new Function<Long, Object>() {
5154
@Override
55+
@Nullable
5256
public Object apply(Long longValue) {
5357
fail("Expected a String");
5458
return null;
@@ -63,20 +67,23 @@ public void booleanAttributeValue() {
6367
attribute.match(
6468
new Function<String, Object>() {
6569
@Override
70+
@Nullable
6671
public Object apply(String stringValue) {
6772
fail("Expected a Boolean");
6873
return null;
6974
}
7075
},
7176
new Function<Boolean, Object>() {
7277
@Override
78+
@Nullable
7379
public Object apply(Boolean booleanValue) {
7480
assertThat(booleanValue).isTrue();
7581
return null;
7682
}
7783
},
7884
new Function<Long, Object>() {
7985
@Override
86+
@Nullable
8087
public Object apply(Long longValue) {
8188
fail("Expected a Boolean");
8289
return null;
@@ -91,20 +98,23 @@ public void longAttributeValue() {
9198
attribute.match(
9299
new Function<String, Object>() {
93100
@Override
101+
@Nullable
94102
public Object apply(String stringValue) {
95103
fail("Expected a Long");
96104
return null;
97105
}
98106
},
99107
new Function<Boolean, Object>() {
100108
@Override
109+
@Nullable
101110
public Object apply(Boolean booleanValue) {
102111
fail("Expected a Long");
103112
return null;
104113
}
105114
},
106115
new Function<Long, Object>() {
107116
@Override
117+
@Nullable
108118
public Object apply(Long longValue) {
109119
assertThat(longValue).isEqualTo(123456L);
110120
return null;

exporters/trace/zipkin/src/main/java/io/opencensus/exporter/trace/zipkin/ZipkinExporterHandler.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
import java.util.Map;
4343
import java.util.logging.Level;
4444
import java.util.logging.Logger;
45+
import javax.annotation.Nullable;
4546
import zipkin2.Endpoint;
4647
import zipkin2.Span;
4748
import zipkin2.codec.SpanBytesEncoder;
@@ -146,6 +147,7 @@ private static String encodeSpanId(SpanId spanId) {
146147
return BaseEncoding.base16().lowerCase().encode(spanId.getBytes());
147148
}
148149

150+
@Nullable
149151
private static Span.Kind toSpanKind(SpanData spanData) {
150152
if (Boolean.TRUE.equals(spanData.getHasRemoteParent())) {
151153
return Span.Kind.SERVER;

gradle/errorprone/experimental_suggestions

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ errorProneExperimentalSuggestions = \
99
-Xep:PrivateConstructorForNoninstantiableModuleTest:ERROR,\
1010
-Xep:PrivateConstructorForUtilityClass:ERROR,\
1111
-Xep:RemoveUnusedImports:ERROR,\
12+
-Xep:ReturnMissingNullable:ERROR,\
1213
-Xep:ThrowsUncheckedException:ERROR,\
1314
-Xep:UnnecessaryStaticImport:ERROR,\
1415
-Xep:UseBinds:ERROR,\

impl_core/src/main/java/io/opencensus/implcore/stats/MeasureToViewMap.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ final class MeasureToViewMap {
5858
private final Map<String, Measure> registeredMeasures = Maps.newHashMap();
5959

6060
/** Returns a {@link ViewData} corresponding to the given {@link View.Name}. */
61+
@Nullable
6162
synchronized ViewData getView(View.Name viewName, Clock clock, StatsCollectionState state) {
6263
MutableViewData view = getMutableViewData(viewName);
6364
return view == null ? null : view.toViewData(clock.now(), state);

impl_core/src/main/java/io/opencensus/implcore/stats/StatsManager.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import io.opencensus.stats.View;
2525
import io.opencensus.stats.ViewData;
2626
import io.opencensus.tags.TagContext;
27+
import javax.annotation.Nullable;
2728

2829
/** Object that stores all views and stats. */
2930
final class StatsManager {
@@ -49,6 +50,7 @@ void registerView(View view) {
4950
measureToViewMap.registerView(view, clock);
5051
}
5152

53+
@Nullable
5254
ViewData getView(View.Name viewName) {
5355
return measureToViewMap.getView(viewName, clock, state.getInternal());
5456
}

impl_core/src/main/java/io/opencensus/implcore/stats/ViewManagerImpl.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import io.opencensus.stats.View;
2020
import io.opencensus.stats.ViewData;
2121
import io.opencensus.stats.ViewManager;
22+
import javax.annotation.Nullable;
2223

2324
/** Implementation of {@link ViewManager}. */
2425
public final class ViewManagerImpl extends ViewManager {
@@ -34,6 +35,7 @@ public void registerView(View view) {
3435
}
3536

3637
@Override
38+
@Nullable
3739
public ViewData getView(View.Name viewName) {
3840
return statsManager.getView(viewName);
3941
}

impl_core/src/main/java/io/opencensus/implcore/trace/export/SampledSpanStoreImpl.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import java.util.Map;
3434
import java.util.Set;
3535
import java.util.concurrent.TimeUnit;
36+
import javax.annotation.Nullable;
3637
import javax.annotation.concurrent.GuardedBy;
3738
import javax.annotation.concurrent.ThreadSafe;
3839

@@ -154,6 +155,7 @@ private PerSpanNameSamples() {
154155
}
155156
}
156157

158+
@Nullable
157159
private Bucket getLatencyBucket(long latencyNs) {
158160
for (int i = 0; i < NUM_LATENCY_BUCKETS; i++) {
159161
LatencyBucketBoundaries boundaries = LatencyBucketBoundaries.values()[i];

impl_core/src/test/java/io/opencensus/implcore/stats/StatsTestUtil.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
import java.util.Collections;
4141
import java.util.List;
4242
import java.util.Map;
43+
import javax.annotation.Nullable;
4344

4445
/** Stats test utilities. */
4546
final class StatsTestUtil {
@@ -170,6 +171,7 @@ private static void assertDistributionDataEquals(
170171
.isEqualTo(removeTrailingZeros(expected.getBucketCounts()));
171172
}
172173

174+
@Nullable
173175
private static List<Long> removeTrailingZeros(List<Long> longs) {
174176
if (longs == null) {
175177
return null;

0 commit comments

Comments
 (0)