From f78aa275c045cf35168f7a9f081e7b3709f338ae Mon Sep 17 00:00:00 2001 From: Philippe Marschall Date: Sat, 15 Oct 2016 12:44:56 +0200 Subject: [PATCH] BATCH-2396 Guard Serializable check message The exception message for the Serializable check in DefaultExecutionContextSerializer is always generated. For large contexts this can quickly put a log of pressure on the allocator and the heap. This commit contains the following changes: * generate the exception message for non-serializable values in DefaultExecutionContextSerializer only when needed I have signed and agree to the terms of the SpringSource Individual Contributor License Agreement. Issue: BATCH-2396 --- .../DefaultExecutionContextSerializer.java | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/DefaultExecutionContextSerializer.java b/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/DefaultExecutionContextSerializer.java index 629135c72..b32f53d36 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/DefaultExecutionContextSerializer.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/DefaultExecutionContextSerializer.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2013 the original author or authors. + * Copyright 2012-2017 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,6 +15,12 @@ */ package org.springframework.batch.core.repository.dao; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.io.Serializable; +import java.util.Map; + import org.springframework.batch.core.repository.ExecutionContextSerializer; import org.springframework.core.serializer.DefaultDeserializer; import org.springframework.core.serializer.DefaultSerializer; @@ -22,12 +28,6 @@ import org.springframework.core.serializer.Deserializer; import org.springframework.core.serializer.Serializer; import org.springframework.util.Assert; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.io.Serializable; -import java.util.Map; - /** * An implementation of the {@link ExecutionContextSerializer} using the default * serialization implementations from Spring ({@link DefaultSerializer} and @@ -56,7 +56,13 @@ public class DefaultExecutionContextSerializer implements ExecutionContextSerial Assert.notNull(out); for(Object value : context.values()) { - Assert.isInstanceOf(Serializable.class, value, "Value: [ " + value + "must be serializable."); + Assert.notNull(value); + if (!(value instanceof Serializable)) { + throw new IllegalArgumentException( + "Value: [ " + value + "must be serializable." + + "Object of class [" + value.getClass().getName() + + "] must be an instance of " + Serializable.class); + } } serializer.serialize(context, out); }