Skip to content

Commit

Permalink
Excavator: Format Java files
Browse files Browse the repository at this point in the history
  • Loading branch information
svc-excavator-bot committed Sep 9, 2019
1 parent ccc8a48 commit 1c4ca7d
Show file tree
Hide file tree
Showing 34 changed files with 295 additions and 177 deletions.
1 change: 1 addition & 0 deletions .baseline/copyright/999_palantir.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(c) Copyright ${today.year} Palantir Technologies Inc. All rights reserved.
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,16 @@ final class KeyStores {
* (everything that occurs between the header and footer).
*/
private static final Pattern KEY_PATTERN = Pattern.compile(
"-----BEGIN RSA PRIVATE KEY-----\n?(.+?)\n?-----END RSA PRIVATE KEY-----", Pattern.DOTALL);
"-----BEGIN RSA PRIVATE KEY-----\n?(.+?)\n?-----END RSA PRIVATE KEY-----",
Pattern.DOTALL);

/**
* Pattern that matches a single certificate in a PEM file. Has a capture group that captures the content of the
* certificate (everything that occurs between the header and footer).
*/
private static final Pattern CERT_PATTERN = Pattern.compile(
"-----BEGIN CERTIFICATE-----\n?(.+?)\n?-----END CERTIFICATE-----", Pattern.DOTALL);
"-----BEGIN CERTIFICATE-----\n?(.+?)\n?-----END CERTIFICATE-----",
Pattern.DOTALL);

private static final FileFilter VISIBLE_FILE_FILTER = new FileFilter() {
@Override
Expand All @@ -68,8 +70,7 @@ public boolean accept(File pathname) {
}
};

private KeyStores() {
}
private KeyStores() {}

/**
* Returns a {@link KeyStore} created by loading the certificate or certificates specified by the provided path.
Expand All @@ -91,10 +92,12 @@ static KeyStore createTrustStoreFromCertificates(Path path) {
keyStore.setCertificateEntry(currFile.getName(), readX509Certificate(in));
} catch (IOException e) {
throw new RuntimeException(String.format(
"IOException encountered when opening '%s'", currFile.toPath()), e);
"IOException encountered when opening '%s'",
currFile.toPath()), e);
} catch (CertificateException | KeyStoreException e) {
throw new RuntimeException(String.format(
"Could not read file at \"%s\" as an X.509 certificate", currFile.toPath()), e);
"Could not read file at \"%s\" as an X.509 certificate",
currFile.toPath()), e);
}
}

Expand All @@ -112,14 +115,16 @@ static KeyStore createTrustStoreFromCertificates(Map<String, PemX509Certificate>
keyStore = createKeyStore();

for (Map.Entry<String, PemX509Certificate> entry : certificatesByAlias.entrySet()) {
try (InputStream certIn = new ByteArrayInputStream(
entry.getValue().pemCertificate().getBytes(StandardCharsets.UTF_8))) {
try (
InputStream certIn = new ByteArrayInputStream(
entry.getValue().pemCertificate().getBytes(StandardCharsets.UTF_8))) {
keyStore.setCertificateEntry(entry.getKey(), readX509Certificate(certIn));
} catch (IOException e) {
throw Throwables.propagate(e);
} catch (KeyStoreException | CertificateException e) {
throw new RuntimeException(String.format(
"Could not read certificate alias \"%s\" as an X.509 certificate", entry.getKey()), e);
"Could not read certificate alias \"%s\" as an X.509 certificate",
entry.getKey()), e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public static SSLContext createSslContext(SslConfiguration config) {
*/
public static SSLContext createSslContext(Map<String, PemX509Certificate> trustCertificatesByAlias) {
TrustManager[] trustManagers = createTrustManagers(trustCertificatesByAlias);
return createSslContext(trustManagers, new KeyManager[]{});
return createSslContext(trustManagers, new KeyManager[] {});
}

