Skip to content

fix: Apply fixes from Google error-prone #1010

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

Merged
merged 2 commits into from
Aug 18, 2022
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
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,20 +51,20 @@ If you are using Maven without BOM, add this to your dependencies:
If you are using Gradle 5.x or later, add this to your dependencies:

```Groovy
implementation platform('com.google.cloud:libraries-bom:26.0.0')
implementation platform('com.google.cloud:libraries-bom:26.1.0')

implementation 'com.google.cloud:google-cloud-logging'
```
If you are using Gradle without BOM, add this to your dependencies:

```Groovy
implementation 'com.google.cloud:google-cloud-logging:3.10.0'
implementation 'com.google.cloud:google-cloud-logging:3.10.2'
```

If you are using SBT, add this to your dependencies:

```Scala
libraryDependencies += "com.google.cloud" % "google-cloud-logging" % "3.10.0"
libraryDependencies += "com.google.cloud" % "google-cloud-logging" % "3.10.2"
```

## Authentication
Expand Down
10 changes: 10 additions & 0 deletions google-cloud-logging/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,16 @@
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-core</artifactId>
</dependency>
<dependency>
<groupId>org.jspecify</groupId>
<artifactId>jspecify</artifactId>
<version>0.2.0</version>
</dependency>
<dependency>
<groupId>com.google.errorprone</groupId>
<artifactId>error_prone_annotations</artifactId>
<version>2.14.0</version>
</dependency>

<!-- Test dependencies -->
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import com.google.cloud.logging.HttpRequest.RequestMethod;
import com.google.common.base.MoreObjects;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import java.util.Objects;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
Expand Down Expand Up @@ -48,17 +49,20 @@ public static final class Builder {
}

/** Sets the HTTP request. */
@CanIgnoreReturnValue
public Builder setRequest(HttpRequest request) {
this.requestBuilder = request != null ? request.toBuilder() : HttpRequest.newBuilder();
return this;
}

@CanIgnoreReturnValue
public Builder setRequestUrl(String url) {
this.requestBuilder.setRequestUrl(url);
return this;
}

