Skip to content
This repository was archived by the owner on Dec 23, 2023. It is now read-only.

Commit ef6e03a

Browse files
authored
Clean up a few nullable annotations. (#1824)
1 parent cb7f064 commit ef6e03a

2 files changed

Lines changed: 13 additions & 31 deletions

File tree

api/src/main/java/io/opencensus/metrics/data/Exemplar.java

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
package io.opencensus.metrics.data;
1818

19+
import static io.opencensus.internal.Utils.checkNotNull;
20+
1921
import com.google.auto.value.AutoValue;
2022
import io.opencensus.common.Timestamp;
2123
import java.util.Collections;
@@ -24,10 +26,6 @@
2426
import java.util.Map.Entry;
2527
import javax.annotation.concurrent.Immutable;
2628

27-
/*>>>
28-
import org.checkerframework.checker.nullness.qual.NonNull;
29-
*/
30-
3129
/**
3230
* An example point that may be used to annotate aggregated distribution values, associated with a
3331
* histogram bucket.
@@ -84,13 +82,4 @@ public static Exemplar create(
8482
}
8583
return new AutoValue_Exemplar(value, timestamp, attachmentsCopy);
8684
}
87-
88-
// TODO(songy23): shade the internal Utils jar and remove this duplicated method.
89-
private static <T /*>>> extends @NonNull Object*/> T checkNotNull(
90-
T arg, @javax.annotation.Nullable Object errorMessage) {
91-
if (arg == null) {
92-
throw new NullPointerException(String.valueOf(errorMessage));
93-
}
94-
return arg;
95-
}
9685
}

api/src/main/java/io/opencensus/resource/Resource.java

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,9 @@
2727
import java.util.List;
2828
import java.util.Map;
2929
import java.util.Map.Entry;
30+
import javax.annotation.Nullable;
3031
import javax.annotation.concurrent.Immutable;
3132

32-
/*>>>
33-
import org.checkerframework.checker.nullness.qual.Nullable;
34-
*/
35-
3633
/**
3734
* {@link Resource} represents a resource, which capture identifying information about the entities
3835
* for which signals (stats or traces) are reported. It further provides a framework for detection
@@ -57,7 +54,7 @@ public abstract class Resource {
5754
private static final String ERROR_MESSAGE_INVALID_VALUE =
5855
" should be a ASCII string with a length not exceed " + MAX_LENGTH + " characters.";
5956

60-
@javax.annotation.Nullable
57+
@Nullable
6158
private static final String ENV_TYPE = parseResourceType(System.getenv(OC_RESOURCE_TYPE_ENV));
6259

6360
private static final Map<String, String> ENV_LABEL_MAP =
@@ -71,7 +68,7 @@ public abstract class Resource {
7168
* @return the type identifier for the resource.
7269
* @since 0.18
7370
*/
74-
@javax.annotation.Nullable
71+
@Nullable
7572
public abstract String getType();
7673

7774
/**
@@ -104,8 +101,7 @@ public static Resource createFromEnvironmentVariables() {
104101
* ASCII string or exceed {@link #MAX_LENGTH} characters.
105102
* @since 0.18
106103
*/
107-
public static Resource create(
108-
@javax.annotation.Nullable String type, Map<String, String> labels) {
104+
public static Resource create(@Nullable String type, Map<String, String> labels) {
109105
return createInternal(
110106
type,
111107
Collections.unmodifiableMap(
@@ -120,7 +116,7 @@ public static Resource create(
120116
* @return a {@code Resource}.
121117
* @since 0.18
122118
*/
123-
@javax.annotation.Nullable
119+
@Nullable
124120
public static Resource mergeResources(List<Resource> resources) {
125121
Resource currentResource = null;
126122
for (Resource resource : resources) {
@@ -129,8 +125,7 @@ public static Resource mergeResources(List<Resource> resources) {
129125
return currentResource;
130126
}
131127

132-
private static Resource createInternal(
133-
@javax.annotation.Nullable String type, Map<String, String> labels) {
128+
private static Resource createInternal(@Nullable String type, Map<String, String> labels) {
134129
return new AutoValue_Resource(type, labels);
135130
}
136131

@@ -140,8 +135,8 @@ private static Resource createInternal(
140135
* <p>OC_RESOURCE_TYPE: A string that describes the type of the resource prefixed by a domain
141136
* namespace, e.g. “kubernetes.io/container”.
142137
*/
143-
@javax.annotation.Nullable
144-
static String parseResourceType(@javax.annotation.Nullable String rawEnvType) {
138+
@Nullable
139+
static String parseResourceType(@Nullable String rawEnvType) {
145140
if (rawEnvType != null && !rawEnvType.isEmpty()) {
146141
Utils.checkArgument(isValidAndNotEmpty(rawEnvType), "Type" + ERROR_MESSAGE_INVALID_CHARS);
147142
return rawEnvType.trim();
@@ -157,7 +152,7 @@ static String parseResourceType(@javax.annotation.Nullable String rawEnvType) {
157152
* quoted or unquoted in general. If a value contains whitespaces, =, or " characters, it must
158153
* always be quoted.
159154
*/
160-
static Map<String, String> parseResourceLabels(@javax.annotation.Nullable String rawEnvLabels) {
155+
static Map<String, String> parseResourceLabels(@Nullable String rawEnvLabels) {
161156
if (rawEnvLabels == null) {
162157
return Collections.<String, String>emptyMap();
163158
} else {
@@ -182,10 +177,8 @@ static Map<String, String> parseResourceLabels(@javax.annotation.Nullable String
182177
* Returns a new, merged {@link Resource} by merging two resources. In case of a collision, first
183178
* resource takes precedence.
184179
*/
185-
@javax.annotation.Nullable
186-
private static Resource merge(
187-
@javax.annotation.Nullable Resource resource,
188-
@javax.annotation.Nullable Resource otherResource) {
180+
@Nullable
181+
private static Resource merge(@Nullable Resource resource, @Nullable Resource otherResource) {
189182
if (otherResource == null) {
190183
return resource;
191184
}

0 commit comments

Comments
 (0)