mirror of
https://github.com/corda/corda.git
synced 2024-12-19 04:57:58 +00:00
Merge pull request #1129 from corda/kat-allowCarpenterToCarpentSeiliasedInstancesOfItself
Don't blindly add SimpleFieldAccess as interface to carpented classes
This commit is contained in:
commit
1f71a6aed2
@ -129,10 +129,12 @@ class ClassCarpenter {
|
|||||||
private fun generateClass(classSchema: Schema): Class<*> {
|
private fun generateClass(classSchema: Schema): Class<*> {
|
||||||
return generate(classSchema) { cw, schema ->
|
return generate(classSchema) { cw, schema ->
|
||||||
val superName = schema.superclass?.jvmName ?: "java/lang/Object"
|
val superName = schema.superclass?.jvmName ?: "java/lang/Object"
|
||||||
val interfaces = arrayOf(SimpleFieldAccess::class.java.name.jvm) + schema.interfaces.map { it.name.jvm }
|
var interfaces = schema.interfaces.map { it.name.jvm }.toMutableList()
|
||||||
|
|
||||||
|
if (SimpleFieldAccess::class.java !in schema.interfaces) interfaces.add(SimpleFieldAccess::class.java.name.jvm)
|
||||||
|
|
||||||
with(cw) {
|
with(cw) {
|
||||||
visit(V1_8, ACC_PUBLIC + ACC_SUPER, schema.jvmName, null, superName, interfaces)
|
visit(V1_8, ACC_PUBLIC + ACC_SUPER, schema.jvmName, null, superName, interfaces.toTypedArray())
|
||||||
|
|
||||||
generateFields(schema)
|
generateFields(schema)
|
||||||
generateConstructor(schema)
|
generateConstructor(schema)
|
||||||
@ -304,6 +306,11 @@ class ClassCarpenter {
|
|||||||
+ "with 'get': ${itf.name}.${it.name}")
|
+ "with 'get': ${itf.name}.${it.name}")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If we're trying to carpent a class that prior to serialisation / deserialisation
|
||||||
|
// was made by a carpenter then we can ignore this (it will implement a plain get
|
||||||
|
// method from SimpleFieldAccess).
|
||||||
|
if (fieldNameFromItf.isEmpty() && SimpleFieldAccess::class.java in schema.interfaces) return@forEach
|
||||||
|
|
||||||
if ((schema is ClassSchema) and (fieldNameFromItf !in allFields))
|
if ((schema is ClassSchema) and (fieldNameFromItf !in allFields))
|
||||||
throw InterfaceMismatchException(
|
throw InterfaceMismatchException(
|
||||||
"Interface ${itf.name} requires a field named $fieldNameFromItf but that "
|
"Interface ${itf.name} requires a field named $fieldNameFromItf but that "
|
||||||
|
Loading…
Reference in New Issue
Block a user