Skip to content

Commit 8ae30c6

Browse files
Excavator: Upgrades Baseline to the latest version (#3093)
1 parent 7ffadd4 commit 8ae30c6

File tree

33 files changed

+166
-237
lines changed

33 files changed

+166
-237
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ buildscript {
1313
classpath 'com.palantir.javaformat:gradle-palantir-java-format:2.71.0'
1414
classpath 'org.revapi:gradle-revapi:1.8.0'
1515
classpath 'com.netflix.nebula:gradle-dependency-lock-plugin:7.0.1'
16-
classpath 'com.palantir.baseline:gradle-baseline-java:6.24.0'
16+
classpath 'com.palantir.baseline:gradle-baseline-java:6.44.0'
1717
classpath 'com.palantir.gradle.gitversion:gradle-git-version:4.0.0'
1818
classpath 'com.palantir.gradle.idea-configuration:gradle-idea-configuration:0.5.0'
1919
classpath 'com.palantir.metricschema:gradle-metric-schema:0.33.0'

client-config/src/main/java/com/palantir/conjure/java/client/config/ClientConfigurations.java

Lines changed: 13 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,8 @@
2525
import com.palantir.conjure.java.api.config.ssl.SslConfiguration;
2626
import com.palantir.conjure.java.config.ssl.SslSocketFactories;
2727
import com.palantir.conjure.java.config.ssl.TrustContext;
28-
import com.palantir.logsafe.SafeArg;
2928
import com.palantir.logsafe.UnsafeArg;
3029
import com.palantir.logsafe.exceptions.SafeIllegalArgumentException;
31-
import com.palantir.logsafe.exceptions.SafeIllegalStateException;
3230
import com.palantir.logsafe.logger.SafeLogger;
3331
import com.palantir.logsafe.logger.SafeLoggerFactory;
3432
import com.palantir.tritium.metrics.registry.SharedTaggedMetricRegistries;
@@ -164,25 +162,22 @@ private static ClientConfiguration of(
164162
}
165163

166164
public static ProxySelector createProxySelector(ProxyConfiguration proxyConfig) {
167-
switch (proxyConfig.type()) {
168-
case DIRECT:
169-
return fixedProxySelectorFor(Proxy.NO_PROXY);
170-
case FROM_ENVIRONMENT:
165+
return switch (proxyConfig.type()) {
166+
case DIRECT -> fixedProxySelectorFor(Proxy.NO_PROXY);
167+
case FROM_ENVIRONMENT -> {
171168
String defaultEnvProxy = System.getenv(ENV_HTTPS_PROXY);
172169
if (defaultEnvProxy == null) {
173170
log.info("Proxy environment variable not set, using no proxy");
174-
return fixedProxySelectorFor(Proxy.NO_PROXY);
171+
yield fixedProxySelectorFor(Proxy.NO_PROXY);
175172
}
176173
log.info("Using proxy from environment variable", UnsafeArg.of("proxy", defaultEnvProxy));
177174
InetSocketAddress address = createInetSocketAddress(defaultEnvProxy);
178-
return fixedProxySelectorFor(new Proxy(Proxy.Type.HTTP, address));
179-
case HTTP:
180-
return getHttpProxySelector(proxyConfig, false);
181-
case HTTPS:
182-
return getHttpProxySelector(proxyConfig, true);
183-
case MESH:
184-
return ProxySelector.getDefault(); // MESH proxy is not a Java proxy
185-
case SOCKS:
175+
yield fixedProxySelectorFor(new Proxy(Proxy.Type.HTTP, address));
176+
}
177+
case HTTP -> getHttpProxySelector(proxyConfig, false);
178+
case HTTPS -> getHttpProxySelector(proxyConfig, true);
179+
case MESH -> ProxySelector.getDefault(); // MESH proxy is not a Java proxy
180+
case SOCKS -> {
186181
HostAndPort socksHostAndPort = HostAndPort.fromString(proxyConfig
187182
.hostAndPort()
188183
.orElseThrow(() -> new SafeIllegalArgumentException(
@@ -191,15 +186,9 @@ public static ProxySelector createProxySelector(ProxyConfiguration proxyConfig)
191186
// Proxy address must not be resolved, otherwise DNS changes while the application
192187
// is running are ignored by the application.
193188
InetSocketAddress.createUnresolved(socksHostAndPort.getHost(), socksHostAndPort.getPort());
194-
return fixedProxySelectorFor(new Proxy(Proxy.Type.SOCKS, socksAddress));
195-
default:
196-
// fall through
197-
}
198-
199-
throw new SafeIllegalStateException(
200-
"Failed to create ProxySelector for proxy configuration",
201-
SafeArg.of("type", proxyConfig.type()),
202-
UnsafeArg.of("hostAndPort", proxyConfig.hostAndPort()));
189+
yield fixedProxySelectorFor(new Proxy(Proxy.Type.SOCKS, socksAddress));
190+
}
191+
};
203192
}
204193

205194
@VisibleForTesting

conjure-java-client-verifier/src/test/java/com/palantir/verification/Cases.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import com.palantir.conjure.verification.server.TestCases;
2727
import java.io.File;
2828
import java.io.IOException;
29+
import java.io.UncheckedIOException;
2930
import java.util.Set;
3031
import javax.annotation.Nullable;
3132

@@ -45,7 +46,7 @@ private static ClientTestCases deserializeTestCases(File file) {
4546
.readValue(file, TestCases.class)
4647
.getClient();
4748
} catch (IOException e) {
48-
throw new RuntimeException(
49+
throw new UncheckedIOException(
4950
String.format("Unable to read %s, you may need to run ./gradlew copyTestCases", file), e);
5051
}
5152
}
@@ -58,7 +59,7 @@ private static IgnoredClientTestCases deserializeIgnoredClientTestCases(File fil
5859
.readValue(file, IgnoredTestCases.class)
5960
.getClient();
6061
} catch (IOException e) {
61-
throw new RuntimeException(String.format("Unable to read %s", file), e);
62+
throw new UncheckedIOException(String.format("Unable to read %s", file), e);
6263
}
6364
}
6465

conjure-java-client-verifier/src/test/java/com/palantir/verification/VerificationServerRule.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import java.io.IOException;
3030
import java.io.InputStream;
3131
import java.io.InputStreamReader;
32+
import java.io.UncheckedIOException;
3233
import java.nio.charset.StandardCharsets;
3334
import java.nio.file.Paths;
3435
import java.util.concurrent.CountDownLatch;
@@ -94,7 +95,7 @@ private static void blockUntilServerStarted(InputStream inputStream) throws Inte
9495
System.out.println(line);
9596
}
9697
} catch (IOException e) {
97-
throw new RuntimeException(e);
98+
throw new UncheckedIOException(e);
9899
}
99100
});
100101
thread.setDaemon(true);

