ENT-11351 - Compiler warnings pass 3 (#7659)

* More compiler warnings fixed

* Amended deprecation suppression annotations, as per review comments
This commit is contained in:
Chris Cochrane 2024-01-25 10:18:58 +00:00 committed by GitHub
parent 3abb218bca
commit 975500d878
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
18 changed files with 37 additions and 29 deletions

View File

@ -51,7 +51,6 @@ class StringToMethodCallParserTest {
val result = parser.parse(Target(), "complexNestedObject pairs: { first: 101, second: [ A, B, C ] }").invoke()
assertTrue(result is Pair<*,*>)
result as Pair<*,*>
assertEquals(101, result.first)

View File

@ -2,6 +2,7 @@ package net.corda.client.rpc
import net.corda.core.internal.uncheckedCast
import kotlin.reflect.KCallable
import kotlin.reflect.jvm.ExperimentalReflectionOnLambdas
import kotlin.reflect.jvm.reflect
/**
@ -10,15 +11,19 @@ import kotlin.reflect.jvm.reflect
* different combinations of parameters.
*/
@OptIn(ExperimentalReflectionOnLambdas::class)
fun <A : Any, R> measure(a: Iterable<A>, f: (A) -> R) =
measure(listOf(a), f.reflect()!!) { f(uncheckedCast(it[0])) }
@OptIn(ExperimentalReflectionOnLambdas::class)
fun <A : Any, B : Any, R> measure(a: Iterable<A>, b: Iterable<B>, f: (A, B) -> R) =
measure(listOf(a, b), f.reflect()!!) { f(uncheckedCast(it[0]), uncheckedCast(it[1])) }
@OptIn(ExperimentalReflectionOnLambdas::class)
fun <A : Any, B : Any, C : Any, R> measure(a: Iterable<A>, b: Iterable<B>, c: Iterable<C>, f: (A, B, C) -> R) =
measure(listOf(a, b, c), f.reflect()!!) { f(uncheckedCast(it[0]), uncheckedCast(it[1]), uncheckedCast(it[2])) }
@OptIn(ExperimentalReflectionOnLambdas::class)
fun <A : Any, B : Any, C : Any, D : Any, R> measure(a: Iterable<A>, b: Iterable<B>, c: Iterable<C>, d: Iterable<D>, f: (A, B, C, D) -> R) =
measure(listOf(a, b, c, d), f.reflect()!!) { f(uncheckedCast(it[0]), uncheckedCast(it[1]), uncheckedCast(it[2]), uncheckedCast(it[3])) }

View File

@ -13,7 +13,7 @@ import net.corda.core.internal.rootCause
import net.corda.core.utilities.getOrThrow
import org.assertj.core.api.Assertions.catchThrowable
import org.hamcrest.Matchers.lessThanOrEqualTo
import org.junit.Assert.assertThat
import org.hamcrest.MatcherAssert.assertThat
import org.junit.Test
import java.util.*
import java.util.concurrent.ExecutorService

View File

@ -58,7 +58,7 @@ class ReceiveMultipleFlowTests : WithMockNet {
assertEquals(message, receivedMessage)
session.send(answer)
}
} as FlowLogic<Unit>
}
}
assertThat(

View File

@ -116,6 +116,7 @@ class AttachmentSerializationTest {
private class CustomAttachment(override val id: SecureHash, internal val customContent: String) : Attachment {
override fun open() = throw UnsupportedOperationException("Not implemented.")
override val signerKeys get() = throw UnsupportedOperationException()
@Suppress("OVERRIDE_DEPRECATION")
override val signers: List<Party> get() = throw UnsupportedOperationException()
override val size get() = throw UnsupportedOperationException()
}

View File

@ -205,7 +205,7 @@ class TransactionTests(private val digestService : DigestService) {
val attachments = listOf(ContractAttachment(object : AbstractAttachment({
(AttachmentsClassLoaderTests::class.java.getResource(ISOLATED_JAR) ?: fail("Missing $ISOLATED_JAR")).openStream().readBytes()
}, TESTDSL_UPLOADER) {
@Suppress("OverridingDeprecatedMember")
@Suppress("OVERRIDE_DEPRECATION")
override val signers: List<Party> = emptyList()
override val signerKeys: List<PublicKey> = emptyList()
override val size: Int = 1234

View File

@ -15,7 +15,7 @@ import net.corda.testing.driver.NodeParameters
import net.corda.testing.driver.driver
import net.corda.testing.node.internal.cordappForClasses
import org.hamcrest.CoreMatchers.`is`
import org.junit.Assert.assertThat
import org.hamcrest.MatcherAssert.assertThat
import org.junit.Test
class FlowOverrideTests {

View File

@ -29,6 +29,7 @@ import org.junit.Test
import java.io.File
import kotlin.test.assertEquals
import kotlin.test.assertTrue
import kotlin.io.path.createTempFile
/**
* The idea of this test is upon start-up of the node check if cash been already issued and if not issue under certain reference.
@ -40,7 +41,7 @@ class CordaServiceIssueOnceAtStartupTests {
private val armedPropName = this::class.java.enclosingClass.name + "-armed"
private val logger = contextLogger()
private val tempFilePropertyName = this::class.java.enclosingClass.name + "-tmpFile"
private val tmpFile = createTempFile(prefix = tempFilePropertyName)
private val tmpFile = createTempFile(prefix = tempFilePropertyName).toFile()
private const val vaultQueryExecutedMarker = "VaultQueryExecuted"
private const val sentFlowMarker = "SentFlow"
}

View File

@ -18,7 +18,7 @@ import org.junit.Test
import java.io.File
import kotlin.test.assertEquals
import kotlin.test.assertFailsWith
import kotlin.io.path.createTempFile
class CordaServiceLifecycleFatalTests {
companion object {
@ -34,7 +34,7 @@ class CordaServiceLifecycleFatalTests {
// Temporaty file used as a latch between two processes
private val tempFilePropertyName = this::class.java.enclosingClass.name + "-tmpFile"
private val tmpFile = createTempFile(prefix = tempFilePropertyName)
private val tmpFile = createTempFile(prefix = tempFilePropertyName).toFile()
private const val readyToThrowMarker = "ReadyToThrow"
private const val goodToThrowMarker = "GoodToThrow"

View File

@ -138,18 +138,18 @@ internal class CordaRPCOpsImpl(
return services.vaultService._trackBy(criteria, paging, sorting, contractStateType)
}
@Suppress("OverridingDeprecatedMember", "DEPRECATION")
@Suppress("OVERRIDE_DEPRECATION", "OverridingDeprecatedMember", "DEPRECATION")
override fun internalVerifiedTransactionsSnapshot(): List<SignedTransaction> {
val (snapshot, updates) = internalVerifiedTransactionsFeed()
updates.notUsed()
return snapshot
}
@Suppress("OverridingDeprecatedMember")
@Suppress("OVERRIDE_DEPRECATION")
override fun internalFindVerifiedTransaction(txnId: SecureHash): SignedTransaction? =
services.validatedTransactions.getTransaction(txnId)
@Suppress("OverridingDeprecatedMember")
@Suppress("OVERRIDE_DEPRECATION")
override fun internalVerifiedTransactionsFeed(): DataFeed<List<SignedTransaction>, SignedTransaction> {
return services.validatedTransactions.track()
}

View File

@ -24,7 +24,6 @@ import org.hamcrest.Matchers.anyOf
import org.hamcrest.Matchers.`is`
import org.hamcrest.number.OrderingComparison.greaterThan
import org.junit.After
import org.junit.Assert
import org.junit.Before
import org.junit.Test
@ -103,9 +102,9 @@ class IdentityServiceToStringShortMigrationTest {
val hashToIdentityResultSet = hashToIdentityStatement.executeQuery()
//check that there is a row for every "new" hash
Assert.assertThat(hashToIdentityResultSet.next(), `is`(true))
assertThat(hashToIdentityResultSet.next(), `is`(true))
//check that the pk_hash actually matches what we expect (kinda redundant, but deserializing the whole PartyAndCertificate feels like overkill)
Assert.assertThat(hashToIdentityResultSet.getString(1), `is`(it.owningKey.toStringShort()))
assertThat(hashToIdentityResultSet.getString(1), `is`(it.owningKey.toStringShort()))
val nameToHashStatement = connection.prepareStatement("SELECT name FROM node_named_identities WHERE pk_hash=?")
nameToHashStatement.setString(1, it.owningKey.toStringShort())
@ -113,7 +112,7 @@ class IdentityServiceToStringShortMigrationTest {
//if there is no result for this key, this means its an identity that is not stored in the DB (IE, it's been seen after another identity has already been mapped to it)
if (nameToHashResultSet.next()) {
Assert.assertThat(nameToHashResultSet.getString(1), `is`(anyOf(groupedByNameIdentities.getValue(it.name).map<PartyAndCertificate, Matcher<String>?> { identity -> CoreMatchers.equalTo(identity.name.toString()) })))
assertThat(nameToHashResultSet.getString(1), `is`(anyOf(groupedByNameIdentities.getValue(it.name).map<PartyAndCertificate, Matcher<String>?> { identity -> CoreMatchers.equalTo(identity.name.toString()) })))
} else {
logger.warn("did not find a PK_HASH for ${it.name}")
listOfNamesWithoutPkHash.add(it.name)

View File

@ -48,7 +48,6 @@ import org.assertj.core.api.Assertions.assertThat
import org.assertj.core.api.Assertions.assertThatThrownBy
import org.hamcrest.collection.IsIterableContainingInAnyOrder
import org.junit.After
import org.junit.Assert
import org.junit.Before
import org.junit.Rule
import org.junit.Test
@ -76,6 +75,8 @@ import kotlin.io.path.exists
import kotlin.test.assertEquals
import kotlin.test.assertFalse
import kotlin.test.assertTrue
import org.hamcrest.MatcherAssert.assertThat
class NetworkMapUpdaterTest {
@Rule
@ -161,7 +162,7 @@ class NetworkMapUpdaterTest {
//TODO: Remove sleep in unit test.
Thread.sleep(2L * cacheExpiryMs)
Assert.assertThat(networkMapCache.allNodeHashes, IsIterableContainingInAnyOrder.containsInAnyOrder(signedNodeInfo1.raw.hash, signedNodeInfo2.raw.hash))
assertThat(networkMapCache.allNodeHashes, IsIterableContainingInAnyOrder.containsInAnyOrder(signedNodeInfo1.raw.hash, signedNodeInfo2.raw.hash))
assertThat(nodeReadyFuture).isDone()
@ -173,7 +174,7 @@ class NetworkMapUpdaterTest {
Thread.sleep(2L * cacheExpiryMs)
//4 node info from network map, and 1 from file.
Assert.assertThat(networkMapCache.allNodeHashes, IsIterableContainingInAnyOrder.containsInAnyOrder(
assertThat(networkMapCache.allNodeHashes, IsIterableContainingInAnyOrder.containsInAnyOrder(
signedNodeInfo1.raw.hash,
signedNodeInfo2.raw.hash,
signedNodeInfo3.raw.hash,
@ -204,7 +205,7 @@ class NetworkMapUpdaterTest {
Thread.sleep(2L * cacheExpiryMs)
Assert.assertThat(networkMapCache.allNodeHashes, IsIterableContainingInAnyOrder.containsInAnyOrder(
assertThat(networkMapCache.allNodeHashes, IsIterableContainingInAnyOrder.containsInAnyOrder(
signedNodeInfo1.raw.hash,
signedNodeInfo2.raw.hash,
signedNodeInfo3.raw.hash,
@ -248,7 +249,7 @@ class NetworkMapUpdaterTest {
//TODO: Remove sleep in unit test.
Thread.sleep(2L * cacheExpiryMs)
Assert.assertThat(networkMapCache.allNodeHashes, IsIterableContainingInAnyOrder.containsInAnyOrder(
assertThat(networkMapCache.allNodeHashes, IsIterableContainingInAnyOrder.containsInAnyOrder(
signedNodeInfo1.raw.hash,
signedNodeInfo2.raw.hash
))

View File

@ -454,7 +454,7 @@ class DBCheckpointStorageTests {
val deserializedException = exceptionDetails.value?.let { SerializedBytes<Any>(it) }?.deserialize(context = SerializationDefaults.STORAGE_CONTEXT)
// IllegalStateException does not implement [CordaThrowable] therefore gets deserialized as a [CordaRuntimeException]
assertTrue(deserializedException is CordaRuntimeException)
val cordaRuntimeException = deserializedException as CordaRuntimeException
val cordaRuntimeException = deserializedException
assertEquals(IllegalStateException::class.java.name, cordaRuntimeException.originalExceptionClassName)
assertEquals("I am a naughty exception", cordaRuntimeException.originalMessage!!)
}

View File

@ -26,9 +26,9 @@ import net.corda.testing.internal.LogHelper
import net.corda.testing.internal.TestingNamedCacheFactory
import net.corda.testing.internal.configureDatabase
import net.corda.testing.node.MockServices.Companion.makeTestDataSourceProperties
import org.hamcrest.MatcherAssert.assertThat
import org.hamcrest.Matchers.instanceOf
import org.junit.After
import org.junit.Assert.assertThat
import org.junit.Before
import org.junit.Rule
import org.junit.Test

View File

@ -12,7 +12,7 @@ import net.corda.coretesting.internal.createTestSerializationEnv
import org.hamcrest.CoreMatchers
import org.hamcrest.CoreMatchers.`is`
import org.hamcrest.Matchers
import org.junit.Assert
import org.hamcrest.MatcherAssert.assertThat
import org.junit.Test
import java.net.URLClassLoader
import java.util.concurrent.ThreadLocalRandom
@ -61,10 +61,10 @@ class AbstractAMQPSerializationSchemeTest {
val testString = "TEST${ThreadLocalRandom.current().nextInt()}"
val serialized = scheme.serialize(testString, context)
val deserialized = serialized.deserialize(context = context, serializationFactory = serializationEnvironment.serializationFactory)
Assert.assertThat(testString, `is`(deserialized))
Assert.assertThat(backingMap.size, `is`(Matchers.lessThanOrEqualTo(maxFactories)))
assertThat(testString, `is`(deserialized))
assertThat(backingMap.size, `is`(Matchers.lessThanOrEqualTo(maxFactories)))
}
Assert.assertThat(backingMap.size, CoreMatchers.`is`(Matchers.lessThanOrEqualTo(maxFactories)))
assertThat(backingMap.size, CoreMatchers.`is`(Matchers.lessThanOrEqualTo(maxFactories)))
}
}

View File

@ -25,6 +25,7 @@ import java.nio.file.Path
import java.nio.file.Paths
import java.security.PublicKey
import kotlin.io.path.Path
import kotlin.io.path.createTempDirectory
import kotlin.io.path.div
import kotlin.test.assertEquals
import kotlin.test.assertFailsWith
@ -99,7 +100,7 @@ class NetworkBootstrapperRunnerTests {
@Test(timeout=300_000)
fun `test when base directory is specified it is passed through to the bootstrapper`() {
val (runner, mockBootstrapper) = getRunner()
val tempDir = createTempDir()
val tempDir = createTempDirectory().toFile()
runner.dir = tempDir.toPath()
val exitCode = runner.runProgram()
verify(mockBootstrapper).bootstrap(tempDir.toPath().toAbsolutePath().normalize(), CopyCordapps.FirstRunOnly, NetworkParametersOverrides())

View File

@ -4,6 +4,7 @@ import junit.framework.TestCase.assertEquals
import net.corda.common.logging.errorReporting.ResourceBundleProperties
import org.junit.Test
import java.util.*
import kotlin.io.path.createTempDirectory
class ResourceGeneratorTest {
@ -42,7 +43,7 @@ class ResourceGeneratorTest {
assertEquals(expectedCodes().map { "$it.properties" }.toSet(), missing.toSet())
// Now check that all resource files that should be created are
val tempDir = createTempDir()
val tempDir = createTempDirectory().toFile()
resourceGenerator.createResources(missing, tempDir.toPath())
val createdFiles = tempDir.walkTopDown().filter { it.isFile && it.extension == "properties" }.map { it.name }.toSet()
assertEquals(missing.toSet(), createdFiles)

View File

@ -44,7 +44,7 @@ fun setupJSchWithSshAgent(): JSch {
override fun getName() = String(identity.comment)
override fun isEncrypted() = false
override fun getSignature(data: ByteArray?) = agentProxy.sign(identity.blob, data)
@Suppress("OverridingDeprecatedMember")
@Suppress("OVERRIDE_DEPRECATION")
override fun decrypt() = true
override fun getPublicKeyBlob() = identity.blob