Change the condition for what is stored in AMQP object history for object reference logic (#1404)

This commit is contained in:
Rick Parker
2017-09-04 11:23:13 +01:00
committed by GitHub
parent 7ec5bd789e
commit f0b2b0a566
3 changed files with 8 additions and 4 deletions

View File

@ -142,7 +142,7 @@ class DeserializationInput(internal val serializerFactory: SerializerFactory) {
} }
// Store the reference in case we need it later on. // Store the reference in case we need it later on.
// Skip for primitive types as they are too small and overhead of referencing them will be much higher than their content // Skip for primitive types as they are too small and overhead of referencing them will be much higher than their content
if (suitableForObjectReference(type)) objectHistory.add(objectRead) if (suitableForObjectReference(objectRead.javaClass)) objectHistory.add(objectRead)
objectRead objectRead
} }

View File

@ -1,5 +1,6 @@
package net.corda.nodeapi.internal.serialization.amqp package net.corda.nodeapi.internal.serialization.amqp
import com.google.common.primitives.Primitives
import com.google.common.reflect.TypeToken import com.google.common.reflect.TypeToken
import org.apache.qpid.proton.codec.Data import org.apache.qpid.proton.codec.Data
import java.beans.IndexedPropertyDescriptor import java.beans.IndexedPropertyDescriptor
@ -221,5 +222,8 @@ internal fun Type.isSubClassOf(type: Type): Boolean {
return TypeToken.of(this).isSubtypeOf(type) return TypeToken.of(this).isSubtypeOf(type)
} }
internal fun suitableForObjectReference(type: Type) = // ByteArrays, primtives and boxed primitives are not stored in the object history
type != ByteArray::class.java && type.asClass()?.isPrimitive != true internal fun suitableForObjectReference(type: Type): Boolean {
val clazz = type.asClass()
return type != ByteArray::class.java && (clazz != null && !clazz.isPrimitive && !Primitives.unwrap(clazz).isPrimitive)
}

View File

@ -87,7 +87,7 @@ open class SerializationOutput(internal val serializerFactory: SerializerFactory
// Important to do it after serialization such that dependent object will have preceding reference numbers // Important to do it after serialization such that dependent object will have preceding reference numbers
// assigned to them first as they will be first read from the stream on receiving end. // assigned to them first as they will be first read from the stream on receiving end.
// Skip for primitive types as they are too small and overhead of referencing them will be much higher than their content // Skip for primitive types as they are too small and overhead of referencing them will be much higher than their content
if (suitableForObjectReference(type)) objectHistory.put(obj, objectHistory.size) if (suitableForObjectReference(obj.javaClass)) objectHistory.put(obj, objectHistory.size)
} }
else { else {
data.writeReferencedObject(ReferencedObject(retrievedRefCount)) data.writeReferencedObject(ReferencedObject(retrievedRefCount))