private static SSLContext createSslContext(TrustManager[] trustManagers, KeyManager[] keyManagers) {
Expand Down Expand Up @@ -144,7 +144,8 @@ public static TrustContext createTrustContext(SslConfiguration config) {
*/
public static TrustContext createTrustContext(Map<String, PemX509Certificate> trustCertificatesByAlias) {
return TrustContext.of(
createSslSocketFactory(trustCertificatesByAlias), createX509TrustManager(trustCertificatesByAlias));
createSslSocketFactory(trustCertificatesByAlias),
createX509TrustManager(trustCertificatesByAlias));
}

/**
Expand All @@ -171,7 +172,8 @@ public static X509TrustManager createX509TrustManager(Map<String, PemX509Certifi
} else {
throw new RuntimeException(String.format(
"First TrustManager associated with certificates was expected to be a %s, but was a %s",
X509TrustManager.class.getSimpleName(), trustManager.getClass().getSimpleName()));
X509TrustManager.class.getSimpleName(),
trustManager.getClass().getSimpleName()));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ public final class Pkcs1Readers {
private static final Supplier<Pkcs1Reader> PKCS1_READER_SUPPLIER = Suppliers.memoize(() -> {
Pkcs1Reader reader = Iterators.getNext(PKCS1_READER_LOADER.iterator(), null);

Preconditions.checkState(reader != null, "No Pkcs1Reader services were present. Ensure that a Pkcs1Reader "
+ "with a properly configured META-INF/services/ entry is present on the classpath.");
Preconditions.checkState(reader != null,
"No Pkcs1Reader services were present. Ensure that a Pkcs1Reader "
+ "with a properly configured META-INF/services/ entry is present on the classpath.");

return reader;
});
Expand All @@ -38,7 +39,6 @@ public static Pkcs1Reader getInstance() {
return PKCS1_READER_SUPPLIER.get();
}

private Pkcs1Readers() {
}
private Pkcs1Readers() {}

}
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public void testCreateTrustStoreFromDirectoryFailsWithNonCertFiles() throws IOEx
.isInstanceOf(RuntimeException.class)
.hasCauseInstanceOf(CertificateParsingException.class)
.hasMessageContaining(String.format("Could not read file at \"%s\" as an X.509 certificate",
tempCertFile.getAbsolutePath()));
tempCertFile.getAbsolutePath()));
}

@Test
Expand All @@ -105,7 +105,7 @@ public void testCreateTrustStoreFromDirectoryFailsWithDirectories() throws IOExc
.isInstanceOf(RuntimeException.class)
.hasCauseInstanceOf(CertificateException.class)
.hasMessageContaining(String.format("Could not read file at \"%s\" as an X.509 certificate",
tempDirFile.getAbsolutePath()));
tempDirFile.getAbsolutePath()));
}

@Test
Expand All @@ -123,9 +123,10 @@ public void createTrustStoreFromCertificatesFromCertificatesByAliasInvalidCert()

assertThatThrownBy(() -> KeyStores.createTrustStoreFromCertificates(
ImmutableMap.of("invalid.crt", PemX509Certificate.of(cert))))
.isInstanceOf(RuntimeException.class)
.hasCauseInstanceOf(CertificateParsingException.class)
.hasMessageContaining("Could not read certificate alias \"invalid.crt\" as an X.509 certificate");
.isInstanceOf(RuntimeException.class)
.hasCauseInstanceOf(CertificateParsingException.class)
.hasMessageContaining(
"Could not read certificate alias \"invalid.crt\" as an X.509 certificate");
}

@Test
Expand Down Expand Up @@ -183,7 +184,7 @@ public void testCreateKeyStoreFromDirectoryFailsWithNonKeyFiles() throws IOExcep
.isInstanceOf(RuntimeException.class)
.hasCauseInstanceOf(GeneralSecurityException.class)
.hasMessageContaining(String.format("Failed to read private key from file at \"%s\"",
tempCertFile.getAbsolutePath()));
tempCertFile.getAbsolutePath()));
}

@Test
Expand Down Expand Up @@ -218,14 +219,14 @@ public void testCreateKeyStoreFromPemDirectoriesFailsIfCertMissing() throws IOEx
Files.copy(TestConstants.SERVER_KEY_PEM_PATH.toFile(), keyFolder.toPath().resolve("server.key").toFile());

assertThatThrownBy(() -> KeyStores.createKeyStoreFromPemDirectories(
keyFolder.toPath(),
".key",
certFolder.toPath(),
".cer",
password))
.hasCauseInstanceOf(NoSuchFileException.class)
.hasMessageContaining(String.format("Failed to read certificates from file at \"%s\"",
certFolder.toPath().resolve("server.cer").toString()));
keyFolder.toPath(),
".key",
certFolder.toPath(),
".cer",
password))
.hasCauseInstanceOf(NoSuchFileException.class)
.hasMessageContaining(String.format("Failed to read certificates from file at \"%s\"",
certFolder.toPath().resolve("server.cer").toString()));
}

@Test
Expand All @@ -235,15 +236,23 @@ public void testCreateKeyStoreFromPemDirectoriesFailsIfArgIsNotDirectory() throw
File file = tempFolder.newFile();

assertThatThrownBy(() -> KeyStores.createKeyStoreFromPemDirectories(
file.toPath(), ".key", folder.toPath(), ".cer", password))
.isInstanceOf(IllegalStateException.class)
.hasMessageContaining(String.format("keyDirPath is not a directory: \"%s\"",
file.toPath().toString()));
file.toPath(),
".key",
folder.toPath(),
".cer",
password))
.isInstanceOf(IllegalStateException.class)
.hasMessageContaining(String.format("keyDirPath is not a directory: \"%s\"",
file.toPath().toString()));

assertThatThrownBy(() -> KeyStores.createKeyStoreFromPemDirectories(
folder.toPath(), ".key", file.toPath(), ".cer", password))
.isInstanceOf(IllegalStateException.class)
.hasMessageContaining(String.format("certDirPath is not a directory: \"%s\"",
file.toPath().toString()));
folder.toPath(),
".key",
file.toPath(),
".cer",
password))
.isInstanceOf(IllegalStateException.class)
.hasMessageContaining(String.format("certDirPath is not a directory: \"%s\"",
file.toPath().toString()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ public final class QosExceptionResponseMapper {

private static final Logger log = LoggerFactory.getLogger(QosExceptionResponseMapper.class);

private QosExceptionResponseMapper() {
}
private QosExceptionResponseMapper() {}

public static Optional<QosException> mapResponseCodeHeaderStream(
int code, Function<String, Stream<String>> headerFn) {
int code,
Function<String, Stream<String>> headerFn) {
return mapResponseCode(code, header -> headerFn.apply(header).findFirst().orElse(null));
}

Expand Down Expand Up @@ -65,7 +65,8 @@ private static Optional<QosException> map308(Function<String, String> headerFn)
return Optional.of(QosException.retryOther(new URL(locationHeader)));
} catch (MalformedURLException e) {
log.error("Failed to parse location header, not performing redirect",
UnsafeArg.of("locationHeader", locationHeader), e);
UnsafeArg.of("locationHeader", locationHeader),
e);
return Optional.empty();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,9 @@ private Key limiterKey(Request request) {
@Value.Immutable
interface Key {
String hostname();

Optional<String> method();

Optional<String> pathTemplate();
}

Expand Down Expand Up @@ -202,8 +204,10 @@ public String spanName() {
static final class NoOpLimiterListener implements Limiter.Listener {
@Override
public void onSuccess() {}

@Override
public void onIgnore() {}

@Override
public void onDropped() {}
}
Expand Down Expand Up @@ -256,7 +260,9 @@ synchronized void processQueue() {
if (!maybeAcquired.isPresent()) {
if (!timeoutScheduled()) {
timeoutCleanup = scheduledExecutorService.schedule(
this::resetLimiter, timeout.toMillis(), TimeUnit.MILLISECONDS);
this::resetLimiter,
timeout.toMillis(),
TimeUnit.MILLISECONDS);
}
return;
}
Expand All @@ -283,8 +289,8 @@ private synchronized boolean timeoutScheduled() {

private synchronized void resetLimiter() {
log.warn("Timed out waiting to get permits for concurrency. In most cases this would indicate some kind of "
+ "deadlock. We expect that either this is caused by either service overloading, or not "
+ "closing response bodies (consider using the try-with-resources pattern).",
+ "deadlock. We expect that either this is caused by either service overloading, or not "
+ "closing response bodies (consider using the try-with-resources pattern).",
SafeArg.of("serviceClass", serviceClass),
UnsafeArg.of("hostname", limiterKey.hostname()),
SafeArg.of("method", limiterKey.method()),
Expand Down Expand Up @@ -312,8 +318,7 @@ public void onSuccess(Limiter.Listener result) {
}

@Override
public void onFailure(Throwable error) {
}
public void onFailure(Throwable error) {}
}, MoreExecutors.directExecutor());
}

Expand Down Expand Up @@ -350,7 +355,8 @@ private static final class QueuedRequest {
private final Optional<RuntimeException> allocationStackTrace;

private QueuedRequest(
SettableFuture<Limiter.Listener> future, Optional<RuntimeException> allocationStackTrace) {
SettableFuture<Limiter.Listener> future,
Optional<RuntimeException> allocationStackTrace) {
this.future = future;
this.allocationStackTrace = allocationStackTrace;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
final class ConcurrencyLimitingInterceptor implements Interceptor {
private static final ImmutableSet<Integer> DROPPED_CODES = ImmutableSet.of(429, 503);

ConcurrencyLimitingInterceptor() { }
ConcurrencyLimitingInterceptor() {}

@Override
public Response intercept(Chain chain) throws IOException {
Expand Down Expand Up @@ -111,7 +111,7 @@ private static Response wrapResponse(Limiter.Listener listener, Response respons
private static BufferedSource wrapSource(BufferedSource currentSource, Limiter.Listener listener) {
return (BufferedSource) Proxy.newProxyInstance(
BufferedSource.class.getClassLoader(),
new Class<?>[] { BufferedSource.class },
new Class<?>[] {BufferedSource.class},
new ReleaseConcurrencyLimitProxy(currentSource, listener));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,10 @@ public void onSample(long startTime, long rtt, int inflight, boolean didDrop) {
MAX_WINDOW_TIME);
// +1 ensures that average rtt in nanos is never 0, which has a precond check in VegasLimit.
delegate.onSample(
startTime, current.getAverageRttNanos() + 1, current.getMaxInFlight(), didDrop);
startTime,
current.getAverageRttNanos() + 1,
current.getMaxInFlight(),
didDrop);
}
}
}
Expand Down
Loading

0 comments on commit 1c4ca7d

Please sign in to comment.