conjure-java-jackson-serialization/src/main/java/com/palantir/conjure/java/serialization/LenientLongModule.java

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -52,16 +52,12 @@ private LongAsStringDeserializer() {
5252

5353
@Override
5454
public Long deserialize(JsonParser jsonParser, DeserializationContext _ctxt) throws IOException {
55-
switch (jsonParser.currentToken()) {
56-
case VALUE_NUMBER_INT:
57-
return jsonParser.getLongValue();
58-
case VALUE_STRING:
59-
return parseLong(jsonParser);
60-
case VALUE_NULL:
61-
return null;
62-
default:
63-
throw new SafeIoException("Expected a long value");
64-
}
55+
return switch (jsonParser.currentToken()) {
56+
case VALUE_NUMBER_INT -> jsonParser.getLongValue();
57+
case VALUE_STRING -> parseLong(jsonParser);
58+
case VALUE_NULL -> null;
59+
default -> throw new SafeIoException("Expected a long value");
60+
};
6561
}
6662

6763
@Override

conjure-java-jaxrs-client/src/main/java/com/palantir/conjure/java/client/jaxrs/DialogueFeignClient.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
import com.palantir.logsafe.SafeArg;
4343
import com.palantir.logsafe.UnsafeArg;
4444
import com.palantir.logsafe.exceptions.SafeIllegalStateException;
45-
import com.palantir.logsafe.exceptions.SafeRuntimeException;
45+
import com.palantir.logsafe.exceptions.SafeUncheckedIoException;
4646
import feign.Request;
4747
import java.io.ByteArrayInputStream;
4848
import java.io.IOException;
@@ -113,8 +113,8 @@ public feign.Response execute(Request request, Request.Options _options) throws
113113
} catch (UncheckedExecutionException e) {
114114
// Rethrow IOException to match standard feign behavior
115115
Throwable cause = e.getCause();
116-
if (cause instanceof IOException) {
117-
throw (IOException) cause;
116+
if (cause instanceof IOException iOException) {
117+
throw iOException;
118118
}
119119
throw e;
120120
}
@@ -146,7 +146,7 @@ private static String urlDecode(String input) {
146146
try {
147147
return URLDecoder.decode(input, "UTF-8");
148148
} catch (UnsupportedEncodingException e) {
149-
throw new SafeRuntimeException("Failed to decode path segment", e, UnsafeArg.of("encoded", input));
149+
throw new SafeUncheckedIoException("Failed to decode path segment", e, UnsafeArg.of("encoded", input));
150150
}
151151
}
152152

@@ -290,7 +290,7 @@ public InputStream body() {
290290
try {
291291
return body.asInputStream();
292292
} catch (IOException e) {
293-
throw new SafeRuntimeException("Failed to access the delegate response body", e);
293+
throw new SafeUncheckedIoException("Failed to access the delegate response body", e);
294294
}
295295
}
296296
return new ByteArrayInputStream(new byte[0]);

conjure-java-jaxrs-client/src/main/java/com/palantir/conjure/java/client/jaxrs/feignimpl/CborDelegateEncoder.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import feign.RequestTemplate;
2525
import feign.codec.EncodeException;
2626
import feign.codec.Encoder;
27+
import java.io.UncheckedIOException;
2728
import java.lang.reflect.Type;
2829
import java.nio.charset.StandardCharsets;
2930
import java.util.Collection;
@@ -66,7 +67,7 @@ public void encode(Object object, Type bodyType, RequestTemplate template) throw
6667
JavaType javaType = cborMapper.getTypeFactory().constructType(bodyType);
6768
template.body(cborMapper.writerFor(javaType).writeValueAsBytes(object), StandardCharsets.UTF_8);
6869
} catch (JsonProcessingException e) {
69-
throw new RuntimeException(e);
70+
throw new UncheckedIOException(e);
7071
}
7172
}
7273
}

