diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/DefaultJobKeyGenerator.java b/spring-batch-core/src/main/java/org/springframework/batch/core/DefaultJobKeyGenerator.java index 695bd94b4..9944fdfad 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/DefaultJobKeyGenerator.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/DefaultJobKeyGenerator.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2022 the original author or authors. + * Copyright 2006-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,7 +15,7 @@ */ package org.springframework.batch.core; -import java.io.UnsupportedEncodingException; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -55,12 +55,7 @@ public class DefaultJobKeyGenerator implements JobKeyGenerator { stringBuffer.append(key).append("=").append(value).append(";"); } } - try { - return DigestUtils.md5DigestAsHex(stringBuffer.toString().getBytes("UTF-8")); - } - catch (UnsupportedEncodingException e) { - throw new IllegalStateException("UTF-8 encoding not available. Fatal (should be in the JDK)."); - } + return DigestUtils.md5DigestAsHex(stringBuffer.toString().getBytes(StandardCharsets.UTF_8)); } } diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/repository/dao/JdbcJobInstanceDaoTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/repository/dao/JdbcJobInstanceDaoTests.java index fe3826ecc..19f2cb5a3 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/repository/dao/JdbcJobInstanceDaoTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/repository/dao/JdbcJobInstanceDaoTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2008-2022 the original author or authors. + * Copyright 2008-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,6 +19,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; import java.math.BigInteger; +import java.nio.charset.StandardCharsets; import java.security.MessageDigest; import java.util.List; @@ -74,7 +75,7 @@ public class JdbcJobInstanceDaoTests extends AbstractJobInstanceDaoTests { @Test void testHexing() throws Exception { MessageDigest digest = MessageDigest.getInstance("MD5"); - byte[] bytes = digest.digest("f78spx".getBytes("UTF-8")); + byte[] bytes = digest.digest("f78spx".getBytes(StandardCharsets.UTF_8)); StringBuilder output = new StringBuilder(); for (byte bite : bytes) { output.append(String.format("%02x", bite)); diff --git a/spring-batch-core/src/test/java/test/jdbc/datasource/DataSourceInitializer.java b/spring-batch-core/src/test/java/test/jdbc/datasource/DataSourceInitializer.java index 2bd7ca7d7..d723bf9b2 100644 --- a/spring-batch-core/src/test/java/test/jdbc/datasource/DataSourceInitializer.java +++ b/spring-batch-core/src/test/java/test/jdbc/datasource/DataSourceInitializer.java @@ -17,6 +17,7 @@ package test.jdbc.datasource; import java.io.IOException; +import java.nio.charset.StandardCharsets; import java.util.List; import javax.sql.DataSource; @@ -102,7 +103,7 @@ public class DataSourceInitializer implements InitializingBean { String[] scripts; try { scripts = StringUtils.delimitedListToStringArray( - stripComments(IOUtils.readLines(scriptResource.getInputStream(), "UTF-8")), ";"); + stripComments(IOUtils.readLines(scriptResource.getInputStream(), StandardCharsets.UTF_8)), ";"); } catch (IOException e) { throw new BeanInitializationException("Cannot load script from [" + scriptResource + "]", e);