From 2c0e24f4a3d4604b2e3b768e653bcc70b14f62d3 Mon Sep 17 00:00:00 2001 From: Darren Gorman Date: Wed, 9 Apr 2014 17:25:51 +0100 Subject: [PATCH] Removed serialisable check on ExecutionContext entries The serialisation/deserialisation implementation is injectable, so it does not make sense to enforce the presence of this interface --- .../dao/DefaultExecutionContextSerializerTests.java | 8 ++++++++ .../springframework/batch/item/ExecutionContext.java | 5 ++--- .../batch/item/ExecutionContextTests.java | 12 ------------ 3 files changed, 10 insertions(+), 15 deletions(-) diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/repository/dao/DefaultExecutionContextSerializerTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/repository/dao/DefaultExecutionContextSerializerTests.java index 9973f22df..66d29299a 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/repository/dao/DefaultExecutionContextSerializerTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/repository/dao/DefaultExecutionContextSerializerTests.java @@ -48,6 +48,14 @@ public class DefaultExecutionContextSerializerTests { compareContexts(m1, m2); } + @Test(expected = IllegalArgumentException.class) + public void testSerializeNonSerializable() throws Exception { + Map m1 = new HashMap(); + m1.put("object1", new Object()); + + serializer.serialize(m1, new ByteArrayOutputStream()); + } + @Test public void testComplexObject() throws Exception { Map m1 = new HashMap(); diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/ExecutionContext.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/ExecutionContext.java index 3b40126f8..485790dec 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/ExecutionContext.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/ExecutionContext.java @@ -117,15 +117,14 @@ public class ExecutionContext implements Serializable { } /** - * Add an Object value to the context (must be Serializable). Putting - * null value for a given key removes the key. + * Add an Object value to the context. Putting null + * value for a given key removes the key. * * @param key Key to add to context * @param value Value to associate with key */ public void put(String key, Object value) { if (value != null) { - Assert.isInstanceOf(Serializable.class, value, "Value: [ " + value + "must be serializable."); Object result = map.put(key, value); dirty = result==null || result!=null && !result.equals(value); } diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/ExecutionContextTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/ExecutionContextTests.java index fd7ef8f9e..b18cec304 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/ExecutionContextTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/ExecutionContextTests.java @@ -124,18 +124,6 @@ public class ExecutionContextTests { assertTrue(tempContext.equals(context)); } - @Test - public void testSerializationCheck() { - // adding a non serializable object should cause an error. - try { - context.put("1", new Object()); - fail(); - } - catch (IllegalArgumentException ex) { - // expected - } - } - /** * Putting null value is equivalent to removing the entry for the given key. */