Skip to content

Commit dc6a4eb

Browse files
committed
Replace hardcoded charsets with StandardCharsets
1 parent 510d476 commit dc6a4eb

File tree

3 files changed

+8
-11
lines changed

3 files changed

+8
-11
lines changed

spring-batch-core/src/main/java/org/springframework/batch/core/DefaultJobKeyGenerator.java

Lines changed: 3 additions & 8 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.
@@ -15,7 +15,7 @@
1515
*/
1616
package org.springframework.batch.core;
1717

18-
import java.io.UnsupportedEncodingException;
18+
import java.nio.charset.StandardCharsets;
1919
import java.util.ArrayList;
2020
import java.util.Collections;
2121
import java.util.List;
@@ -55,12 +55,7 @@ public String generateKey(JobParameters source) {
5555
stringBuffer.append(key).append("=").append(value).append(";");
5656
}
5757
}
58-
try {
59-
return DigestUtils.md5DigestAsHex(stringBuffer.toString().getBytes("UTF-8"));
60-
}
61-
catch (UnsupportedEncodingException e) {
62-
throw new IllegalStateException("UTF-8 encoding not available. Fatal (should be in the JDK).");
63-
}
58+
return DigestUtils.md5DigestAsHex(stringBuffer.toString().getBytes(StandardCharsets.UTF_8));
6459
}
6560

6661
}

spring-batch-core/src/test/java/org/springframework/batch/core/repository/dao/JdbcJobInstanceDaoTests.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2008-2022 the original author or authors.
2+
* Copyright 2008-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.
@@ -19,6 +19,7 @@
1919
import static org.junit.jupiter.api.Assertions.assertTrue;
2020

2121
import java.math.BigInteger;
22+
import java.nio.charset.StandardCharsets;
2223
import java.security.MessageDigest;
2324
import java.util.List;
2425

@@ -74,7 +75,7 @@ void testFindJobInstanceByExecution() {
7475
@Test
7576
void testHexing() throws Exception {
7677
MessageDigest digest = MessageDigest.getInstance("MD5");
77-
byte[] bytes = digest.digest("f78spx".getBytes("UTF-8"));
78+
byte[] bytes = digest.digest("f78spx".getBytes(StandardCharsets.UTF_8));
7879
StringBuilder output = new StringBuilder();
7980
for (byte bite : bytes) {
8081
output.append(String.format("%02x", bite));

spring-batch-core/src/test/java/test/jdbc/datasource/DataSourceInitializer.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package test.jdbc.datasource;
1818

1919
import java.io.IOException;
20+
import java.nio.charset.StandardCharsets;
2021
import java.util.List;
2122
import javax.sql.DataSource;
2223

@@ -102,7 +103,7 @@ private void doExecuteScript(final Resource scriptResource) {
102103
String[] scripts;
103104
try {
104105
scripts = StringUtils.delimitedListToStringArray(
105-
stripComments(IOUtils.readLines(scriptResource.getInputStream(), "UTF-8")), ";");
106+
stripComments(IOUtils.readLines(scriptResource.getInputStream(), StandardCharsets.UTF_8)), ";");
106107
}
107108
catch (IOException e) {
108109
throw new BeanInitializationException("Cannot load script from [" + scriptResource + "]", e);

0 commit comments

Comments
 (0)