Skip to content
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

Excavator: Format Java files #1218

Merged
merged 1 commit into from
Sep 24, 2019
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
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 @@ -78,12 +78,12 @@ public void testClientIsInstrumentedWithTracer() throws InterruptedException {

Tracer.unsubscribe(TracerTest.class.getName());
assertThat(observedSpans).containsExactlyInAnyOrder(
Maps.immutableEntry(SpanType.LOCAL, "OkHttp: GET /{param}"),
Maps.immutableEntry(SpanType.LOCAL, "OkHttp: attempt 0"),
Maps.immutableEntry(SpanType.LOCAL, "OkHttp: client-side-concurrency-limiter 0/10"),
Maps.immutableEntry(SpanType.LOCAL, "OkHttp: dispatcher"),
Maps.immutableEntry(SpanType.CLIENT_OUTGOING, "OkHttp: wait-for-headers"),
Maps.immutableEntry(SpanType.CLIENT_OUTGOING, "OkHttp: wait-for-body"));
Maps.immutableEntry(SpanType.LOCAL, "OkHttp: GET /{param}"),
Maps.immutableEntry(SpanType.LOCAL, "OkHttp: attempt 0"),
Maps.immutableEntry(SpanType.LOCAL, "OkHttp: client-side-concurrency-limiter 0/10"),
Maps.immutableEntry(SpanType.LOCAL, "OkHttp: dispatcher"),
Maps.immutableEntry(SpanType.CLIENT_OUTGOING, "OkHttp: wait-for-headers"),
Maps.immutableEntry(SpanType.CLIENT_OUTGOING, "OkHttp: wait-for-body"));

RecordedRequest request = server.takeRequest();
assertThat(request.getHeader(TraceHttpHeaders.TRACE_ID)).isEqualTo(traceId);
Expand Down
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 @@ -119,7 +122,8 @@ static KeyStore createTrustStoreFromCertificates(Map<String, PemX509Certificate>
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 @@ -88,7 +88,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 @@ -102,7 +102,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 @@ -120,9 +120,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 All @@ -136,7 +137,7 @@ public void testCreateKeyStoreFromPemFile() throws GeneralSecurityException, IOE
assertThat(keyStore.size()).isEqualTo(1);
assertThat(keyStore.getCertificate(
TestConstants.SERVER_KEY_CERT_COMBINED_PEM_PATH.getFileName().toString()).toString())
.contains("CN=testCA");
.contains("CN=testCA");
assertThat(keyStore.getKey(TestConstants.SERVER_KEY_CERT_COMBINED_PEM_PATH.getFileName().toString(),
password.toCharArray()).getFormat()).isEqualTo("PKCS#8");
}
Expand Down Expand Up @@ -179,7 +180,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 @@ -214,14 +215,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 @@ -231,15 +232,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