ENT-11717: Re-enable warnings as errors on Jenkins

This commit is contained in:
Shams Asari 2024-03-27 11:20:28 +00:00
parent a400b210be
commit d576588676
14 changed files with 48 additions and 59 deletions

View File

@ -34,10 +34,7 @@ pipeline {
stage('Compilation warnings check') { stage('Compilation warnings check') {
steps { steps {
/* sh "./gradlew --no-daemon -Pcompilation.warningsAsErrors=true compileAll"
* TODO JDK17: Re-enable warnings as errors
*/
sh "./gradlew --no-daemon -Pcompilation.warningsAsErrors=false compileAll"
} }
} }

View File

@ -14,7 +14,7 @@ import org.bouncycastle.asn1.DERSequence
import org.bouncycastle.asn1.x509.AlgorithmIdentifier import org.bouncycastle.asn1.x509.AlgorithmIdentifier
import org.bouncycastle.asn1.x509.SubjectPublicKeyInfo import org.bouncycastle.asn1.x509.SubjectPublicKeyInfo
import java.security.PublicKey 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 * 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<NodeAn
val builder = Builder() val builder = Builder()
val listOfChildren = sequenceOfChildren.objects.toList() val listOfChildren = sequenceOfChildren.objects.toList()
listOfChildren.forEach { childAsn1 -> listOfChildren.forEach { childAsn1 ->
require(childAsn1 is ASN1Sequence) { "Child key is not in ASN1 format" } val childSeq = requireNotNull(childAsn1 as? ASN1Sequence) { "Child key is not in ASN1 format" }
val childSeq = childAsn1 as ASN1Sequence
val key = Crypto.decodePublicKey((childSeq.getObjectAt(0) as DERBitString).bytes) val key = Crypto.decodePublicKey((childSeq.getObjectAt(0) as DERBitString).bytes)
val weight = ASN1Integer.getInstance(childSeq.getObjectAt(1)) val weight = ASN1Integer.getInstance(childSeq.getObjectAt(1))
builder.addKey(key, weight.positiveValue.toInt()) builder.addKey(key, weight.positiveValue.toInt())
@ -278,7 +277,7 @@ class CompositeKey private constructor(val threshold: Int, children: List<NodeAn
require(threshold == null || threshold > 0) { "Threshold must not be specified or its value must be greater than zero" } require(threshold == null || threshold > 0) { "Threshold must not be specified or its value must be greater than zero" }
val n = children.size val n = children.size
return when { return when {
n > 1 -> CompositeKey(threshold ?: children.map { (_, weight) -> weight }.sum(), children) n > 1 -> CompositeKey(threshold ?: children.sumOf { (_, weight) -> weight }, children)
n == 1 -> { n == 1 -> {
require(threshold == null || threshold == children.first().weight) require(threshold == null || threshold == children.first().weight)
{ "Trying to build invalid CompositeKey, threshold value different than weight of single child node." } { "Trying to build invalid CompositeKey, threshold value different than weight of single child node." }

View File

@ -38,20 +38,20 @@ class PrivateInterner<T>(val verifier: IternabilityVerifier<T> = AlwaysInternabl
} }
fun isSerializableCore(clazz: Class<*>): Boolean { 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) return hasCordaSerializable(clazz)
} }
fun findInterner(clazz: Class<*>?): PrivateInterner<Any>? { fun findInterner(clazz: Class<*>?): PrivateInterner<Any>? {
// Kotlin reflection has a habit of throwing exceptions, so protect just in case. // Kotlin reflection has a habit of throwing exceptions, so protect just in case.
try { return try {
return clazz?.kotlin?.companionObjectInstance?.let { clazz?.kotlin?.companionObjectInstance?.let {
(it as? Internable<*>)?.let { (it as? Internable<*>)?.let {
uncheckedCast(it.interner) uncheckedCast(it.interner)
} }
} }
} catch (_: Throwable) { } catch (_: Throwable) {
return null null
} }
} }
return if (clazz != null) { return if (clazz != null) {
@ -64,6 +64,6 @@ class PrivateInterner<T>(val verifier: IternabilityVerifier<T> = AlwaysInternabl
private val interner = Interners.newBuilder().weak().concurrencyLevel(CONCURRENCY_LEVEL).build<T>() private val interner = Interners.newBuilder().weak().concurrencyLevel(CONCURRENCY_LEVEL).build<T>()
fun <S : T> intern(sample: S): S = if (DISABLE) sample else uncheckedCast(verifier.choose(sample, interner.intern(sample))) fun <S : T> intern(sample: S): S = if (DISABLE) sample else uncheckedCast(verifier.choose(sample, interner.intern(sample!!)))
} }

View File

@ -469,6 +469,7 @@ class TransactionVerifier(private val transactionClassLoader: ClassLoader) : Fun
} }
override fun apply(transactionFactory: Supplier<LedgerTransaction>) { override fun apply(transactionFactory: Supplier<LedgerTransaction>) {
@Suppress("VARIABLE_WITH_REDUNDANT_INITIALIZER") // Because the external verifier uses Kotlin 1.2
var firstLtx: LedgerTransaction? = null var firstLtx: LedgerTransaction? = null
transactionFactory.get().let { ltx -> transactionFactory.get().let { ltx ->

View File

@ -34,6 +34,7 @@ class AttachmentTest {
override val id get() = throw UnsupportedOperationException() override val id get() = throw UnsupportedOperationException()
override fun open() = inputStream override fun open() = inputStream
override val signerKeys get() = throw UnsupportedOperationException() override val signerKeys get() = throw UnsupportedOperationException()
@Suppress("OVERRIDE_DEPRECATION")
override val signers: List<Party> get() = throw UnsupportedOperationException() override val signers: List<Party> get() = throw UnsupportedOperationException()
override val size: Int = 512 override val size: Int = 512
} }

View File

@ -25,7 +25,7 @@ private class PrettyPrint(arr : Arrangement) {
private fun println(message: Any?) { private fun println(message: Any?) {
if (atStart) if (atStart)
repeat(indentLevel) { sb.append(' ') } repeat(indentLevel) { sb.append(' ') }
sb.appendln(message) sb.appendLine(message)
atStart = true atStart = true
} }

View File

@ -1,6 +1,12 @@
package net.corda.finance.contracts.universal 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.AbstractParty
import net.corda.core.identity.Party import net.corda.core.identity.Party
import net.corda.core.internal.uncheckedCast import net.corda.core.internal.uncheckedCast
@ -182,7 +188,7 @@ class UniversalContract : Contract {
"transaction has a single command".using(tx.commands.size == 1) "transaction has a single command".using(tx.commands.size == 1)
} }
val cmd = tx.commands.requireSingleCommand<UniversalContract.Commands>() val cmd = tx.commands.requireSingleCommand<Commands>()
val value = cmd.value val value = cmd.value
@ -275,13 +281,14 @@ class UniversalContract : Contract {
} }
} }
@Suppress("UNCHECKED_CAST")
fun <T> replaceFixing(tx: LedgerTransaction, perceivable: Perceivable<T>, fun <T> replaceFixing(tx: LedgerTransaction, perceivable: Perceivable<T>,
fixings: Map<FixOf, BigDecimal>, unusedFixings: MutableSet<FixOf>): Perceivable<T> = fixings: Map<FixOf, BigDecimal>, unusedFixings: MutableSet<FixOf>): Perceivable<T> =
when (perceivable) { when (perceivable) {
is Const -> perceivable is Const -> perceivable
is UnaryPlus -> UnaryPlus(replaceFixing(tx, perceivable.arg, fixings, unusedFixings)) is UnaryPlus -> UnaryPlus(replaceFixing(tx, perceivable.arg, fixings, unusedFixings))
is PerceivableOperation -> PerceivableOperation(replaceFixing(tx, perceivable.left, fixings, unusedFixings), is PerceivableOperation -> PerceivableOperation(replaceFixing(tx, perceivable.left, fixings, unusedFixings),
perceivable.op, replaceFixing(tx, perceivable.right, fixings, unusedFixings)) as Perceivable<T> perceivable.op, replaceFixing(tx, perceivable.right, fixings, unusedFixings))
is Interest -> Interest(replaceFixing(tx, perceivable.amount, fixings, unusedFixings), is Interest -> Interest(replaceFixing(tx, perceivable.amount, fixings, unusedFixings),
perceivable.dayCountConvention, replaceFixing(tx, perceivable.interest, fixings, unusedFixings), perceivable.dayCountConvention, replaceFixing(tx, perceivable.interest, fixings, unusedFixings),
perceivable.start, perceivable.end) as Perceivable<T> perceivable.start, perceivable.end) as Perceivable<T>

View File

@ -4,7 +4,7 @@ import net.corda.core.crypto.generateKeyPair
import net.corda.core.identity.CordaX500Name import net.corda.core.identity.CordaX500Name
import net.corda.testing.core.TestIdentity import net.corda.testing.core.TestIdentity
import org.junit.Test import org.junit.Test
import java.util.* import java.util.Currency
import kotlin.test.assertEquals import kotlin.test.assertEquals
import kotlin.test.assertTrue import kotlin.test.assertTrue
@ -118,8 +118,6 @@ class ContractDefinition {
assertTrue(arr is Actions) assertTrue(arr is Actions)
if (arr is Actions) { assertEquals(1, arr.actions.size)
assertEquals(1, arr.actions.size)
}
} }
} }

View File

@ -10,12 +10,18 @@ import net.corda.core.identity.AbstractParty
import net.corda.core.identity.Party import net.corda.core.identity.Party
import net.corda.core.node.ServiceHub import net.corda.core.node.ServiceHub
import net.corda.core.node.services.StatesNotAvailableException 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 net.corda.finance.contracts.asset.Cash
import java.sql.Connection import java.sql.Connection
import java.sql.DatabaseMetaData import java.sql.DatabaseMetaData
import java.sql.ResultSet 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 import java.util.concurrent.atomic.AtomicReference
/** /**
@ -30,8 +36,8 @@ abstract class AbstractCashSelection(private val maxRetries : Int = 8, private v
companion object { companion object {
val instance = AtomicReference<AbstractCashSelection>() val instance = AtomicReference<AbstractCashSelection>()
fun getInstance(metadata: () -> java.sql.DatabaseMetaData): AbstractCashSelection { fun getInstance(metadata: () -> DatabaseMetaData): AbstractCashSelection {
return instance.get() ?: { return instance.get() ?: run {
val metadataLocal = metadata() val metadataLocal = metadata()
val cashSelectionAlgos = ServiceLoader.load(AbstractCashSelection::class.java, this::class.java.classLoader).toList() val cashSelectionAlgos = ServiceLoader.load(AbstractCashSelection::class.java, this::class.java.classLoader).toList()
val cashSelectionAlgo = cashSelectionAlgos.firstOrNull { it.isCompatible(metadataLocal) } 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}'." + } ?: 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}." + "\nPlease specify an implementation in META-INF/services/${AbstractCashSelection::class.qualifiedName}." +
"\nAvailable implementations: $cashSelectionAlgos") "\nAvailable implementations: $cashSelectionAlgos")
}.invoke() }
} }
private val log = contextLogger() private val log = contextLogger()
@ -139,19 +145,19 @@ abstract class AbstractCashSelection(private val maxRetries : Int = 8, private v
if (stateRefs.isNotEmpty()) { if (stateRefs.isNotEmpty()) {
// TODO: future implementation to retrieve contract states from a Vault BLOB store // TODO: future implementation to retrieve contract states from a Vault BLOB store
@Suppress("UNCHECKED_CAST") @Suppress("UNCHECKED_CAST")
stateAndRefs.addAll(services.loadStates(stateRefs) as Collection<out StateAndRef<Cash.State>>) stateAndRefs.addAll(services.loadStates(stateRefs) as Collection<StateAndRef<Cash.State>>)
} }
val success = stateAndRefs.isNotEmpty() && totalPennies >= amount.quantity val success = stateAndRefs.isNotEmpty() && totalPennies >= amount.quantity
if (success) { if (success) {
// we should have a minimum number of states to satisfy our selection `amount` criteria // 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. // 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. // TODO However, we will have to revisit these methods in the future multi-threaded.
services.vaultService.softLockReserve(lockId, (stateAndRefs.map { it.ref }).toNonEmptySet()) services.vaultService.softLockReserve(lockId, (stateAndRefs.map { it.ref }).toNonEmptySet())
} else { } 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 success
} }

View File

@ -98,15 +98,15 @@ class OpenTelemetryComponent(serviceName: String, val spanStartEndEventsEnabled:
} }
private fun extractContext(carrier: ContextCarrier): Context { private fun extractContext(carrier: ContextCarrier): Context {
val getter = object : TextMapGetter<ContextCarrier?> { val getter = object : TextMapGetter<ContextCarrier> {
override fun get(carrier: ContextCarrier?, key: String): String? { override fun get(carrier: ContextCarrier?, key: String): String? {
return if (carrier?.context?.containsKey(key) == true) { return if (carrier?.context?.containsKey(key) == true) {
val value = carrier.context[key] val value = carrier.context[key]
value value
} else null } else null
} }
override fun keys(carrier: ContextCarrier?): MutableIterable<String> { override fun keys(carrier: ContextCarrier): MutableIterable<String> {
return carrier?.context?.keys ?: mutableListOf() return carrier.context.keys
} }
} }
return carrier.let { return carrier.let {

View File

@ -7,15 +7,14 @@ import net.corda.nodeapi.internal.ArtemisTcpTransport.Companion.TRUST_MANAGER_FA
import net.corda.nodeapi.internal.protonwrapper.netty.createAndInitSslContext 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.DefaultOpenSSLContextFactory
import org.apache.activemq.artemis.core.remoting.impl.ssl.DefaultSSLContextFactory 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.spi.core.remoting.ssl.SSLContextConfig
import org.apache.activemq.artemis.utils.ClassloadingUtil import org.apache.activemq.artemis.utils.ClassloadingUtil
import java.io.File import java.io.File
import java.io.InputStream import java.io.InputStream
import java.net.MalformedURLException import java.net.MalformedURLException
import java.net.URL import java.net.URL
import java.security.AccessController
import java.security.KeyStore import java.security.KeyStore
import java.security.PrivilegedAction
import javax.net.ssl.KeyManagerFactory import javax.net.ssl.KeyManagerFactory
import javax.net.ssl.SSLContext import javax.net.ssl.SSLContext
import javax.net.ssl.TrustManagerFactory import javax.net.ssl.TrustManagerFactory
@ -79,7 +78,7 @@ private fun loadKeystore(
val keyStore = keystoreProvider?.let { KeyStore.getInstance(keystoreType, it) } ?: KeyStore.getInstance(keystoreType) val keyStore = keystoreProvider?.let { KeyStore.getInstance(keystoreType, it) } ?: KeyStore.getInstance(keystoreType)
var inputStream : InputStream? = null var inputStream : InputStream? = null
try { try {
if (keystorePath != null && keystorePath.isNotEmpty()) { if (!keystorePath.isNullOrEmpty()) {
val keystoreURL = validateStoreURL(keystorePath) val keystoreURL = validateStoreURL(keystorePath)
inputStream = keystoreURL.openStream() inputStream = keystoreURL.openStream()
} }
@ -103,23 +102,11 @@ private fun validateStoreURL(storePath: String): URL {
if (file.exists() && file.isFile) { if (file.exists() && file.isFile) {
file.toURI().toURL() file.toURI().toURL()
} else { } 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 * This is an inline function for [InputStream] so it can be closed and
* ignore an exception. * ignore an exception.
@ -132,4 +119,3 @@ private fun InputStream?.closeQuietly() {
// quietly absorb problems // quietly absorb problems
} }
} }

View File

@ -11,7 +11,6 @@ import java.net.DatagramSocket
import java.net.ServerSocket import java.net.ServerSocket
import java.net.Socket import java.net.Socket
import java.net.URLConnection import java.net.URLConnection
import java.security.AccessController
import java.security.KeyStore import java.security.KeyStore
import java.security.Permission import java.security.Permission
import java.security.Provider 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. * 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 * 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. * 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 { object AllButBlacklisted : ClassWhitelist {
@ -56,7 +55,6 @@ object AllButBlacklisted : ClassWhitelist {
// java.security. // java.security.
KeyStore::class.java.name, KeyStore::class.java.name,
AccessController::class.java.name,
Permission::class.java.name, Permission::class.java.name,
// java.net. // java.net.

View File

@ -37,7 +37,7 @@ data class SerializationContextImpl @JvmOverloads constructor(override val prefe
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
@Suppress("OverridingDeprecatedMember") @Suppress("OVERRIDE_DEPRECATION")
override fun withAttachmentsClassLoader(attachmentHashes: List<SecureHash>): SerializationContext { override fun withAttachmentsClassLoader(attachmentHashes: List<SecureHash>): SerializationContext {
return this return this
} }

View File

@ -31,10 +31,6 @@ class CarpenterClassLoader(private val parentClassLoader: ClassLoader = Thread.c
@Throws(ClassNotFoundException::class) @Throws(ClassNotFoundException::class)
override fun loadClass(name: String?, resolve: Boolean): Class<*>? { override fun loadClass(name: String?, resolve: Boolean): Class<*>? {
return synchronized(getClassLoadingLock(name)) { 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 -> (findLoadedClass(name) ?: Class.forName(name, false, parentClassLoader)).also { clazz ->
if (resolve) { if (resolve) {
resolveClass(clazz) resolveClass(clazz)
@ -294,7 +290,7 @@ class ClassCarpenterImpl @JvmOverloads constructor (override val whitelist: Clas
visitFieldInsn(GETFIELD, schema.jvmName, name, type.descriptor) visitFieldInsn(GETFIELD, schema.jvmName, name, type.descriptor)
when (type.field) { when (type.field) {
java.lang.Boolean.TYPE, Integer.TYPE, java.lang.Short.TYPE, java.lang.Byte.TYPE, 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.Long.TYPE -> visitInsn(LRETURN)
java.lang.Double.TYPE -> visitInsn(DRETURN) java.lang.Double.TYPE -> visitInsn(DRETURN)
java.lang.Float.TYPE -> visitInsn(FRETURN) 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 { private fun MethodVisitor.load(slot: Int, type: Field): Int {
when (type.field) { when (type.field) {
java.lang.Boolean.TYPE, Integer.TYPE, java.lang.Short.TYPE, java.lang.Byte.TYPE, 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.Long.TYPE -> visitVarInsn(LLOAD, slot)
java.lang.Double.TYPE -> visitVarInsn(DLOAD, slot) java.lang.Double.TYPE -> visitVarInsn(DLOAD, slot)
java.lang.Float.TYPE -> visitVarInsn(FLOAD, slot) java.lang.Float.TYPE -> visitVarInsn(FLOAD, slot)