From 03d56f6834a18b8d0c268625760e5a03b131a6c0 Mon Sep 17 00:00:00 2001 From: sjh836 Date: Wed, 15 Sep 2021 01:50:39 +0900 Subject: [PATCH 1/2] Assign a static collection to a local variable in StepContext#getPartitionPlan --- .../batch/core/scope/context/StepContext.java | 4 ++-- .../batch/core/scope/context/StepContextTests.java | 10 +++++++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/scope/context/StepContext.java b/spring-batch-core/src/main/java/org/springframework/batch/core/scope/context/StepContext.java index 99c35c66dc..5173ecdee1 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/scope/context/StepContext.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/scope/context/StepContext.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2019 the original author or authors. + * Copyright 2006-2021 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. @@ -160,7 +160,7 @@ public Map getJobParameters() { @SuppressWarnings({"rawtypes", "unchecked"}) public Map getPartitionPlan() { - Map partitionPlanProperties = new HashMap<>(); + Map partitionPlanProperties = Collections.emptyMap(); if(propertyContext != null) { Map partitionProperties = propertyContext.getStepProperties(getStepName()); diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/scope/context/StepContextTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/scope/context/StepContextTests.java index e0b70a6685..a01123c777 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/scope/context/StepContextTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/scope/context/StepContextTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2019 the original author or authors. + * Copyright 2006-2021 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. @@ -81,6 +81,14 @@ public void testGetPartitionPlan() { assertEquals("value1", plan.get("key1")); } + @Test + public void testGetPartitionPlanWhenPropertyContextIsNull() { + context = new StepContext(stepExecution, null); + + Map plan = context.getPartitionPlan(); + assertEquals(0, plan.size()); + } + @Test public void testEqualsSelf() { assertEquals(context, context); From 34f20fed98ee0d2aeecdeec1efb30fd8e62d33bf Mon Sep 17 00:00:00 2001 From: sjh836 Date: Wed, 15 Sep 2021 01:53:48 +0900 Subject: [PATCH 2/2] Change from arrayList to immutableList in OrderedComposite#iterator --- .../springframework/batch/core/listener/OrderedComposite.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/listener/OrderedComposite.java b/spring-batch-core/src/main/java/org/springframework/batch/core/listener/OrderedComposite.java index f8cf88e5db..643b9e863d 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/listener/OrderedComposite.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/listener/OrderedComposite.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2007 the original author or authors. + * Copyright 2006-2021 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. @@ -84,7 +84,7 @@ else if (!unordered.contains(item)) { * @return an iterator over the list of items */ public Iterator iterator() { - return new ArrayList<>(list).iterator(); + return Collections.unmodifiableList(list).iterator(); } /**