diff --git a/.ci/dev/pr-code-checks/Jenkinsfile b/.ci/dev/pr-code-checks/Jenkinsfile index 5e7085cc1f..c2b238e1b8 100644 --- a/.ci/dev/pr-code-checks/Jenkinsfile +++ b/.ci/dev/pr-code-checks/Jenkinsfile @@ -34,10 +34,7 @@ pipeline { stage('Compilation warnings check') { steps { - /* - * TODO JDK17: Re-enable warnings as errors - */ - sh "./gradlew --no-daemon -Pcompilation.warningsAsErrors=false compileAll" + sh "./gradlew --no-daemon -Pcompilation.warningsAsErrors=true compileAll" } } diff --git a/core/src/main/kotlin/net/corda/core/crypto/CompositeKey.kt b/core/src/main/kotlin/net/corda/core/crypto/CompositeKey.kt index e968257931..dfa5da1998 100644 --- a/core/src/main/kotlin/net/corda/core/crypto/CompositeKey.kt +++ b/core/src/main/kotlin/net/corda/core/crypto/CompositeKey.kt @@ -14,7 +14,7 @@ import org.bouncycastle.asn1.DERSequence import org.bouncycastle.asn1.x509.AlgorithmIdentifier import org.bouncycastle.asn1.x509.SubjectPublicKeyInfo import java.security.PublicKey -import java.util.* +import java.util.IdentityHashMap /** * A tree data structure that enables the representation of composite public keys, which are used to represent @@ -50,8 +50,7 @@ class CompositeKey private constructor(val threshold: Int, children: List - require(childAsn1 is ASN1Sequence) { "Child key is not in ASN1 format" } - val childSeq = childAsn1 as ASN1Sequence + val childSeq = requireNotNull(childAsn1 as? ASN1Sequence) { "Child key is not in ASN1 format" } val key = Crypto.decodePublicKey((childSeq.getObjectAt(0) as DERBitString).bytes) val weight = ASN1Integer.getInstance(childSeq.getObjectAt(1)) builder.addKey(key, weight.positiveValue.toInt()) @@ -278,7 +277,7 @@ class CompositeKey private constructor(val threshold: Int, children: List 0) { "Threshold must not be specified or its value must be greater than zero" } val n = children.size return when { - n > 1 -> CompositeKey(threshold ?: children.map { (_, weight) -> weight }.sum(), children) + n > 1 -> CompositeKey(threshold ?: children.sumOf { (_, weight) -> weight }, children) n == 1 -> { require(threshold == null || threshold == children.first().weight) { "Trying to build invalid CompositeKey, threshold value different than weight of single child node." } diff --git a/core/src/main/kotlin/net/corda/core/internal/utilities/PrivateInterner.kt b/core/src/main/kotlin/net/corda/core/internal/utilities/PrivateInterner.kt index 8fbe92f4f9..5407ca4560 100644 --- a/core/src/main/kotlin/net/corda/core/internal/utilities/PrivateInterner.kt +++ b/core/src/main/kotlin/net/corda/core/internal/utilities/PrivateInterner.kt @@ -38,20 +38,20 @@ class PrivateInterner(val verifier: IternabilityVerifier = AlwaysInternabl } fun isSerializableCore(clazz: Class<*>): Boolean { - if (!(clazz.packageNameOrNull?.startsWith("net.corda.core") ?: false)) return false + if (clazz.packageNameOrNull?.startsWith("net.corda.core") != true) return false return hasCordaSerializable(clazz) } fun findInterner(clazz: Class<*>?): PrivateInterner? { // Kotlin reflection has a habit of throwing exceptions, so protect just in case. - try { - return clazz?.kotlin?.companionObjectInstance?.let { + return try { + clazz?.kotlin?.companionObjectInstance?.let { (it as? Internable<*>)?.let { uncheckedCast(it.interner) } } } catch (_: Throwable) { - return null + null } } return if (clazz != null) { @@ -64,6 +64,6 @@ class PrivateInterner(val verifier: IternabilityVerifier = AlwaysInternabl private val interner = Interners.newBuilder().weak().concurrencyLevel(CONCURRENCY_LEVEL).build() - fun intern(sample: S): S = if (DISABLE) sample else uncheckedCast(verifier.choose(sample, interner.intern(sample))) + fun intern(sample: S): S = if (DISABLE) sample else uncheckedCast(verifier.choose(sample, interner.intern(sample!!))) } diff --git a/core/src/main/kotlin/net/corda/core/internal/verification/Verifier.kt b/core/src/main/kotlin/net/corda/core/internal/verification/Verifier.kt index 5ca243260d..ab448bd0b0 100644 --- a/core/src/main/kotlin/net/corda/core/internal/verification/Verifier.kt +++ b/core/src/main/kotlin/net/corda/core/internal/verification/Verifier.kt @@ -469,6 +469,7 @@ class TransactionVerifier(private val transactionClassLoader: ClassLoader) : Fun } override fun apply(transactionFactory: Supplier) { + @Suppress("VARIABLE_WITH_REDUNDANT_INITIALIZER") // Because the external verifier uses Kotlin 1.2 var firstLtx: LedgerTransaction? = null transactionFactory.get().let { ltx -> diff --git a/core/src/test/kotlin/net/corda/core/contracts/StructuresTests.kt b/core/src/test/kotlin/net/corda/core/contracts/StructuresTests.kt index f8ba9772ae..c6b4f20317 100644 --- a/core/src/test/kotlin/net/corda/core/contracts/StructuresTests.kt +++ b/core/src/test/kotlin/net/corda/core/contracts/StructuresTests.kt @@ -34,6 +34,7 @@ class AttachmentTest { override val id get() = throw UnsupportedOperationException() override fun open() = inputStream override val signerKeys get() = throw UnsupportedOperationException() + @Suppress("OVERRIDE_DEPRECATION") override val signers: List get() = throw UnsupportedOperationException() override val size: Int = 512 } diff --git a/experimental/src/main/kotlin/net/corda/finance/contracts/universal/PrettyPrint.kt b/experimental/src/main/kotlin/net/corda/finance/contracts/universal/PrettyPrint.kt index 65a63c5a81..3ed9dd1862 100644 --- a/experimental/src/main/kotlin/net/corda/finance/contracts/universal/PrettyPrint.kt +++ b/experimental/src/main/kotlin/net/corda/finance/contracts/universal/PrettyPrint.kt @@ -25,7 +25,7 @@ private class PrettyPrint(arr : Arrangement) { private fun println(message: Any?) { if (atStart) repeat(indentLevel) { sb.append(' ') } - sb.appendln(message) + sb.appendLine(message) atStart = true } diff --git a/experimental/src/main/kotlin/net/corda/finance/contracts/universal/UniversalContract.kt b/experimental/src/main/kotlin/net/corda/finance/contracts/universal/UniversalContract.kt index 7ca5abee0d..0c235766e8 100644 --- a/experimental/src/main/kotlin/net/corda/finance/contracts/universal/UniversalContract.kt +++ b/experimental/src/main/kotlin/net/corda/finance/contracts/universal/UniversalContract.kt @@ -1,6 +1,12 @@ package net.corda.finance.contracts.universal -import net.corda.core.contracts.* +import net.corda.core.contracts.CommandData +import net.corda.core.contracts.Contract +import net.corda.core.contracts.ContractState +import net.corda.core.contracts.PartyAndReference +import net.corda.core.contracts.TypeOnlyCommandData +import net.corda.core.contracts.requireSingleCommand +import net.corda.core.contracts.requireThat import net.corda.core.identity.AbstractParty import net.corda.core.identity.Party import net.corda.core.internal.uncheckedCast @@ -182,7 +188,7 @@ class UniversalContract : Contract { "transaction has a single command".using(tx.commands.size == 1) } - val cmd = tx.commands.requireSingleCommand() + val cmd = tx.commands.requireSingleCommand() val value = cmd.value @@ -275,13 +281,14 @@ class UniversalContract : Contract { } } + @Suppress("UNCHECKED_CAST") fun replaceFixing(tx: LedgerTransaction, perceivable: Perceivable, fixings: Map, unusedFixings: MutableSet): Perceivable = when (perceivable) { is Const -> perceivable is UnaryPlus -> UnaryPlus(replaceFixing(tx, perceivable.arg, fixings, unusedFixings)) is PerceivableOperation -> PerceivableOperation(replaceFixing(tx, perceivable.left, fixings, unusedFixings), - perceivable.op, replaceFixing(tx, perceivable.right, fixings, unusedFixings)) as Perceivable + perceivable.op, replaceFixing(tx, perceivable.right, fixings, unusedFixings)) is Interest -> Interest(replaceFixing(tx, perceivable.amount, fixings, unusedFixings), perceivable.dayCountConvention, replaceFixing(tx, perceivable.interest, fixings, unusedFixings), perceivable.start, perceivable.end) as Perceivable diff --git a/experimental/src/test/kotlin/net/corda/finance/contracts/universal/ContractDefinition.kt b/experimental/src/test/kotlin/net/corda/finance/contracts/universal/ContractDefinition.kt index 4db963a9f6..019485ca6c 100644 --- a/experimental/src/test/kotlin/net/corda/finance/contracts/universal/ContractDefinition.kt +++ b/experimental/src/test/kotlin/net/corda/finance/contracts/universal/ContractDefinition.kt @@ -4,7 +4,7 @@ import net.corda.core.crypto.generateKeyPair import net.corda.core.identity.CordaX500Name import net.corda.testing.core.TestIdentity import org.junit.Test -import java.util.* +import java.util.Currency import kotlin.test.assertEquals import kotlin.test.assertTrue @@ -118,8 +118,6 @@ class ContractDefinition { assertTrue(arr is Actions) - if (arr is Actions) { - assertEquals(1, arr.actions.size) - } + assertEquals(1, arr.actions.size) } } diff --git a/finance/workflows/src/main/kotlin/net/corda/finance/workflows/asset/selection/AbstractCashSelection.kt b/finance/workflows/src/main/kotlin/net/corda/finance/workflows/asset/selection/AbstractCashSelection.kt index 77ba1fcf98..7e46dde20d 100644 --- a/finance/workflows/src/main/kotlin/net/corda/finance/workflows/asset/selection/AbstractCashSelection.kt +++ b/finance/workflows/src/main/kotlin/net/corda/finance/workflows/asset/selection/AbstractCashSelection.kt @@ -10,12 +10,18 @@ import net.corda.core.identity.AbstractParty import net.corda.core.identity.Party import net.corda.core.node.ServiceHub import net.corda.core.node.services.StatesNotAvailableException -import net.corda.core.utilities.* +import net.corda.core.utilities.OpaqueBytes +import net.corda.core.utilities.contextLogger +import net.corda.core.utilities.millis +import net.corda.core.utilities.toNonEmptySet +import net.corda.core.utilities.trace import net.corda.finance.contracts.asset.Cash import java.sql.Connection import java.sql.DatabaseMetaData import java.sql.ResultSet -import java.util.* +import java.util.Currency +import java.util.ServiceLoader +import java.util.UUID import java.util.concurrent.atomic.AtomicReference /** @@ -30,8 +36,8 @@ abstract class AbstractCashSelection(private val maxRetries : Int = 8, private v companion object { val instance = AtomicReference() - fun getInstance(metadata: () -> java.sql.DatabaseMetaData): AbstractCashSelection { - return instance.get() ?: { + fun getInstance(metadata: () -> DatabaseMetaData): AbstractCashSelection { + return instance.get() ?: run { val metadataLocal = metadata() val cashSelectionAlgos = ServiceLoader.load(AbstractCashSelection::class.java, this::class.java.classLoader).toList() val cashSelectionAlgo = cashSelectionAlgos.firstOrNull { it.isCompatible(metadataLocal) } @@ -41,7 +47,7 @@ abstract class AbstractCashSelection(private val maxRetries : Int = 8, private v } ?: throw ClassNotFoundException("\nUnable to load compatible cash selection algorithm implementation for JDBC driver name '${metadataLocal.driverName}'." + "\nPlease specify an implementation in META-INF/services/${AbstractCashSelection::class.qualifiedName}." + "\nAvailable implementations: $cashSelectionAlgos") - }.invoke() + } } private val log = contextLogger() @@ -139,19 +145,19 @@ abstract class AbstractCashSelection(private val maxRetries : Int = 8, private v if (stateRefs.isNotEmpty()) { // TODO: future implementation to retrieve contract states from a Vault BLOB store @Suppress("UNCHECKED_CAST") - stateAndRefs.addAll(services.loadStates(stateRefs) as Collection>) + stateAndRefs.addAll(services.loadStates(stateRefs) as Collection>) } val success = stateAndRefs.isNotEmpty() && totalPennies >= amount.quantity if (success) { // we should have a minimum number of states to satisfy our selection `amount` criteria - log.trace("Coin selection for $amount retrieved ${stateAndRefs.count()} states totalling $totalPennies pennies: $stateAndRefs") + log.trace { "Coin selection for $amount retrieved ${stateAndRefs.count()} states totalling $totalPennies pennies: $stateAndRefs" } // With the current single threaded state machine available states are guaranteed to lock. // TODO However, we will have to revisit these methods in the future multi-threaded. services.vaultService.softLockReserve(lockId, (stateAndRefs.map { it.ref }).toNonEmptySet()) } else { - log.trace("Coin selection requested $amount but retrieved $totalPennies pennies with state refs: ${stateAndRefs.map { it.ref }}") + log.trace { "Coin selection requested $amount but retrieved $totalPennies pennies with state refs: ${stateAndRefs.map { it.ref }}" } } success } diff --git a/node-api/src/main/kotlin/net/corda/nodeapi/internal/telemetry/OpenTelemetryComponent.kt b/node-api/src/main/kotlin/net/corda/nodeapi/internal/telemetry/OpenTelemetryComponent.kt index 73595dd460..ee20c3a977 100644 --- a/node-api/src/main/kotlin/net/corda/nodeapi/internal/telemetry/OpenTelemetryComponent.kt +++ b/node-api/src/main/kotlin/net/corda/nodeapi/internal/telemetry/OpenTelemetryComponent.kt @@ -98,15 +98,15 @@ class OpenTelemetryComponent(serviceName: String, val spanStartEndEventsEnabled: } private fun extractContext(carrier: ContextCarrier): Context { - val getter = object : TextMapGetter { + val getter = object : TextMapGetter { override fun get(carrier: ContextCarrier?, key: String): String? { return if (carrier?.context?.containsKey(key) == true) { val value = carrier.context[key] value } else null } - override fun keys(carrier: ContextCarrier?): MutableIterable { - return carrier?.context?.keys ?: mutableListOf() + override fun keys(carrier: ContextCarrier): MutableIterable { + return carrier.context.keys } } return carrier.let { diff --git a/node/src/main/kotlin/net/corda/node/services/messaging/NodeSSLContextFactory.kt b/node/src/main/kotlin/net/corda/node/services/messaging/NodeSSLContextFactory.kt index 9b3fa85241..e2c49e8b83 100644 --- a/node/src/main/kotlin/net/corda/node/services/messaging/NodeSSLContextFactory.kt +++ b/node/src/main/kotlin/net/corda/node/services/messaging/NodeSSLContextFactory.kt @@ -7,15 +7,14 @@ import net.corda.nodeapi.internal.ArtemisTcpTransport.Companion.TRUST_MANAGER_FA import net.corda.nodeapi.internal.protonwrapper.netty.createAndInitSslContext import org.apache.activemq.artemis.core.remoting.impl.ssl.DefaultOpenSSLContextFactory import org.apache.activemq.artemis.core.remoting.impl.ssl.DefaultSSLContextFactory +import org.apache.activemq.artemis.core.remoting.impl.ssl.SSLSupport import org.apache.activemq.artemis.spi.core.remoting.ssl.SSLContextConfig import org.apache.activemq.artemis.utils.ClassloadingUtil import java.io.File import java.io.InputStream import java.net.MalformedURLException import java.net.URL -import java.security.AccessController import java.security.KeyStore -import java.security.PrivilegedAction import javax.net.ssl.KeyManagerFactory import javax.net.ssl.SSLContext import javax.net.ssl.TrustManagerFactory @@ -79,7 +78,7 @@ private fun loadKeystore( val keyStore = keystoreProvider?.let { KeyStore.getInstance(keystoreType, it) } ?: KeyStore.getInstance(keystoreType) var inputStream : InputStream? = null try { - if (keystorePath != null && keystorePath.isNotEmpty()) { + if (!keystorePath.isNullOrEmpty()) { val keystoreURL = validateStoreURL(keystorePath) inputStream = keystoreURL.openStream() } @@ -103,23 +102,11 @@ private fun validateStoreURL(storePath: String): URL { if (file.exists() && file.isFile) { file.toURI().toURL() } else { - findResource(storePath) + ClassloadingUtil.findResource(storePath) } } } - -/** - * This is a copy of [SSLSupport.findResource] so we can have a full copy of - * [SSLSupport.validateStoreURL] and. - */ -private fun findResource(resourceName: String): URL { - return AccessController.doPrivileged(PrivilegedAction { - ClassloadingUtil.findResource(resourceName) - }) -} - - /** * This is an inline function for [InputStream] so it can be closed and * ignore an exception. @@ -132,4 +119,3 @@ private fun InputStream?.closeQuietly() { // quietly absorb problems } } - diff --git a/serialization/src/main/kotlin/net/corda/serialization/internal/AllButBlacklisted.kt b/serialization/src/main/kotlin/net/corda/serialization/internal/AllButBlacklisted.kt index f620422149..6ca60cce89 100644 --- a/serialization/src/main/kotlin/net/corda/serialization/internal/AllButBlacklisted.kt +++ b/serialization/src/main/kotlin/net/corda/serialization/internal/AllButBlacklisted.kt @@ -11,7 +11,6 @@ import java.net.DatagramSocket import java.net.ServerSocket import java.net.Socket import java.net.URLConnection -import java.security.AccessController import java.security.KeyStore import java.security.Permission import java.security.Provider @@ -30,7 +29,7 @@ import kotlin.collections.LinkedHashSet * Inheritance works for blacklisted items, but one can specifically exclude classes from blacklisting as well. * Note: Custom serializer registration trumps white/black lists. So if a given type has a custom serializer and has its name * in the blacklist - it will still be serialized as specified by custom serializer. - * For more details, see [net.corda.serialization.internal.CordaClassResolver.getRegistration] + * For more details, see [net.corda.nodeapi.internal.serialization.kryo.CordaClassResolver.getRegistration] */ object AllButBlacklisted : ClassWhitelist { @@ -56,7 +55,6 @@ object AllButBlacklisted : ClassWhitelist { // java.security. KeyStore::class.java.name, - AccessController::class.java.name, Permission::class.java.name, // java.net. diff --git a/serialization/src/main/kotlin/net/corda/serialization/internal/SerializationScheme.kt b/serialization/src/main/kotlin/net/corda/serialization/internal/SerializationScheme.kt index 2ec5e8d9b8..45ed28ac32 100644 --- a/serialization/src/main/kotlin/net/corda/serialization/internal/SerializationScheme.kt +++ b/serialization/src/main/kotlin/net/corda/serialization/internal/SerializationScheme.kt @@ -37,7 +37,7 @@ data class SerializationContextImpl @JvmOverloads constructor(override val prefe /** * {@inheritDoc} */ - @Suppress("OverridingDeprecatedMember") + @Suppress("OVERRIDE_DEPRECATION") override fun withAttachmentsClassLoader(attachmentHashes: List): SerializationContext { return this } diff --git a/serialization/src/main/kotlin/net/corda/serialization/internal/carpenter/ClassCarpenter.kt b/serialization/src/main/kotlin/net/corda/serialization/internal/carpenter/ClassCarpenter.kt index 854ab89eb8..4a3373775b 100644 --- a/serialization/src/main/kotlin/net/corda/serialization/internal/carpenter/ClassCarpenter.kt +++ b/serialization/src/main/kotlin/net/corda/serialization/internal/carpenter/ClassCarpenter.kt @@ -31,10 +31,6 @@ class CarpenterClassLoader(private val parentClassLoader: ClassLoader = Thread.c @Throws(ClassNotFoundException::class) override fun loadClass(name: String?, resolve: Boolean): Class<*>? { return synchronized(getClassLoadingLock(name)) { - /** - * Search parent classloaders using lock-less [Class.forName], - * bypassing [parent] to avoid its [SecurityManager] overhead. - */ (findLoadedClass(name) ?: Class.forName(name, false, parentClassLoader)).also { clazz -> if (resolve) { resolveClass(clazz) @@ -294,7 +290,7 @@ class ClassCarpenterImpl @JvmOverloads constructor (override val whitelist: Clas visitFieldInsn(GETFIELD, schema.jvmName, name, type.descriptor) when (type.field) { java.lang.Boolean.TYPE, Integer.TYPE, java.lang.Short.TYPE, java.lang.Byte.TYPE, - java.lang.Character.TYPE -> visitInsn(IRETURN) + Character.TYPE -> visitInsn(IRETURN) java.lang.Long.TYPE -> visitInsn(LRETURN) java.lang.Double.TYPE -> visitInsn(DRETURN) java.lang.Float.TYPE -> visitInsn(FRETURN) @@ -423,7 +419,7 @@ class ClassCarpenterImpl @JvmOverloads constructor (override val whitelist: Clas private fun MethodVisitor.load(slot: Int, type: Field): Int { when (type.field) { java.lang.Boolean.TYPE, Integer.TYPE, java.lang.Short.TYPE, java.lang.Byte.TYPE, - java.lang.Character.TYPE -> visitVarInsn(ILOAD, slot) + Character.TYPE -> visitVarInsn(ILOAD, slot) java.lang.Long.TYPE -> visitVarInsn(LLOAD, slot) java.lang.Double.TYPE -> visitVarInsn(DLOAD, slot) java.lang.Float.TYPE -> visitVarInsn(FLOAD, slot)