Skip to content

Commit 1758f7b

Browse files
authored
Suppress spurious MockWebServer crash warnings in CI logs (#7357)
Route java.util.logging through SLF4J via jul-to-slf4j bridge, which discards the output through the existing slf4j-nop binding in tests. This suppresses StringIndexOutOfBoundsException crash logs from MockWebServer when normalizeRepository() probes HTTPS on HTTP-only mock servers. Also fix flaky useHttpWhenHttpsFails test by switching from enqueue to Dispatcher to avoid TLS probe bytes consuming the single enqueued response.
1 parent 245278a commit 1758f7b

4 files changed

Lines changed: 35 additions & 2 deletions

File tree

rewrite-maven/build.gradle.kts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ dependencies {
4343
testImplementation("com.squareup.okio:okio-jvm:3.9.1")
4444
testImplementation("org.mapdb:mapdb:latest.release")
4545

46+
testRuntimeOnly("org.slf4j:jul-to-slf4j:latest.release")
4647
testRuntimeOnly("org.mapdb:mapdb:latest.release")
4748
testRuntimeOnly(project(":rewrite-java-21"))
4849
testRuntimeOnly("org.rocksdb:rocksdbjni:10.2.1")
@@ -62,6 +63,10 @@ tasks.register<JavaExec>("generateAntlrSources") {
6263
finalizedBy("licenseFormat")
6364
}
6465

66+
tasks.withType<Test>().configureEach {
67+
jvmArgs("-Djava.util.logging.config.file=${file("src/test/resources/logging.properties").absolutePath}")
68+
}
69+
6570
tasks.withType<Javadoc>().configureEach {
6671
// generated ANTLR sources violate doclint
6772
(options as StandardJavadocDocletOptions).addStringOption("Xdoclint:none", "-quiet")

rewrite-maven/src/test/java/org/openrewrite/maven/MavenParserTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -984,7 +984,6 @@ void dependencyScopeTakesPrecedenceOverDependencyManagementScope() {
984984
@Test
985985
void mirrorsAndAuth() throws Exception {
986986
// Set up a web server that returns 401 to any request without an Authorization header corresponding to specific credentials
987-
// Exceptions in the console output are due to MavenPomDownloader attempting to access via https first before falling back to http
988987
var username = "admin";
989988
var password = "password";
990989
try (var mockRepo = new MockWebServer()) {

rewrite-maven/src/test/java/org/openrewrite/maven/internal/MavenPomDownloaderTest.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,16 @@ void normalizeRejectConnectException() {
346346
void useHttpWhenHttpsFails() throws Exception {
347347
var downloader = new MavenPomDownloader(emptyMap(), ctx);
348348
try (var mockRepo = new MockWebServer()) {
349-
mockRepo.enqueue(new MockResponse().setResponseCode(200).setBody("body"));
349+
// Use a Dispatcher instead of enqueue to avoid flakiness: normalizeRepository()
350+
// probes HTTPS first, and TLS bytes sent to this HTTP-only server can sometimes
351+
// parse as valid HTTP, consuming an enqueued response before the real HTTP request.
352+
mockRepo.setDispatcher(new Dispatcher() {
353+
@Override
354+
public MockResponse dispatch(RecordedRequest recordedRequest) {
355+
return new MockResponse().setResponseCode(200).setBody("body");
356+
}
357+
});
358+
mockRepo.start();
350359
var httpRepo = MavenRepository.builder()
351360
.id("id")
352361
.uri("http://%s:%d/maven/".formatted(mockRepo.getHostName(), mockRepo.getPort()))
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#
2+
# Copyright 2025 the original author or authors.
3+
# <p>
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
# <p>
8+
# https://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
#
16+
17+
# Route java.util.logging through SLF4J, which uses slf4j-nop in tests.
18+
# This suppresses spurious MockWebServer crash logs caused by
19+
# normalizeRepository() probing HTTPS on HTTP-only mock servers.
20+
handlers = org.slf4j.bridge.SLF4JBridgeHandler

0 commit comments

Comments
 (0)