/** Sets the HTTP request method. */
@CanIgnoreReturnValue
public Builder setRequestMethod(RequestMethod method) {
this.requestBuilder.setRequestMethod(method);
return this;
Expand All @@ -70,6 +74,7 @@ public Builder setRequestMethod(RequestMethod method) {
* @see <a href= "http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html">HTTP/1.1 Header Field
* Definitions</a>
*/
@CanIgnoreReturnValue
public Builder setReferer(String referer) {
this.requestBuilder.setReferer(referer);
return this;
Expand All @@ -79,6 +84,7 @@ public Builder setReferer(String referer) {
* Sets the IP address (IPv4 or IPv6) of the client that issued the HTTP request. Examples:
* {@code 192.168.1.1}, {@code FE80::0202:B3FF:FE1E:8329}.
*/
@CanIgnoreReturnValue
public Builder setRemoteIp(String remoteIp) {
this.requestBuilder.setRemoteIp(remoteIp);
return this;
Expand All @@ -88,18 +94,21 @@ public Builder setRemoteIp(String remoteIp) {
* Sets the IP address (IPv4 or IPv6) of the origin server that the request was sent to.
* Examples: {@code 192.168.1.1}, {@code FE80::0202:B3FF:FE1E:8329}.
*/
@CanIgnoreReturnValue
public Builder setServerIp(String serverIp) {
this.requestBuilder.setServerIp(serverIp);
return this;
}

/** Sets the string as a trace id value. */
@CanIgnoreReturnValue
public Builder setTraceId(String traceId) {
this.traceId = traceId;
return this;
}

/** Sets the string as a span id value. */
@CanIgnoreReturnValue
public Builder setSpanId(String spanId) {
this.spanId = spanId;
return this;
Expand All @@ -113,6 +122,7 @@ public Builder setSpanId(String spanId) {
* @see <a href="https://cloud.google.com/trace/docs/setup#force-trace">Cloud Trace header
* format.</a>
*/
@CanIgnoreReturnValue
public Builder loadCloudTraceContext(String cloudTrace) {
if (cloudTrace != null) {
cloudTrace = cloudTrace.split(";")[0];
Expand Down Expand Up @@ -146,6 +156,7 @@ public Builder loadCloudTraceContext(String cloudTrace) {
* @throws IllegalArgumentException if passed argument does not follow the @W3C trace format or
* the format version is not supported.
*/
@CanIgnoreReturnValue
public Builder loadW3CTraceParentContext(String traceParent) throws IllegalArgumentException {
if (traceParent != null) {
Matcher validator = W3C_TRACE_CONTEXT_FORMAT.matcher(traceParent.toLowerCase());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@

import com.google.common.base.Function;
import com.google.common.base.MoreObjects;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import com.google.logging.v2.LogExclusion;
import com.google.protobuf.Timestamp;
import java.util.Objects;
import org.jspecify.nullness.Nullable;

/**
* Specifies a set of log entries that are not to be stored in Logging. If your GCP resource
Expand All @@ -35,15 +37,15 @@ public class Exclusion {
static final Function<LogExclusion, Exclusion> FROM_PROTOBUF_FUNCTION =
new Function<LogExclusion, Exclusion>() {
@Override
public Exclusion apply(LogExclusion exclusionPb) {
public @Nullable Exclusion apply(LogExclusion exclusionPb) {
return exclusionPb != null ? Exclusion.fromProtobuf(exclusionPb) : null;
}
};

static final Function<Exclusion, LogExclusion> TO_PROTOBUF_FUNCTION =
new Function<Exclusion, LogExclusion>() {
@Override
public LogExclusion apply(Exclusion exclusion) {
public @Nullable LogExclusion apply(Exclusion exclusion) {
return exclusion != null ? exclusion.toProtobuf() : null;
}
};
Expand Down Expand Up @@ -84,12 +86,14 @@ private Builder(Exclusion exclusion) {
* limited to 100 characters and can include only letters, digits, underscores, hyphens, and
* periods. First character has to be alphanumeric.
*/
@CanIgnoreReturnValue
public Builder setName(String name) {
this.name = checkNotNull(name);
return this;
}

/** [Optional] A description of this exclusion. */
@CanIgnoreReturnValue
public Builder setDescription(String description) {
this.description = description;
return this;
Expand All @@ -99,6 +103,7 @@ public Builder setDescription(String description) {
* [Required] An advanced logs filter that matches the log entries to be excluded. By using the
* sample function, you can exclude less than 100% of the matching log entries.
*/
@CanIgnoreReturnValue
public Builder setFilter(String filter) {
this.filter = checkNotNull(filter);
return this;
Expand All @@ -108,18 +113,21 @@ public Builder setFilter(String filter) {
* [Optional] If set to True, then this exclusion is disabled and it does not exclude any log
* entries.
*/
@CanIgnoreReturnValue
public Builder setDisabled(boolean disabled) {
this.disabled = disabled;
return this;
}

/** [Output only] The creation timestamp of the exclusion. */
@CanIgnoreReturnValue
public Builder setCreateTime(Timestamp createTime) {
this.createTime = createTime;
return this;
}

/** [Output only] The last update timestamp of the exclusion. */
@CanIgnoreReturnValue
public Builder setUpdateTime(Timestamp updateTime) {
this.updateTime = updateTime;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import com.google.cloud.StringEnumValue;
import com.google.common.base.MoreObjects;
import com.google.common.base.Strings;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import java.io.Serializable;
import java.util.Objects;
import org.threeten.bp.Duration;
Expand Down Expand Up @@ -134,6 +135,7 @@ public static final class Builder {
}

/** Sets the HTTP request method. */
@CanIgnoreReturnValue
public Builder setRequestMethod(RequestMethod requestMethod) {
this.requestMethod = requestMethod;
return this;
Expand All @@ -144,6 +146,7 @@ public Builder setRequestMethod(RequestMethod requestMethod) {
* host name, the path and the query portion of the URL that was requested. Example: {@code
* http://example.com/some/info?color=red}.
*/
@CanIgnoreReturnValue
public Builder setRequestUrl(String requestUrl) {
this.requestUrl = requestUrl;
return this;
Expand All @@ -153,12 +156,14 @@ public Builder setRequestUrl(String requestUrl) {
* Sets the size of the HTTP request message in bytes, including the request headers and the
* request body.
*/
@CanIgnoreReturnValue
public Builder setRequestSize(long requestSize) {
this.requestSize = requestSize;
return this;
}

/** Sets the response code indicating the status of response. */
@CanIgnoreReturnValue
public Builder setStatus(int status) {
this.status = status;
return this;
Expand All @@ -168,6 +173,7 @@ public Builder setStatus(int status) {
* Sets the size of the HTTP response message sent back to the client, in bytes, including the
* response headers and the response body.
*/
@CanIgnoreReturnValue
public Builder setResponseSize(long responseSize) {
this.responseSize = responseSize;
return this;
Expand All @@ -177,6 +183,7 @@ public Builder setResponseSize(long responseSize) {
* Sets the user agent sent by the client. Example: {@code Mozilla/4.0 (compatible; MSIE 6.0;
* Windows 98; Q312461; .NET CLR 1.0.3705)}.
*/
@CanIgnoreReturnValue
public Builder setUserAgent(String userAgent) {
this.userAgent = userAgent;
return this;
Expand All @@ -186,6 +193,7 @@ public Builder setUserAgent(String userAgent) {
* Sets the IP address (IPv4 or IPv6) of the client that issued the HTTP request. Examples:
* {@code 192.168.1.1}, {@code FE80::0202:B3FF:FE1E:8329}.
*/
@CanIgnoreReturnValue
public Builder setRemoteIp(String remoteIp) {
this.remoteIp = remoteIp;
return this;
Expand All @@ -195,6 +203,7 @@ public Builder setRemoteIp(String remoteIp) {
* Sets the IP address (IPv4 or IPv6) of the origin server that the request was sent to.
* Examples: {@code 192.168.1.1}, {@code FE80::0202:B3FF:FE1E:8329}.
*/
@CanIgnoreReturnValue
public Builder setServerIp(String serverIp) {
this.serverIp = serverIp;
return this;
Expand All @@ -206,12 +215,14 @@ public Builder setServerIp(String serverIp) {
* @see <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html">HTTP/1.1 Header Field
* Definitions</a>
*/
@CanIgnoreReturnValue
public Builder setReferer(String referer) {
this.referer = referer;
return this;
}

/** Sets whether or not a cache lookup was attempted. If not set, {@code false} is used. */
@CanIgnoreReturnValue
public Builder setCacheLookup(boolean cacheLookup) {
this.cacheLookup = cacheLookup;
return this;
Expand All @@ -221,6 +232,7 @@ public Builder setCacheLookup(boolean cacheLookup) {
* Sets whether or not an entity was served from cache (with or without validation). If not set,
* {@code false} is used.
*/
@CanIgnoreReturnValue
public Builder setCacheHit(boolean cacheHit) {
this.cacheHit = cacheHit;
return this;
Expand All @@ -231,6 +243,7 @@ public Builder setCacheHit(boolean cacheHit) {
* from cache. This field is only meaningful if {@link #setCacheHit(boolean)} is set to {@code
* true}. If not set, {@code false} is used.
*/
@CanIgnoreReturnValue
public Builder setCacheValidatedWithOriginServer(boolean cacheValidatedWithOriginServer) {
this.cacheValidatedWithOriginServer = cacheValidatedWithOriginServer;
return this;
Expand All @@ -240,6 +253,7 @@ public Builder setCacheValidatedWithOriginServer(boolean cacheValidatedWithOrigi
* Sets the number of HTTP response bytes inserted into cache. Set only when a cache fill was
* attempted.
*/
@CanIgnoreReturnValue
public Builder setCacheFillBytes(long cacheFillBytes) {
this.cacheFillBytes = cacheFillBytes;
return this;
Expand All @@ -249,6 +263,7 @@ public Builder setCacheFillBytes(long cacheFillBytes) {
* Sets the latency on the server, from the time the request was received until the response was
* sent.
*/
@CanIgnoreReturnValue
public Builder setLatency(Duration latency) {
this.latency = latency;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.jspecify.nullness.Nullable;

public class Instrumentation {
public static final String DIAGNOSTIC_INFO_KEY = "logging.googleapis.com/diagnostic";
Expand Down Expand Up @@ -96,7 +97,7 @@ public static Tuple<Boolean, Iterable<LogEntry>> populateInstrumentationInfo(
* @return The new array of oprions containing WriteOption.OptionType.PARTIAL_SUCCESS flag set to
* true
*/
public static WriteOption[] addPartialSuccessOption(WriteOption[] options) {
public static WriteOption @Nullable [] addPartialSuccessOption(WriteOption[] options) {
if (options == null) return options;
List<WriteOption> writeOptions = new ArrayList<WriteOption>();
writeOptions.addAll(Arrays.asList(options));
Expand Down Expand Up @@ -151,7 +152,7 @@ private static ListValue generateLibrariesList(
if (Strings.isNullOrEmpty(libraryName) || !libraryName.startsWith(JAVA_LIBRARY_NAME_PREFIX))
libraryName = JAVA_LIBRARY_NAME_PREFIX;
if (Strings.isNullOrEmpty(libraryVersion)) {
libraryVersion = getLibraryVersion(Instrumentation.class.getClass());
libraryVersion = getLibraryVersion(Instrumentation.class);
}
Struct libraryInfo = createInfoStruct(libraryName, libraryVersion);
ListValue.Builder libraryList = ListValue.newBuilder();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import com.google.logging.v2.LogName;
import java.util.Map;
import org.jspecify.nullness.Nullable;

/**
* Class for specifying resource name of the log to which this log entry belongs (see 'logName'
Expand Down Expand Up @@ -87,7 +88,7 @@ public static LogDestinationName billingAccount(String id) {
}

/** Creates a {@code LogEntry} object for given log ID. */
public LogName toLogName(String logId) {
public @Nullable LogName toLogName(String logId) {
if (logId == null) {
return null;
}
Expand Down Expand Up @@ -120,7 +121,7 @@ public DestinationType getDestinationType() {
}

/** Creates a {@code LogDestinationName} object from given {@code LogName}. */
public static LogDestinationName fromLogName(LogName logName) {
public static @Nullable LogDestinationName fromLogName(LogName logName) {
if (logName == null) {
return null;
}
Expand Down
Loading