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
This commit is contained in:
committed by
Michael Minella
parent
2ec8183e39
commit
f78aa275c0
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user