Remove jsr305; switch GuardedBy to com.google.errorprone (#1611)

- Remove single usage of @immutable without replacement
- Remove HttpClient's usages of @threadsafe without replacement
- Replace javax.annotation.concurrent.GuardedBy
  with com.google.errorprone.annotations.concurrent.GuardedBy

Also:
- Remove redundant final modifiers from members of a final class

---------

Co-authored-by: odenix <self@odenix.org>
This commit is contained in:
Daniel Chao
2026-05-22 14:15:18 -07:00
committed by GitHub
parent a800072441
commit 95bcd6a463
16 changed files with 17 additions and 29 deletions
+1 -1
View File
@@ -43,7 +43,7 @@ dependencies {
annotationProcessor(libs.truffleDslProcessor)
annotationProcessor(generatorSourceSet.get().runtimeClasspath)
compileOnly(libs.jsr305)
compileOnly(libs.errorProneAnnotations)
// pkl-core implements pkl-executor's ExecutorSpi, but the SPI doesn't ship with pkl-core
compileOnly(projects.pklExecutor)
@@ -15,6 +15,7 @@
*/
package org.pkl.core.externalreader;
import com.google.errorprone.annotations.concurrent.GuardedBy;
import java.io.IOException;
import java.lang.ProcessBuilder.Redirect;
import java.time.Duration;
@@ -26,7 +27,6 @@ import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import javax.annotation.concurrent.GuardedBy;
import org.jspecify.annotations.Nullable;
import org.pkl.core.evaluatorSettings.PklEvaluatorSettings.ExternalReader;
import org.pkl.core.externalreader.ExternalReaderMessages.*;
@@ -1,5 +1,5 @@
/*
* Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved.
* Copyright © 2024-2026 Apple Inc. and the Pkl project authors. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -18,10 +18,8 @@ package org.pkl.core.http;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.net.http.HttpResponse.BodyHandler;
import javax.annotation.concurrent.ThreadSafe;
/** An {@code HttpClient} implementation that throws {@code AssertionError} on every send. */
@ThreadSafe
final class DummyHttpClient implements HttpClient {
@Override
public <T> HttpResponse<T> send(HttpRequest request, BodyHandler<T> responseBodyHandler) {
@@ -1,5 +1,5 @@
/*
* Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved.
* Copyright © 2024-2026 Apple Inc. and the Pkl project authors. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -41,7 +41,6 @@ import java.time.Duration;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import javax.annotation.concurrent.ThreadSafe;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLException;
import javax.net.ssl.SSLHandshakeException;
@@ -50,7 +49,6 @@ import org.pkl.core.util.ErrorMessages;
import org.pkl.core.util.Exceptions;
/** An {@code HttpClient} implementation backed by {@link java.net.http.HttpClient}. */
@ThreadSafe
final class JdkHttpClient implements HttpClient {
// non-private for testing
final java.net.http.HttpClient underlying;
@@ -15,21 +15,19 @@
*/
package org.pkl.core.http;
import com.google.errorprone.annotations.concurrent.GuardedBy;
import java.io.IOException;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.net.http.HttpResponse.BodyHandler;
import java.util.Optional;
import java.util.function.Supplier;
import javax.annotation.concurrent.GuardedBy;
import javax.annotation.concurrent.ThreadSafe;
import org.jspecify.annotations.Nullable;
/**
* An {@code HttpClient} decorator that defers creating the underlying HTTP client until the first
* send.
*/
@ThreadSafe
final class LazyHttpClient implements HttpClient {
private final Supplier<HttpClient> supplier;
private final Object lock = new Object();
@@ -30,7 +30,6 @@ import java.util.Map.Entry;
import java.util.Objects;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.regex.Pattern;
import javax.annotation.concurrent.ThreadSafe;
import org.jspecify.annotations.Nullable;
import org.pkl.core.PklBugException;
import org.pkl.core.util.HttpUtils;
@@ -50,7 +49,6 @@ import org.pkl.core.util.Pair;
* <p>Both {@code User-Agent} header and default request timeout are configurable through {@link
* HttpClient.Builder}.
*/
@ThreadSafe
final class RequestRewritingClient implements HttpClient {
// non-private for testing
final String userAgent;
@@ -15,6 +15,7 @@
*/
package org.pkl.core.module;
import com.google.errorprone.annotations.concurrent.GuardedBy;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
@@ -26,7 +27,6 @@ import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.ServiceLoader;
import javax.annotation.concurrent.GuardedBy;
import org.jspecify.annotations.Nullable;
import org.pkl.core.Closeables;
import org.pkl.core.externalreader.ExternalModuleResolver;
@@ -15,6 +15,7 @@
*/
package org.pkl.core.module;
import com.google.errorprone.annotations.concurrent.GuardedBy;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.UncheckedIOException;
@@ -27,7 +28,6 @@ import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.annotation.concurrent.GuardedBy;
import org.jspecify.annotations.Nullable;
import org.pkl.core.module.PathElement.TreePathElement;
import org.pkl.core.runtime.FileSystemManager;
@@ -15,12 +15,12 @@
*/
package org.pkl.core.module;
import com.google.errorprone.annotations.concurrent.GuardedBy;
import java.io.IOException;
import java.net.URI;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import javax.annotation.concurrent.GuardedBy;
import org.graalvm.collections.EconomicMap;
import org.jspecify.annotations.Nullable;
import org.pkl.core.PklBugException;
@@ -15,6 +15,7 @@
*/
package org.pkl.core.packages;
import com.google.errorprone.annotations.concurrent.GuardedBy;
import java.io.ByteArrayInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
@@ -42,7 +43,6 @@ import java.util.concurrent.atomic.AtomicBoolean;
import java.util.stream.Collectors;
import java.util.stream.StreamSupport;
import java.util.zip.ZipInputStream;
import javax.annotation.concurrent.GuardedBy;
import org.graalvm.collections.EconomicMap;
import org.jspecify.annotations.Nullable;
import org.pkl.core.SecurityManager;
@@ -15,6 +15,7 @@
*/
package org.pkl.core.runtime;
import com.google.errorprone.annotations.concurrent.GuardedBy;
import com.oracle.truffle.api.CompilerDirectives.CompilationFinal;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import com.oracle.truffle.api.dsl.Idempotent;
@@ -22,7 +23,6 @@ import com.oracle.truffle.api.frame.FrameDescriptor;
import com.oracle.truffle.api.source.SourceSection;
import java.util.*;
import java.util.function.*;
import javax.annotation.concurrent.GuardedBy;
import org.graalvm.collections.*;
import org.jspecify.annotations.Nullable;
import org.pkl.core.Member.SourceLocation;
@@ -15,11 +15,11 @@
*/
package org.pkl.core.runtime;
import com.google.errorprone.annotations.concurrent.GuardedBy;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import com.oracle.truffle.api.frame.MaterializedFrame;
import java.util.HashSet;
import java.util.Map;
import javax.annotation.concurrent.GuardedBy;
import org.graalvm.collections.UnmodifiableEconomicMap;
import org.pkl.core.ast.member.ListingOrMappingTypeCastNode;
import org.pkl.core.ast.member.ObjectMember;
@@ -15,6 +15,7 @@
*/
package org.pkl.core.runtime;
import com.google.errorprone.annotations.concurrent.GuardedBy;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import com.oracle.truffle.api.frame.Frame;
import com.oracle.truffle.api.frame.MaterializedFrame;
@@ -22,7 +23,6 @@ import com.oracle.truffle.api.source.SourceSection;
import java.net.URI;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.concurrent.GuardedBy;
import org.jspecify.annotations.Nullable;
import org.pkl.core.Member.SourceLocation;
import org.pkl.core.PClassInfo;
@@ -1,5 +1,5 @@
/*
* Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved.
* Copyright © 2024-2026 Apple Inc. and the Pkl project authors. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,7 +16,6 @@
package org.pkl.core.util;
import java.util.Arrays;
import javax.annotation.concurrent.Immutable;
/**
* The JaroWinkler distance metric is designed and best suited for short strings such as person
@@ -28,7 +27,6 @@ import javax.annotation.concurrent.Immutable;
*
* @author Thibault Debatty
*/
@Immutable
public final class StringSimilarity {
private static final double DEFAULT_THRESHOLD = 0.7;
private static final int THREE = 3;
@@ -54,7 +52,7 @@ public final class StringSimilarity {
*
* @return the current value of the threshold
*/
public final double getThreshold() {
public double getThreshold() {
return threshold;
}
@@ -65,7 +63,7 @@ public final class StringSimilarity {
* @param s2 The second string to compare.
* @return The Jaro-Winkler similarity in the range [0, 1]
*/
public final double similarity(final String s1, final String s2) {
public double similarity(final String s1, final String s2) {
if (s1.equals(s2)) {
return 1;
}
@@ -90,7 +88,7 @@ public final class StringSimilarity {
* @param s2 The second string to compare.
* @return 1 - similarity.
*/
public final double distance(final String s1, final String s2) {
public double distance(final String s1, final String s2) {
return 1.0 - similarity(s1, s2);
}