conjure-java-jaxrs-client/src/main/java/com/palantir/conjure/java/client/jaxrs/feignimpl/InputStreamDelegateEncoder.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import feign.codec.Encoder;
2727
import java.io.IOException;
2828
import java.io.InputStream;
29+
import java.io.UncheckedIOException;
2930
import java.lang.reflect.Type;
3031
import java.nio.charset.StandardCharsets;
3132

@@ -56,7 +57,7 @@ public void encode(Object object, Type bodyType, RequestTemplate template) throw
5657
dangerousBufferingMeter.mark(Math.max(1, bytes.length));
5758
template.body(bytes, StandardCharsets.UTF_8);
5859
} catch (IOException e) {
59-
throw new RuntimeException(e);
60+
throw new UncheckedIOException(e);
6061
}
6162
} else {
6263
delegate.encode(object, bodyType, template);

conjure-java-jaxrs-client/src/test/java/com/palantir/conjure/java/client/jaxrs/feignimpl/GuavaTestServer.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import java.io.ByteArrayInputStream;
3333
import java.io.IOException;
3434
import java.io.InputStream;
35+
import java.io.UncheckedIOException;
3536
import java.nio.charset.StandardCharsets;
3637
import javax.annotation.Nullable;
3738
import org.assertj.core.util.Strings;
@@ -131,7 +132,7 @@ public String readInputStream(InputStream data) {
131132
try {
132133
return new String(data.readAllBytes(), StandardCharsets.UTF_8);
133134
} catch (IOException e) {
134-
throw new RuntimeException(e);
135+
throw new UncheckedIOException(e);
135136
}
136137
}
137138

conjure-java-jaxrs-client/src/test/java/com/palantir/conjure/java/client/jaxrs/feignimpl/Java8TestServer.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import java.io.ByteArrayInputStream;
3434
import java.io.IOException;
3535
import java.io.InputStream;
36+
import java.io.UncheckedIOException;
3637
import java.nio.charset.StandardCharsets;
3738
import java.util.List;
3839
import java.util.Map;
@@ -128,7 +129,7 @@ public String readInputStream(InputStream data) {
128129
try {
129130
return new String(data.readAllBytes(), StandardCharsets.UTF_8);
130131
} catch (IOException e) {
131-
throw new RuntimeException(e);
132+
throw new UncheckedIOException(e);
132133
}
133134
}
134135

0 commit comments

Comments
 (0)