Skip to content

Commit 9763ea2

Browse files
Merge branch '1.14.x'
2 parents c63bc5a + 4c8c22f commit 9763ea2

File tree

17 files changed

+52
-35
lines changed

17 files changed

+52
-35
lines changed

build.gradle

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,12 @@ subprojects {
7575
tasks.withType(JavaCompile).configureEach {
7676
options.errorprone.disableWarningsInGeneratedCode = true
7777
options.errorprone.excludedPaths = ".*/build/generated/.*"
78-
options.errorprone.error("StringCaseLocaleUsage")
78+
options.errorprone.error(
79+
"BadImport",
80+
"DefaultCharset",
81+
"MissingOverride",
82+
"StringCaseLocaleUsage"
83+
)
7984

8085
if (!javaLanguageVersion.canCompileOrRun(17)) {
8186
// Error Prone does not work with JDK <17
@@ -450,7 +455,7 @@ nexusPublishing {
450455
}
451456

452457
wrapper {
453-
gradleVersion = '8.13'
458+
gradleVersion = '8.14'
454459
}
455460

456461
defaultTasks 'build'

docs/src/test/java/io/micrometer/docs/observation/messaging/ObservationMessagingIntegrationTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ public KafkaReceiverContext(ConsumerRecords<String, String> consumerRecord) {
178178
// This is a very naive approach that takes the first ConsumerRecord
179179
Header header = carrier.iterator().next().headers().lastHeader(key);
180180
if (header != null) {
181-
return new String(header.value());
181+
return new String(header.value(), StandardCharsets.UTF_8);
182182
}
183183
return null;
184184
});

gradle/wrapper/gradle-wrapper.jar

59 Bytes
Binary file not shown.

gradle/wrapper/gradle-wrapper.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-8.13-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.14-bin.zip
44
networkTimeout=10000
55
validateDistributionUrl=true
66
zipStoreBase=GRADLE_USER_HOME

gradlew

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ case "$( uname )" in #(
114114
NONSTOP* ) nonstop=true ;;
115115
esac
116116

117-
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
117+
CLASSPATH="\\\"\\\""
118118

119119

120120
# Determine the Java command to use to start the JVM.
@@ -213,7 +213,7 @@ DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
213213
set -- \
214214
"-Dorg.gradle.appname=$APP_BASE_NAME" \
215215
-classpath "$CLASSPATH" \
216-
org.gradle.wrapper.GradleWrapperMain \
216+
-jar "$APP_HOME/gradle/wrapper/gradle-wrapper.jar" \
217217
"$@"
218218

219219
# Stop when "xargs" is not available.

gradlew.bat

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,11 @@ goto fail
7070
:execute
7171
@rem Setup the command line
7272

73-
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73+
set CLASSPATH=
7474

7575

7676
@rem Execute Gradle
77-
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
77+
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %*
7878

7979
:end
8080
@rem End local scope for the variables with windows NT shell

implementations/micrometer-registry-dynatrace/src/test/java/io/micrometer/dynatrace/DynatraceConfigTest.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import org.junit.jupiter.api.Test;
2424

2525
import java.io.IOException;
26+
import java.nio.charset.StandardCharsets;
2627
import java.nio.file.Files;
2728
import java.nio.file.Path;
2829
import java.time.Duration;
@@ -311,7 +312,7 @@ void testFileBasedConfig() throws IOException {
311312

312313
Files.write(tempFile, ("DT_METRICS_INGEST_URL = https://your-dynatrace-ingest-url/api/v2/metrics/ingest\n"
313314
+ "DT_METRICS_INGEST_API_TOKEN = YOUR.DYNATRACE.TOKEN")
314-
.getBytes());
315+
.getBytes(StandardCharsets.UTF_8));
315316

316317
DynatraceFileBasedConfigurationProvider.getInstance()
317318
.forceOverwriteConfig(tempFile.toString(), Duration.ofMillis(50));
@@ -333,7 +334,7 @@ public DynatraceApiVersion apiVersion() {
333334

334335
Files.write(tempFile, ("DT_METRICS_INGEST_URL = https://a-different-url/api/v2/metrics/ingest\n"
335336
+ "DT_METRICS_INGEST_API_TOKEN = A.DIFFERENT.TOKEN")
336-
.getBytes());
337+
.getBytes(StandardCharsets.UTF_8));
337338

338339
await().atMost(1_000, MILLISECONDS).until(() -> config.apiToken().equals("A.DIFFERENT.TOKEN"));
339340
assertThat(config.uri()).isEqualTo("https://a-different-url/api/v2/metrics/ingest");

implementations/micrometer-registry-dynatrace/src/test/java/io/micrometer/dynatrace/v2/DynatraceExporterV2Test.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import org.junit.jupiter.api.Test;
3030
import org.mockito.ArgumentCaptor;
3131

32+
import java.nio.charset.StandardCharsets;
3233
import java.nio.file.Files;
3334
import java.nio.file.Path;
3435
import java.time.Duration;
@@ -663,9 +664,11 @@ public String get(String key) {
663664
final String firstUri = baseUri + "first";
664665
final String secondUri = baseUri + "second";
665666

666-
Files.write(tempFile, ("DT_METRICS_INGEST_URL = " + firstUri + "\n"
667-
+ "DT_METRICS_INGEST_API_TOKEN = YOUR.DYNATRACE.TOKEN.FIRST")
668-
.getBytes());
667+
Files
668+
.write(tempFile,
669+
("DT_METRICS_INGEST_URL = " + firstUri + "\n"
670+
+ "DT_METRICS_INGEST_API_TOKEN = YOUR.DYNATRACE.TOKEN.FIRST")
671+
.getBytes(StandardCharsets.UTF_8));
669672

670673
DynatraceFileBasedConfigurationProvider.getInstance()
671674
.forceOverwriteConfig(tempFile.toString(), Duration.ofMillis(50));
@@ -689,9 +692,10 @@ public String get(String key) {
689692
clock.add(config.step());
690693

691694
// overwrite the file content to use the second uri
692-
Files.write(tempFile, ("DT_METRICS_INGEST_URL = " + secondUri + "\n"
693-
+ "DT_METRICS_INGEST_API_TOKEN = YOUR.DYNATRACE.TOKEN.SECOND")
694-
.getBytes());
695+
Files.write(tempFile,
696+
("DT_METRICS_INGEST_URL = " + secondUri + "\n"
697+
+ "DT_METRICS_INGEST_API_TOKEN = YOUR.DYNATRACE.TOKEN.SECOND")
698+
.getBytes(StandardCharsets.UTF_8));
695699

696700
await().atMost(1_000, MILLISECONDS).until(() -> config.uri().equals(secondUri));
697701
exporter.export(Collections.singletonList(counter));

implementations/micrometer-registry-new-relic/src/test/java/io/micrometer/newrelic/NewRelicMeterRegistryTest.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import io.micrometer.newrelic.NewRelicMeterRegistryTest.MockNewRelicAgent.MockNewRelicInsights;
2525
import org.junit.jupiter.api.Test;
2626

27+
import java.nio.charset.StandardCharsets;
2728
import java.util.Arrays;
2829
import java.util.HashMap;
2930
import java.util.List;
@@ -612,7 +613,7 @@ void sendEventsWithApiProvider() {
612613

613614
apiProvider.sendEvents(apiProvider.writeGauge(gauge));
614615

615-
assertThat(new String(mockHttpClient.getRequest().getEntity())).contains(
616+
assertThat(new String(mockHttpClient.getRequest().getEntity(), StandardCharsets.UTF_8)).contains(
616617
"{\"eventType\":\"MicrometerSample\",\"value\":1,\"metricName\":\"myGauge\",\"metricType\":\"GAUGE\"}");
617618

618619
// test meterNameEventTypeEnabledConfig = true
@@ -624,7 +625,7 @@ void sendEventsWithApiProvider() {
624625

625626
apiProvider.sendEvents(apiProvider.writeGauge(gauge));
626627

627-
assertThat(new String(mockHttpClient.getRequest().getEntity()))
628+
assertThat(new String(mockHttpClient.getRequest().getEntity(), StandardCharsets.UTF_8))
628629
.contains("{\"eventType\":\"myGauge2\",\"value\":1}");
629630
}
630631

@@ -679,7 +680,7 @@ void publishWithApiClientProvider() {
679680
registry.publish();
680681

681682
// should send a batch of multiple in one json payload
682-
assertThat(new String(mockHttpClient.getRequest().getEntity())).contains(
683+
assertThat(new String(mockHttpClient.getRequest().getEntity(), StandardCharsets.UTF_8)).contains(
683684
"[{\"eventType\":\"MicrometerSample\",\"value\":2,\"metricName\":\"otherGauge\",\"metricType\":\"GAUGE\"},"
684685
+ "{\"eventType\":\"MicrometerSample\",\"value\":1,\"metricName\":\"myGauge\",\"metricType\":\"GAUGE\",\"theTag\":\"theValue\"}]");
685686
}

implementations/micrometer-registry-prometheus/src/main/java/io/micrometer/prometheusmetrics/PrometheusMeterRegistry.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
import java.io.ByteArrayOutputStream;
4343
import java.io.IOException;
4444
import java.io.OutputStream;
45+
import java.nio.charset.StandardCharsets;
4546
import java.util.ArrayList;
4647
import java.util.List;
4748
import java.util.Set;
@@ -136,7 +137,7 @@ public String scrape(String contentType) {
136137
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
137138
try {
138139
scrape(outputStream, contentType);
139-
return outputStream.toString();
140+
return outputStream.toString(StandardCharsets.UTF_8.name());
140141
}
141142
catch (IOException e) {
142143
// This should not happen during writing a ByteArrayOutputStream
@@ -182,7 +183,7 @@ public String scrape(String contentType, @Nullable Set<String> includedNames) {
182183
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
183184
try {
184185
scrape(outputStream, contentType, includedNames);
185-
return outputStream.toString();
186+
return outputStream.toString(StandardCharsets.UTF_8.name());
186187
}
187188
catch (IOException e) {
188189
// This should not happen during writing a ByteArrayOutputStream

implementations/micrometer-registry-prometheus/src/test/java/io/micrometer/prometheusmetrics/PrometheusMeterRegistryIntegrationTest.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import java.io.IOException;
3636
import java.io.OutputStream;
3737
import java.net.InetSocketAddress;
38+
import java.nio.charset.StandardCharsets;
3839
import java.time.Duration;
3940
import java.util.ArrayList;
4041
import java.util.List;
@@ -277,9 +278,9 @@ private HttpServer startHttpServer(int port) throws IOException {
277278
String response = registry.scrape(acceptHeader);
278279

279280
httpExchange.getResponseHeaders().add("Content-Type", contentType);
280-
httpExchange.sendResponseHeaders(200, response.getBytes().length);
281+
httpExchange.sendResponseHeaders(200, response.getBytes(StandardCharsets.UTF_8).length);
281282
try (OutputStream outputStream = httpExchange.getResponseBody()) {
282-
outputStream.write(response.getBytes());
283+
outputStream.write(response.getBytes(StandardCharsets.UTF_8));
283284
}
284285
});
285286
new Thread(server::start).start();

implementations/micrometer-registry-statsd/src/main/java/io/micrometer/statsd/internal/BufferingFlux.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import reactor.core.publisher.DirectProcessor;
1919
import reactor.core.publisher.Flux;
2020

21+
import java.nio.charset.StandardCharsets;
2122
import java.time.Duration;
2223
import java.util.concurrent.atomic.AtomicInteger;
2324
import java.util.concurrent.atomic.AtomicLong;
@@ -45,7 +46,7 @@ private BufferingFlux() {
4546
public static Flux<String> create(final Flux<String> source, final String delimiter, final int maxByteArraySize,
4647
final long maxMillisecondsBetweenEmits) {
4748
return Flux.defer(() -> {
48-
final int delimiterSize = delimiter.getBytes().length;
49+
final int delimiterSize = delimiter.getBytes(StandardCharsets.UTF_8).length;
4950
final AtomicInteger byteSize = new AtomicInteger();
5051
final AtomicLong lastTime = new AtomicLong();
5152

@@ -62,7 +63,7 @@ public static Flux<String> create(final Flux<String> source, final String delimi
6263
.mergeWith(heartbeat);
6364

6465
return sourceWithEmptyStringKeepAlive.bufferUntil(line -> {
65-
final int bytesLength = line.getBytes().length;
66+
final int bytesLength = line.getBytes(StandardCharsets.UTF_8).length;
6667
final long now = System.currentTimeMillis();
6768
// Update last time to now if this is the first time
6869
lastTime.compareAndSet(0, now);

micrometer-core/src/main/java/io/micrometer/core/ipc/http/HttpSender.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ public String toString() {
120120
printed.append("<no request body>");
121121
}
122122
else {
123-
printed.append(new String(entity));
123+
printed.append(new String(entity, StandardCharsets.UTF_8));
124124
}
125125
return printed.toString();
126126
}

micrometer-core/src/test/java/io/micrometer/core/instrument/binder/tomcat/TomcatMetricsTest.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
import javax.servlet.http.HttpServletRequest;
4545
import javax.servlet.http.HttpServletResponse;
4646
import java.io.IOException;
47+
import java.nio.charset.StandardCharsets;
4748
import java.util.Arrays;
4849
import java.util.Collection;
4950
import java.util.Collections;
@@ -150,7 +151,7 @@ void whenTomcatMetricsBoundBeforeTomcatStarted_mbeanMetricsRegisteredEventually(
150151
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {
151152
IOUtils.toString(req.getInputStream());
152153
sleep();
153-
resp.getOutputStream().write("yes".getBytes());
154+
resp.getOutputStream().write("yes".getBytes(StandardCharsets.UTF_8));
154155
}
155156
};
156157

@@ -183,7 +184,7 @@ void whenTomcatMetricsBoundAfterTomcatStarted_mbeanMetricsRegisteredImmediately(
183184
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {
184185
IOUtils.toString(req.getInputStream());
185186
sleep();
186-
resp.getOutputStream().write("yes".getBytes());
187+
resp.getOutputStream().write("yes".getBytes(StandardCharsets.UTF_8));
187188
}
188189
};
189190

@@ -217,15 +218,15 @@ void whenMultipleServlets_thenRegisterMetricsForAllServlets() throws Exception {
217218
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {
218219
IOUtils.toString(req.getInputStream());
219220
sleep();
220-
resp.getOutputStream().write("yes".getBytes());
221+
resp.getOutputStream().write("yes".getBytes(StandardCharsets.UTF_8));
221222
}
222223
}, new HttpServlet() {
223224
@Override
224225
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
225226
throws ServletException, IOException {
226227
IOUtils.toString(req.getInputStream());
227228
sleep();
228-
resp.getOutputStream().write("hi".getBytes());
229+
resp.getOutputStream().write("hi".getBytes(StandardCharsets.UTF_8));
229230
}
230231
});
231232

@@ -277,15 +278,15 @@ else if ("servlet1".equals(m.getId().getTag("name"))) {
277278
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {
278279
IOUtils.toString(req.getInputStream());
279280
sleep();
280-
resp.getOutputStream().write("yes".getBytes());
281+
resp.getOutputStream().write("yes".getBytes(StandardCharsets.UTF_8));
281282
}
282283
}, new HttpServlet() {
283284
@Override
284285
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
285286
throws ServletException, IOException {
286287
IOUtils.toString(req.getInputStream());
287288
sleep();
288-
resp.getOutputStream().write("hi".getBytes());
289+
resp.getOutputStream().write("hi".getBytes(StandardCharsets.UTF_8));
289290
}
290291
});
291292

micrometer-core/src/test/java/io/micrometer/core/instrument/util/IOUtilsTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class IOUtilsTest {
3333
void testToString() {
3434
String expected = "This is a sample.";
3535

36-
ByteArrayInputStream inputStream = new ByteArrayInputStream(expected.getBytes());
36+
ByteArrayInputStream inputStream = new ByteArrayInputStream(expected.getBytes(StandardCharsets.UTF_8));
3737

3838
assertThat(IOUtils.toString(inputStream)).isEqualTo(expected);
3939
}

micrometer-core/src/test/java/io/micrometer/core/testsupport/system/OutputCapture.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import java.io.IOException;
2222
import java.io.OutputStream;
2323
import java.io.PrintStream;
24+
import java.nio.charset.StandardCharsets;
2425
import java.util.ArrayDeque;
2526
import java.util.ArrayList;
2627
import java.util.Deque;
@@ -260,7 +261,7 @@ public void write(int b) throws IOException {
260261

261262
@Override
262263
public void write(byte[] b, int off, int len) throws IOException {
263-
this.copy.accept(new String(b, off, len));
264+
this.copy.accept(new String(b, off, len, StandardCharsets.UTF_8));
264265
this.systemStream.write(b, off, len);
265266
}
266267

samples/micrometer-samples-core/src/main/java/io/micrometer/core/samples/utils/SampleRegistries.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262

6363
import java.io.*;
6464
import java.net.InetSocketAddress;
65+
import java.nio.charset.StandardCharsets;
6566
import java.time.Duration;
6667

6768
public class SampleRegistries {
@@ -116,7 +117,7 @@ public String get(String k) {
116117
String response = prometheusRegistry.scrape();
117118
httpExchange.sendResponseHeaders(200, response.length());
118119
OutputStream os = httpExchange.getResponseBody();
119-
os.write(response.getBytes());
120+
os.write(response.getBytes(StandardCharsets.UTF_8));
120121
os.close();
121122
});
122123

0 commit comments

Comments
 (0)