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') {
steps {
/*
* TODO JDK17: Re-enable warnings as errors
*/
sh "./gradlew --no-daemon -Pcompilation.warningsAsErrors=false compileAll"
sh "./gradlew --no-daemon -Pcompilation.warningsAsErrors=true compileAll"
}
}

View File

@ -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<NodeAn
val builder = Builder()
val listOfChildren = sequenceOfChildren.objects.toList()
listOfChildren.forEach { childAsn1 ->
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<NodeAn
require(threshold == null || threshold > 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." }

View File

@ -38,20 +38,20 @@ class PrivateInterner<T>(val verifier: IternabilityVerifier<T> = 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<Any>? {
// 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<T>(val verifier: IternabilityVerifier<T> = AlwaysInternabl
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>) {
@Suppress("VARIABLE_WITH_REDUNDANT_INITIALIZER") // Because the external verifier uses Kotlin 1.2
var firstLtx: LedgerTransaction? = null
transactionFactory.get().let { ltx ->

View File

@ -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<Party> get() = throw UnsupportedOperationException()
override val size: Int = 512
}

View File

@ -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
}

View File

@ -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<UniversalContract.Commands>()
val cmd = tx.commands.requireSingleCommand<Commands>()
val value = cmd.value
@ -275,13 +281,14 @@ class UniversalContract : Contract {
}
}
@Suppress("UNCHECKED_CAST")
fun <T> replaceFixing(tx: LedgerTransaction, perceivable: Perceivable<T>,
fixings: Map<FixOf, BigDecimal>, unusedFixings: MutableSet<FixOf>): Perceivable<T> =
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<T>
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<T>

View File

@ -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)
}
}

View File

@ -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<AbstractCashSelection>()
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<out StateAndRef<Cash.State>>)
stateAndRefs.addAll(services.loadStates(stateRefs) as Collection<StateAndRef<Cash.State>>)
}
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
}

View File

@ -98,15 +98,15 @@ class OpenTelemetryComponent(serviceName: String, val spanStartEndEventsEnabled:
}
private fun extractContext(carrier: ContextCarrier): Context {
val getter = object : TextMapGetter<ContextCarrier?> {
val getter = object : TextMapGetter<ContextCarrier> {
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<String> {
return carrier?.context?.keys ?: mutableListOf()
override fun keys(carrier: ContextCarrier): MutableIterable<String> {
return carrier.context.keys
}
}
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 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
}
}

View File

@ -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.

View File

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

View File

@ -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)