Skip to content

Commit efdb59e

Browse files
committed
Replace hardcoded charsets with StandardCharsets
1 parent f0137bc commit efdb59e

File tree

3 files changed

+12
-7
lines changed

3 files changed

+12
-7
lines changed

spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/JdbcExecutionContextDao.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ private String serializeContext(ExecutionContext ctx) {
354354

355355
try {
356356
serializer.serialize(m, out);
357-
results = new String(out.toByteArray(), charset.name());
357+
results = out.toString(charset);
358358
}
359359
catch (IOException ioe) {
360360
throw new IllegalArgumentException("Could not serialize the execution context", ioe);
@@ -374,7 +374,7 @@ public ExecutionContext mapRow(ResultSet rs, int i) throws SQLException {
374374

375375
Map<String, Object> map;
376376
try {
377-
ByteArrayInputStream in = new ByteArrayInputStream(serializedContext.getBytes(charset.name()));
377+
ByteArrayInputStream in = new ByteArrayInputStream(serializedContext.getBytes(charset));
378378
map = serializer.deserialize(in);
379379
}
380380
catch (IOException ioe) {

spring-batch-infrastructure/src/test/java/org/springframework/batch/support/transaction/TransactionAwareBufferedWriterTests.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2006-2022 the original author or authors.
2+
* Copyright 2006-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -18,6 +18,7 @@
1818
import java.io.IOException;
1919
import java.nio.ByteBuffer;
2020
import java.nio.channels.FileChannel;
21+
import java.nio.charset.StandardCharsets;
2122

2223
import org.junit.jupiter.api.BeforeEach;
2324
import org.junit.jupiter.api.Test;
@@ -41,6 +42,7 @@
4142
* @author Michael Minella
4243
* @author Will Schipp
4344
* @author Niels Ferguson
45+
* @author Mahmoud Ben Hassine
4446
*
4547
*/
4648
class TransactionAwareBufferedWriterTests {
@@ -301,7 +303,7 @@ void testResourceKeyCollision() throws Exception {
301303
FileChannel fileChannel = mock(FileChannel.class);
302304
when(fileChannel.write(any(ByteBuffer.class))).thenAnswer(invocation -> {
303305
ByteBuffer buffer = (ByteBuffer) invocation.getArguments()[0];
304-
String val = new String(buffer.array(), "UTF-8");
306+
String val = new String(buffer.array(), StandardCharsets.UTF_8);
305307
if (results[index] == null) {
306308
results[index] = val;
307309
}

spring-batch-samples/src/test/java/org/springframework/batch/sample/MultilineJobFunctionalTests.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2006-2022 the original author or authors.
2+
* Copyright 2006-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,6 +16,8 @@
1616

1717
package org.springframework.batch.sample;
1818

19+
import java.nio.charset.StandardCharsets;
20+
1921
import org.apache.commons.io.IOUtils;
2022
import org.junit.jupiter.api.Test;
2123

@@ -45,8 +47,9 @@ class MultilineJobFunctionalTests {
4547
@Test
4648
void testJobLaunch() throws Exception {
4749
this.jobLauncherTestUtils.launchJob();
48-
assertEquals(EXPECTED_RESULT, StringUtils.replace(IOUtils.toString(output.getInputStream(), "UTF-8"),
49-
System.getProperty("line.separator"), ""));
50+
assertEquals(EXPECTED_RESULT,
51+
StringUtils.replace(IOUtils.toString(output.getInputStream(), StandardCharsets.UTF_8),
52+
System.getProperty("line.separator"), ""));
5053
}
5154

5255
}

0 commit comments

Comments
 (0)