diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/JdbcExecutionContextDao.java b/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/JdbcExecutionContextDao.java index ab76d53e0..91e1903fb 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/JdbcExecutionContextDao.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/JdbcExecutionContextDao.java @@ -354,7 +354,7 @@ public class JdbcExecutionContextDao extends AbstractJdbcBatchMetadataDao implem try { serializer.serialize(m, out); - results = new String(out.toByteArray(), charset.name()); + results = out.toString(charset); } catch (IOException ioe) { throw new IllegalArgumentException("Could not serialize the execution context", ioe); @@ -374,7 +374,7 @@ public class JdbcExecutionContextDao extends AbstractJdbcBatchMetadataDao implem Map map; try { - ByteArrayInputStream in = new ByteArrayInputStream(serializedContext.getBytes(charset.name())); + ByteArrayInputStream in = new ByteArrayInputStream(serializedContext.getBytes(charset)); map = serializer.deserialize(in); } catch (IOException ioe) { diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/support/transaction/TransactionAwareBufferedWriterTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/support/transaction/TransactionAwareBufferedWriterTests.java index cd3348cb3..1c236239d 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/support/transaction/TransactionAwareBufferedWriterTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/support/transaction/TransactionAwareBufferedWriterTests.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. @@ -18,6 +18,7 @@ package org.springframework.batch.support.transaction; import java.io.IOException; import java.nio.ByteBuffer; import java.nio.channels.FileChannel; +import java.nio.charset.StandardCharsets; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -41,6 +42,7 @@ import static org.mockito.Mockito.when; * @author Michael Minella * @author Will Schipp * @author Niels Ferguson + * @author Mahmoud Ben Hassine * */ class TransactionAwareBufferedWriterTests { @@ -301,7 +303,7 @@ class TransactionAwareBufferedWriterTests { FileChannel fileChannel = mock(FileChannel.class); when(fileChannel.write(any(ByteBuffer.class))).thenAnswer(invocation -> { ByteBuffer buffer = (ByteBuffer) invocation.getArguments()[0]; - String val = new String(buffer.array(), "UTF-8"); + String val = new String(buffer.array(), StandardCharsets.UTF_8); if (results[index] == null) { results[index] = val; } diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/MultilineJobFunctionalTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/MultilineJobFunctionalTests.java index dada9ca79..294813ab7 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/MultilineJobFunctionalTests.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/MultilineJobFunctionalTests.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. @@ -16,6 +16,8 @@ package org.springframework.batch.sample; +import java.nio.charset.StandardCharsets; + import org.apache.commons.io.IOUtils; import org.junit.jupiter.api.Test; @@ -45,8 +47,9 @@ class MultilineJobFunctionalTests { @Test void testJobLaunch() throws Exception { this.jobLauncherTestUtils.launchJob(); - assertEquals(EXPECTED_RESULT, StringUtils.replace(IOUtils.toString(output.getInputStream(), "UTF-8"), - System.getProperty("line.separator"), "")); + assertEquals(EXPECTED_RESULT, + StringUtils.replace(IOUtils.toString(output.getInputStream(), StandardCharsets.UTF_8), + System.getProperty("line.separator"), "")); } }