diff --git a/.ci/api-current.txt b/.ci/api-current.txt index 4c18baca85..91a2c644df 100644 --- a/.ci/api-current.txt +++ b/.ci/api-current.txt @@ -2822,27 +2822,27 @@ public final class net.corda.core.schemas.CommonSchemaV1 extends net.corda.core. @javax.persistence.MappedSuperclass @net.corda.core.serialization.CordaSerializable public static class net.corda.core.schemas.CommonSchemaV1$FungibleState extends net.corda.core.schemas.PersistentState public () public (Set, net.corda.core.identity.AbstractParty, long, net.corda.core.identity.AbstractParty, byte[]) - @org.jetbrains.annotations.NotNull public final net.corda.core.identity.AbstractParty getIssuer() - @org.jetbrains.annotations.NotNull public final byte[] getIssuerRef() - @org.jetbrains.annotations.NotNull public final net.corda.core.identity.AbstractParty getOwner() + @org.jetbrains.annotations.NotNull public net.corda.core.identity.AbstractParty getIssuer() + @org.jetbrains.annotations.NotNull public byte[] getIssuerRef() + @org.jetbrains.annotations.NotNull public net.corda.core.identity.AbstractParty getOwner() @org.jetbrains.annotations.Nullable public Set getParticipants() - public final long getQuantity() - public final void setIssuer(net.corda.core.identity.AbstractParty) - public final void setIssuerRef(byte[]) - public final void setOwner(net.corda.core.identity.AbstractParty) + public long getQuantity() + public void setIssuer(net.corda.core.identity.AbstractParty) + public void setIssuerRef(byte[]) + public void setOwner(net.corda.core.identity.AbstractParty) public void setParticipants(Set) - public final void setQuantity(long) + public void setQuantity(long) ## @javax.persistence.MappedSuperclass @net.corda.core.serialization.CordaSerializable public static class net.corda.core.schemas.CommonSchemaV1$LinearState extends net.corda.core.schemas.PersistentState public () public (Set, String, UUID) public (net.corda.core.contracts.UniqueIdentifier, Set) - @org.jetbrains.annotations.Nullable public final String getExternalId() + @org.jetbrains.annotations.Nullable public String getExternalId() @org.jetbrains.annotations.Nullable public Set getParticipants() - @org.jetbrains.annotations.NotNull public final UUID getUuid() - public final void setExternalId(String) + @org.jetbrains.annotations.NotNull public UUID getUuid() + public void setExternalId(String) public void setParticipants(Set) - public final void setUuid(UUID) + public void setUuid(UUID) ## public class net.corda.core.schemas.MappedSchema extends java.lang.Object public (Class, int, Iterable) @@ -2854,10 +2854,10 @@ public class net.corda.core.schemas.MappedSchema extends java.lang.Object @javax.persistence.MappedSuperclass @net.corda.core.serialization.CordaSerializable public class net.corda.core.schemas.PersistentState extends java.lang.Object implements net.corda.core.schemas.StatePersistable public () public (net.corda.core.schemas.PersistentStateRef) - @org.jetbrains.annotations.Nullable public final net.corda.core.schemas.PersistentStateRef getStateRef() - public final void setStateRef(net.corda.core.schemas.PersistentStateRef) + @org.jetbrains.annotations.Nullable public net.corda.core.schemas.PersistentStateRef getStateRef() + public void setStateRef(net.corda.core.schemas.PersistentStateRef) ## -@javax.persistence.Embeddable public final class net.corda.core.schemas.PersistentStateRef extends java.lang.Object implements java.io.Serializable +@javax.persistence.Embeddable public class net.corda.core.schemas.PersistentStateRef extends java.lang.Object implements java.io.Serializable public () public (String, Integer) public (net.corda.core.contracts.StateRef) @@ -2865,18 +2865,18 @@ public class net.corda.core.schemas.MappedSchema extends java.lang.Object @org.jetbrains.annotations.Nullable public final Integer component2() @org.jetbrains.annotations.NotNull public final net.corda.core.schemas.PersistentStateRef copy(String, Integer) public boolean equals(Object) - @org.jetbrains.annotations.Nullable public final Integer getIndex() - @org.jetbrains.annotations.Nullable public final String getTxId() + @org.jetbrains.annotations.Nullable public Integer getIndex() + @org.jetbrains.annotations.Nullable public String getTxId() public int hashCode() - public final void setIndex(Integer) - public final void setTxId(String) + public void setIndex(Integer) + public void setTxId(String) public String toString() ## @net.corda.core.serialization.CordaSerializable public interface net.corda.core.schemas.QueryableState extends net.corda.core.contracts.ContractState @org.jetbrains.annotations.NotNull public abstract net.corda.core.schemas.PersistentState generateMappedObject(net.corda.core.schemas.MappedSchema) @org.jetbrains.annotations.NotNull public abstract Iterable supportedSchemas() ## -public interface net.corda.core.schemas.StatePersistable +public interface net.corda.core.schemas.StatePersistable extends java.io.Serializable ## public interface net.corda.core.serialization.ClassWhitelist public abstract boolean hasListed(Class) diff --git a/build.gradle b/build.gradle index d6371a6bde..bec9c2586c 100644 --- a/build.gradle +++ b/build.gradle @@ -85,6 +85,7 @@ buildscript { } dependencies { classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" + classpath "org.jetbrains.kotlin:kotlin-allopen:$kotlin_version" classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.4' classpath "net.corda.plugins:publish-utils:$gradle_plugins_version" classpath "net.corda.plugins:quasar-utils:$gradle_plugins_version" @@ -133,6 +134,15 @@ allprojects { apply plugin: 'java' apply plugin: 'jacoco' apply plugin: 'org.owasp.dependencycheck' + apply plugin: 'kotlin-allopen' + + allOpen { + annotations( + "javax.persistence.Entity", + "javax.persistence.Embeddable", + "javax.persistence.MappedSuperclass" + ) + } dependencyCheck { suppressionFile = '.ci/dependency-checker/suppressedLibraries.xml' diff --git a/core/src/main/kotlin/net/corda/core/schemas/PersistentTypes.kt b/core/src/main/kotlin/net/corda/core/schemas/PersistentTypes.kt index cd55da4982..fbf9b3ccf9 100644 --- a/core/src/main/kotlin/net/corda/core/schemas/PersistentTypes.kt +++ b/core/src/main/kotlin/net/corda/core/schemas/PersistentTypes.kt @@ -69,4 +69,4 @@ data class PersistentStateRef( /** * Marker interface to denote a persistable Corda state entity that will always have a transaction id and index */ -interface StatePersistable \ No newline at end of file +interface StatePersistable : Serializable \ No newline at end of file diff --git a/node/src/main/kotlin/net/corda/node/internal/schemas/NodeInfoSchema.kt b/node/src/main/kotlin/net/corda/node/internal/schemas/NodeInfoSchema.kt index 4bf0bd16c4..3e0386b149 100644 --- a/node/src/main/kotlin/net/corda/node/internal/schemas/NodeInfoSchema.kt +++ b/node/src/main/kotlin/net/corda/node/internal/schemas/NodeInfoSchema.kt @@ -10,6 +10,7 @@ import net.corda.core.serialization.serialize import net.corda.core.utilities.MAX_HASH_HEX_SIZE import net.corda.core.utilities.NetworkHostAndPort import net.corda.node.services.persistence.NodePropertiesPersistentStore +import java.io.Serializable import javax.persistence.* object NodeInfoSchema @@ -52,7 +53,7 @@ object NodeInfoSchemaV1 : MappedSchema( */ @Column(name = "serial") val serial: Long - ) { + ) : Serializable { fun toNodeInfo(): NodeInfo { return NodeInfo( this.addresses.map { it.toHostAndPort() }, @@ -72,7 +73,7 @@ object NodeInfoSchemaV1 : MappedSchema( var id: Int, val host: String? = null, val port: Int? = null - ) { + ) : Serializable { companion object { fun fromHostAndPort(hostAndPort: NetworkHostAndPort) = DBHostAndPort( 0, hostAndPort.host, hostAndPort.port @@ -106,7 +107,7 @@ object NodeInfoSchemaV1 : MappedSchema( @ManyToMany(mappedBy = "legalIdentitiesAndCerts", cascade = arrayOf(CascadeType.ALL)) // ManyToMany because of distributed services. private val persistentNodeInfos: Set = emptySet() - ) { + ) : Serializable { constructor(partyAndCert: PartyAndCertificate, isMain: Boolean = false) : this(partyAndCert.name.toString(), partyAndCert.party.owningKey.toStringShort(), diff --git a/node/src/main/kotlin/net/corda/node/services/events/NodeSchedulerService.kt b/node/src/main/kotlin/net/corda/node/services/events/NodeSchedulerService.kt index fee41e219c..be5a44091a 100644 --- a/node/src/main/kotlin/net/corda/node/services/events/NodeSchedulerService.kt +++ b/node/src/main/kotlin/net/corda/node/services/events/NodeSchedulerService.kt @@ -31,6 +31,7 @@ import net.corda.nodeapi.internal.persistence.CordaPersistence import net.corda.nodeapi.internal.persistence.NODE_DATABASE_PREFIX import org.apache.activemq.artemis.utils.ReusableLatch import org.slf4j.Logger +import java.io.Serializable import java.time.Duration import java.time.Instant import java.util.* @@ -155,7 +156,7 @@ class NodeSchedulerService(private val clock: CordaClock, @Column(name = "scheduled_at", nullable = false) var scheduledAt: Instant = Instant.now() - ) + ) : Serializable private class InnerState { var scheduledStatesQueue: PriorityQueue = PriorityQueue({ a, b -> a.scheduledAt.compareTo(b.scheduledAt) }) diff --git a/node/src/main/kotlin/net/corda/node/services/identity/PersistentIdentityService.kt b/node/src/main/kotlin/net/corda/node/services/identity/PersistentIdentityService.kt index 9c77d45ded..a6fb506c86 100644 --- a/node/src/main/kotlin/net/corda/node/services/identity/PersistentIdentityService.kt +++ b/node/src/main/kotlin/net/corda/node/services/identity/PersistentIdentityService.kt @@ -16,6 +16,7 @@ import net.corda.nodeapi.internal.crypto.X509CertificateFactory import net.corda.nodeapi.internal.crypto.X509Utilities import net.corda.nodeapi.internal.crypto.x509Certificates import net.corda.nodeapi.internal.persistence.NODE_DATABASE_PREFIX +import java.io.Serializable import java.security.InvalidAlgorithmParameterException import java.security.PublicKey import java.security.cert.* @@ -74,7 +75,7 @@ class PersistentIdentityService(override val trustRoot: X509Certificate, @Lob @Column(name = "identity_value") var identity: ByteArray = ByteArray(0) - ) + ) : Serializable @Entity @javax.persistence.Table(name = "${NODE_DATABASE_PREFIX}named_identities") @@ -85,7 +86,7 @@ class PersistentIdentityService(override val trustRoot: X509Certificate, @Column(name = "pk_hash", length = MAX_HASH_HEX_SIZE) var publicKeyHash: String = "" - ) + ) : Serializable override val caCertStore: CertStore override val trustAnchor: TrustAnchor = TrustAnchor(trustRoot, null) diff --git a/node/src/main/kotlin/net/corda/node/services/keys/PersistentKeyManagementService.kt b/node/src/main/kotlin/net/corda/node/services/keys/PersistentKeyManagementService.kt index 96f41e9670..6249a01212 100644 --- a/node/src/main/kotlin/net/corda/node/services/keys/PersistentKeyManagementService.kt +++ b/node/src/main/kotlin/net/corda/node/services/keys/PersistentKeyManagementService.kt @@ -9,6 +9,7 @@ import net.corda.core.utilities.MAX_HASH_HEX_SIZE import net.corda.node.utilities.AppendOnlyPersistentMap import net.corda.nodeapi.internal.persistence.NODE_DATABASE_PREFIX import org.bouncycastle.operator.ContentSigner +import java.io.Serializable import java.security.KeyPair import java.security.PrivateKey import java.security.PublicKey @@ -42,7 +43,7 @@ class PersistentKeyManagementService(val identityService: IdentityService, @Lob @Column(name = "private_key") var privateKey: ByteArray = ByteArray(0) - ) { + ) : Serializable { constructor(publicKey: PublicKey, privateKey: PrivateKey) : this(publicKey.toStringShort(), publicKey.encoded, privateKey.encoded) } diff --git a/node/src/main/kotlin/net/corda/node/services/messaging/P2PMessagingClient.kt b/node/src/main/kotlin/net/corda/node/services/messaging/P2PMessagingClient.kt index b86751a102..a2c3c61717 100644 --- a/node/src/main/kotlin/net/corda/node/services/messaging/P2PMessagingClient.kt +++ b/node/src/main/kotlin/net/corda/node/services/messaging/P2PMessagingClient.kt @@ -43,6 +43,7 @@ import org.apache.activemq.artemis.api.core.client.* import rx.Observable import rx.Subscription import rx.subjects.PublishSubject +import java.io.Serializable import java.security.PublicKey import java.time.Instant import java.util.* @@ -195,7 +196,7 @@ class P2PMessagingClient(private val config: NodeConfiguration, @Column(name = "insertion_time") var insertionTime: Instant = Instant.now() - ) + ) : Serializable @Entity @javax.persistence.Table(name = "${NODE_DATABASE_PREFIX}message_retry") @@ -211,7 +212,7 @@ class P2PMessagingClient(private val config: NodeConfiguration, @Lob @Column var recipients: ByteArray = ByteArray(0) - ) + ) : Serializable fun start() { state.locked { diff --git a/node/src/main/kotlin/net/corda/node/services/persistence/DBCheckpointStorage.kt b/node/src/main/kotlin/net/corda/node/services/persistence/DBCheckpointStorage.kt index 5e92461c18..5c8b307bc0 100644 --- a/node/src/main/kotlin/net/corda/node/services/persistence/DBCheckpointStorage.kt +++ b/node/src/main/kotlin/net/corda/node/services/persistence/DBCheckpointStorage.kt @@ -5,6 +5,7 @@ import net.corda.node.services.api.Checkpoint import net.corda.node.services.api.CheckpointStorage import net.corda.nodeapi.internal.persistence.NODE_DATABASE_PREFIX import net.corda.nodeapi.internal.persistence.currentDBSession +import java.io.Serializable import javax.persistence.Column import javax.persistence.Entity import javax.persistence.Id @@ -25,7 +26,7 @@ class DBCheckpointStorage : CheckpointStorage { @Lob @Column(name = "checkpoint_value") var checkpoint: ByteArray = ByteArray(0) - ) + ) : Serializable override fun addCheckpoint(checkpoint: Checkpoint) { currentDBSession().save(DBCheckpoint().apply { diff --git a/node/src/main/kotlin/net/corda/node/services/persistence/DBTransactionMappingStorage.kt b/node/src/main/kotlin/net/corda/node/services/persistence/DBTransactionMappingStorage.kt index e81c6767f8..9e9137cf03 100644 --- a/node/src/main/kotlin/net/corda/node/services/persistence/DBTransactionMappingStorage.kt +++ b/node/src/main/kotlin/net/corda/node/services/persistence/DBTransactionMappingStorage.kt @@ -11,6 +11,7 @@ import net.corda.nodeapi.internal.persistence.NODE_DATABASE_PREFIX import net.corda.nodeapi.internal.persistence.bufferUntilDatabaseCommit import net.corda.nodeapi.internal.persistence.wrapWithDatabaseTransaction import rx.subjects.PublishSubject +import java.io.Serializable import java.util.* import javax.annotation.concurrent.ThreadSafe import javax.persistence.* @@ -33,7 +34,7 @@ class DBTransactionMappingStorage : StateMachineRecordedTransactionMappingStorag @Column(name = "state_machine_run_id", length = 36) var stateMachineRunId: String = "" - ) + ) : Serializable private companion object { fun createMap(): AppendOnlyPersistentMap { diff --git a/node/src/main/kotlin/net/corda/node/services/persistence/DBTransactionStorage.kt b/node/src/main/kotlin/net/corda/node/services/persistence/DBTransactionStorage.kt index 893579af03..880047f765 100644 --- a/node/src/main/kotlin/net/corda/node/services/persistence/DBTransactionStorage.kt +++ b/node/src/main/kotlin/net/corda/node/services/persistence/DBTransactionStorage.kt @@ -15,6 +15,7 @@ import net.corda.nodeapi.internal.persistence.bufferUntilDatabaseCommit import net.corda.nodeapi.internal.persistence.wrapWithDatabaseTransaction import rx.Observable import rx.subjects.PublishSubject +import java.io.Serializable import java.util.* import javax.persistence.* @@ -35,7 +36,7 @@ class DBTransactionStorage(cacheSizeBytes: Long) : WritableTransactionStorage, S @Lob @Column(name = "transaction_value") var transaction: ByteArray = ByteArray(0) - ) + ) : Serializable private companion object { fun createTransactionsMap(maxSizeInBytes: Long) diff --git a/node/src/main/kotlin/net/corda/node/services/persistence/NodePropertiesPersistentStore.kt b/node/src/main/kotlin/net/corda/node/services/persistence/NodePropertiesPersistentStore.kt index afa84c9f2a..28a6aaab95 100644 --- a/node/src/main/kotlin/net/corda/node/services/persistence/NodePropertiesPersistentStore.kt +++ b/node/src/main/kotlin/net/corda/node/services/persistence/NodePropertiesPersistentStore.kt @@ -9,6 +9,7 @@ import net.corda.nodeapi.internal.persistence.CordaPersistence import net.corda.nodeapi.internal.persistence.NODE_DATABASE_PREFIX import org.slf4j.Logger import rx.subjects.PublishSubject +import java.io.Serializable import javax.persistence.Column import javax.persistence.Entity import javax.persistence.Id @@ -34,7 +35,7 @@ class NodePropertiesPersistentStore(readPhysicalNodeId: () -> String, persistenc @Column(name = "property_value") var value: String? = "" - ) + ) : Serializable } private class FlowsDrainingModeOperationsImpl(readPhysicalNodeId: () -> String, private val persistence: CordaPersistence, logger: Logger) : FlowsDrainingModeOperations { diff --git a/node/src/main/kotlin/net/corda/node/services/transactions/PersistentUniquenessProvider.kt b/node/src/main/kotlin/net/corda/node/services/transactions/PersistentUniquenessProvider.kt index 886baaec93..7fd3bf01a9 100644 --- a/node/src/main/kotlin/net/corda/node/services/transactions/PersistentUniquenessProvider.kt +++ b/node/src/main/kotlin/net/corda/node/services/transactions/PersistentUniquenessProvider.kt @@ -39,7 +39,7 @@ class PersistentUniquenessProvider : UniquenessProvider, SingletonSerializeAsTok @Embedded var party: PersistentParty = PersistentParty() - ) + ) : Serializable @Embeddable data class PersistentParty( diff --git a/node/src/main/kotlin/net/corda/node/services/transactions/RaftUniquenessProvider.kt b/node/src/main/kotlin/net/corda/node/services/transactions/RaftUniquenessProvider.kt index 4ecd3b572a..8a659e7621 100644 --- a/node/src/main/kotlin/net/corda/node/services/transactions/RaftUniquenessProvider.kt +++ b/node/src/main/kotlin/net/corda/node/services/transactions/RaftUniquenessProvider.kt @@ -36,6 +36,7 @@ import net.corda.nodeapi.internal.config.NodeSSLConfiguration import net.corda.nodeapi.internal.config.SSLConfiguration import net.corda.nodeapi.internal.persistence.CordaPersistence import net.corda.nodeapi.internal.persistence.NODE_DATABASE_PREFIX +import java.io.Serializable import java.nio.file.Path import java.util.concurrent.CompletableFuture import javax.annotation.concurrent.ThreadSafe @@ -83,7 +84,7 @@ class RaftUniquenessProvider(private val transportConfiguration: NodeSSLConfigur @Column(name = "state_index") var index: Long = 0 - ) + ) : Serializable /** Directory storing the Raft log and state machine snapshots */ private val storagePath: Path = transportConfiguration.baseDirectory diff --git a/node/src/main/kotlin/net/corda/node/services/upgrade/ContractUpgradeServiceImpl.kt b/node/src/main/kotlin/net/corda/node/services/upgrade/ContractUpgradeServiceImpl.kt index 162d8d945b..68f0854770 100644 --- a/node/src/main/kotlin/net/corda/node/services/upgrade/ContractUpgradeServiceImpl.kt +++ b/node/src/main/kotlin/net/corda/node/services/upgrade/ContractUpgradeServiceImpl.kt @@ -6,6 +6,7 @@ import net.corda.core.node.services.ContractUpgradeService import net.corda.core.serialization.SingletonSerializeAsToken import net.corda.nodeapi.internal.persistence.NODE_DATABASE_PREFIX import net.corda.node.utilities.PersistentMap +import java.io.Serializable import javax.persistence.Column import javax.persistence.Entity import javax.persistence.Id @@ -23,7 +24,7 @@ class ContractUpgradeServiceImpl : ContractUpgradeService, SingletonSerializeAsT /** refers to the UpgradedContract class name*/ @Column(name = "contract_class_name") var upgradedContractClassName: String = "" - ) + ) : Serializable private companion object { fun createContractUpgradesMap(): PersistentMap { diff --git a/node/src/test/kotlin/net/corda/node/services/schema/NodeSchemaServiceTest.kt b/node/src/test/kotlin/net/corda/node/services/schema/NodeSchemaServiceTest.kt index a14cd60e5c..92493f0616 100644 --- a/node/src/test/kotlin/net/corda/node/services/schema/NodeSchemaServiceTest.kt +++ b/node/src/test/kotlin/net/corda/node/services/schema/NodeSchemaServiceTest.kt @@ -20,6 +20,7 @@ import org.hibernate.annotations.Cascade import org.hibernate.annotations.CascadeType import org.junit.Ignore import org.junit.Test +import java.io.Serializable import javax.persistence.* import kotlin.test.assertEquals import kotlin.test.assertFalse @@ -141,12 +142,13 @@ object TestSchema : MappedSchema(SchemaFamily::class.java, 1, setOf(Parent::clas @Suppress("unused") @Entity @Table(name = "Children") - class Child { + class Child : Serializable { @Id @GeneratedValue @Column(name = "child_id", unique = true, nullable = false) var childId: Int? = null + @ManyToOne(fetch = FetchType.LAZY) @JoinColumns(JoinColumn(name = "transaction_id", referencedColumnName = "transaction_id"), JoinColumn(name = "output_index", referencedColumnName = "output_index")) var parent: Parent? = null