Skip to content

Commit 975500d

Browse files
ENT-11351 - Compiler warnings pass 3 (corda#7659)
* More compiler warnings fixed * Amended deprecation suppression annotations, as per review comments
1 parent 3abb218 commit 975500d

File tree

18 files changed

+37
-29
lines changed

18 files changed

+37
-29
lines changed

client/jackson/src/test/kotlin/net/corda/client/jackson/StringToMethodCallParserTest.kt

-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ class StringToMethodCallParserTest {
5151
val result = parser.parse(Target(), "complexNestedObject pairs: { first: 101, second: [ A, B, C ] }").invoke()
5252

5353
assertTrue(result is Pair<*,*>)
54-
result as Pair<*,*>
5554

5655
assertEquals(101, result.first)
5756

client/rpc/src/test/kotlin/net/corda/client/rpc/Measure.kt

+5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package net.corda.client.rpc
22

33
import net.corda.core.internal.uncheckedCast
44
import kotlin.reflect.KCallable
5+
import kotlin.reflect.jvm.ExperimentalReflectionOnLambdas
56
import kotlin.reflect.jvm.reflect
67

78
/**
@@ -10,15 +11,19 @@ import kotlin.reflect.jvm.reflect
1011
* different combinations of parameters.
1112
*/
1213

14+
@OptIn(ExperimentalReflectionOnLambdas::class)
1315
fun <A : Any, R> measure(a: Iterable<A>, f: (A) -> R) =
1416
measure(listOf(a), f.reflect()!!) { f(uncheckedCast(it[0])) }
1517

18+
@OptIn(ExperimentalReflectionOnLambdas::class)
1619
fun <A : Any, B : Any, R> measure(a: Iterable<A>, b: Iterable<B>, f: (A, B) -> R) =
1720
measure(listOf(a, b), f.reflect()!!) { f(uncheckedCast(it[0]), uncheckedCast(it[1])) }
1821

22+
@OptIn(ExperimentalReflectionOnLambdas::class)
1923
fun <A : Any, B : Any, C : Any, R> measure(a: Iterable<A>, b: Iterable<B>, c: Iterable<C>, f: (A, B, C) -> R) =
2024
measure(listOf(a, b, c), f.reflect()!!) { f(uncheckedCast(it[0]), uncheckedCast(it[1]), uncheckedCast(it[2])) }
2125

26+
@OptIn(ExperimentalReflectionOnLambdas::class)
2227
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) =
2328
measure(listOf(a, b, c, d), f.reflect()!!) { f(uncheckedCast(it[0]), uncheckedCast(it[1]), uncheckedCast(it[2]), uncheckedCast(it[3])) }
2429

core-tests/src/test/kotlin/net/corda/coretests/flows/FastThreadLocalTest.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import net.corda.core.internal.rootCause
1313
import net.corda.core.utilities.getOrThrow
1414
import org.assertj.core.api.Assertions.catchThrowable
1515
import org.hamcrest.Matchers.lessThanOrEqualTo
16-
import org.junit.Assert.assertThat
16+
import org.hamcrest.MatcherAssert.assertThat
1717
import org.junit.Test
1818
import java.util.*
1919
import java.util.concurrent.ExecutorService

core-tests/src/test/kotlin/net/corda/coretests/flows/ReceiveAllFlowTests.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ class ReceiveMultipleFlowTests : WithMockNet {
5858
assertEquals(message, receivedMessage)
5959
session.send(answer)
6060
}
61-
} as FlowLogic<Unit>
61+
}
6262
}
6363

6464
assertThat(

core-tests/src/test/kotlin/net/corda/coretests/serialization/AttachmentSerializationTest.kt

+1
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ class AttachmentSerializationTest {
116116
private class CustomAttachment(override val id: SecureHash, internal val customContent: String) : Attachment {
117117
override fun open() = throw UnsupportedOperationException("Not implemented.")
118118
override val signerKeys get() = throw UnsupportedOperationException()
119+
@Suppress("OVERRIDE_DEPRECATION")
119120
override val signers: List<Party> get() = throw UnsupportedOperationException()
120121
override val size get() = throw UnsupportedOperationException()
121122
}

core-tests/src/test/kotlin/net/corda/coretests/transactions/TransactionTests.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ class TransactionTests(private val digestService : DigestService) {
205205
val attachments = listOf(ContractAttachment(object : AbstractAttachment({
206206
(AttachmentsClassLoaderTests::class.java.getResource(ISOLATED_JAR) ?: fail("Missing $ISOLATED_JAR")).openStream().readBytes()
207207
}, TESTDSL_UPLOADER) {
208-
@Suppress("OverridingDeprecatedMember")
208+
@Suppress("OVERRIDE_DEPRECATION")
209209
override val signers: List<Party> = emptyList()
210210
override val signerKeys: List<PublicKey> = emptyList()
211211
override val size: Int = 1234

node/src/integration-test/kotlin/net/corda/node/flows/FlowOverrideTests.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import net.corda.testing.driver.NodeParameters
1515
import net.corda.testing.driver.driver
1616
import net.corda.testing.node.internal.cordappForClasses
1717
import org.hamcrest.CoreMatchers.`is`
18-
import org.junit.Assert.assertThat
18+
import org.hamcrest.MatcherAssert.assertThat
1919
import org.junit.Test
2020

2121
class FlowOverrideTests {

node/src/integration-test/kotlin/net/corda/node/services/CordaServiceIssueOnceAtStartupTests.kt

+2-1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import org.junit.Test
2929
import java.io.File
3030
import kotlin.test.assertEquals
3131
import kotlin.test.assertTrue
32+
import kotlin.io.path.createTempFile
3233

3334
/**
3435
* 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 {
4041
private val armedPropName = this::class.java.enclosingClass.name + "-armed"
4142
private val logger = contextLogger()
4243
private val tempFilePropertyName = this::class.java.enclosingClass.name + "-tmpFile"
43-
private val tmpFile = createTempFile(prefix = tempFilePropertyName)
44+
private val tmpFile = createTempFile(prefix = tempFilePropertyName).toFile()
4445
private const val vaultQueryExecutedMarker = "VaultQueryExecuted"
4546
private const val sentFlowMarker = "SentFlow"
4647
}

node/src/integration-test/kotlin/net/corda/node/services/CordaServiceLifecycleFatalTests.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import org.junit.Test
1818
import java.io.File
1919
import kotlin.test.assertEquals
2020
import kotlin.test.assertFailsWith
21-
21+
import kotlin.io.path.createTempFile
2222
class CordaServiceLifecycleFatalTests {
2323

2424
companion object {
@@ -34,7 +34,7 @@ class CordaServiceLifecycleFatalTests {
3434

3535
// Temporaty file used as a latch between two processes
3636
private val tempFilePropertyName = this::class.java.enclosingClass.name + "-tmpFile"
37-
private val tmpFile = createTempFile(prefix = tempFilePropertyName)
37+
private val tmpFile = createTempFile(prefix = tempFilePropertyName).toFile()
3838
private const val readyToThrowMarker = "ReadyToThrow"
3939
private const val goodToThrowMarker = "GoodToThrow"
4040

node/src/main/kotlin/net/corda/node/internal/CordaRPCOpsImpl.kt

+3-3
Original file line numberDiff line numberDiff line change
@@ -138,18 +138,18 @@ internal class CordaRPCOpsImpl(
138138
return services.vaultService._trackBy(criteria, paging, sorting, contractStateType)
139139
}
140140

141-
@Suppress("OverridingDeprecatedMember", "DEPRECATION")
141+
@Suppress("OVERRIDE_DEPRECATION", "OverridingDeprecatedMember", "DEPRECATION")
142142
override fun internalVerifiedTransactionsSnapshot(): List<SignedTransaction> {
143143
val (snapshot, updates) = internalVerifiedTransactionsFeed()
144144
updates.notUsed()
145145
return snapshot
146146
}
147147

148-
@Suppress("OverridingDeprecatedMember")
148+
@Suppress("OVERRIDE_DEPRECATION")
149149
override fun internalFindVerifiedTransaction(txnId: SecureHash): SignedTransaction? =
150150
services.validatedTransactions.getTransaction(txnId)
151151

152-
@Suppress("OverridingDeprecatedMember")
152+
@Suppress("OVERRIDE_DEPRECATION")
153153
override fun internalVerifiedTransactionsFeed(): DataFeed<List<SignedTransaction>, SignedTransaction> {
154154
return services.validatedTransactions.track()
155155
}

node/src/test/kotlin/net/corda/node/migration/IdentityServiceToStringShortMigrationTest.kt

+3-4
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import org.hamcrest.Matchers.anyOf
2424
import org.hamcrest.Matchers.`is`
2525
import org.hamcrest.number.OrderingComparison.greaterThan
2626
import org.junit.After
27-
import org.junit.Assert
2827
import org.junit.Before
2928
import org.junit.Test
3029

@@ -103,17 +102,17 @@ class IdentityServiceToStringShortMigrationTest {
103102
val hashToIdentityResultSet = hashToIdentityStatement.executeQuery()
104103

105104
//check that there is a row for every "new" hash
106-
Assert.assertThat(hashToIdentityResultSet.next(), `is`(true))
105+
assertThat(hashToIdentityResultSet.next(), `is`(true))
107106
//check that the pk_hash actually matches what we expect (kinda redundant, but deserializing the whole PartyAndCertificate feels like overkill)
108-
Assert.assertThat(hashToIdentityResultSet.getString(1), `is`(it.owningKey.toStringShort()))
107+
assertThat(hashToIdentityResultSet.getString(1), `is`(it.owningKey.toStringShort()))
109108

110109
val nameToHashStatement = connection.prepareStatement("SELECT name FROM node_named_identities WHERE pk_hash=?")
111110
nameToHashStatement.setString(1, it.owningKey.toStringShort())
112111
val nameToHashResultSet = nameToHashStatement.executeQuery()
113112

114113
//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)
115114
if (nameToHashResultSet.next()) {
116-
Assert.assertThat(nameToHashResultSet.getString(1), `is`(anyOf(groupedByNameIdentities.getValue(it.name).map<PartyAndCertificate, Matcher<String>?> { identity -> CoreMatchers.equalTo(identity.name.toString()) })))
115+
assertThat(nameToHashResultSet.getString(1), `is`(anyOf(groupedByNameIdentities.getValue(it.name).map<PartyAndCertificate, Matcher<String>?> { identity -> CoreMatchers.equalTo(identity.name.toString()) })))
117116
} else {
118117
logger.warn("did not find a PK_HASH for ${it.name}")
119118
listOfNamesWithoutPkHash.add(it.name)

node/src/test/kotlin/net/corda/node/services/network/NetworkMapUpdaterTest.kt

+6-5
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ import org.assertj.core.api.Assertions.assertThat
4848
import org.assertj.core.api.Assertions.assertThatThrownBy
4949
import org.hamcrest.collection.IsIterableContainingInAnyOrder
5050
import org.junit.After
51-
import org.junit.Assert
5251
import org.junit.Before
5352
import org.junit.Rule
5453
import org.junit.Test
@@ -76,6 +75,8 @@ import kotlin.io.path.exists
7675
import kotlin.test.assertEquals
7776
import kotlin.test.assertFalse
7877
import kotlin.test.assertTrue
78+
import org.hamcrest.MatcherAssert.assertThat
79+
7980

8081
class NetworkMapUpdaterTest {
8182
@Rule
@@ -161,7 +162,7 @@ class NetworkMapUpdaterTest {
161162
//TODO: Remove sleep in unit test.
162163
Thread.sleep(2L * cacheExpiryMs)
163164

164-
Assert.assertThat(networkMapCache.allNodeHashes, IsIterableContainingInAnyOrder.containsInAnyOrder(signedNodeInfo1.raw.hash, signedNodeInfo2.raw.hash))
165+
assertThat(networkMapCache.allNodeHashes, IsIterableContainingInAnyOrder.containsInAnyOrder(signedNodeInfo1.raw.hash, signedNodeInfo2.raw.hash))
165166

166167
assertThat(nodeReadyFuture).isDone()
167168

@@ -173,7 +174,7 @@ class NetworkMapUpdaterTest {
173174
Thread.sleep(2L * cacheExpiryMs)
174175
//4 node info from network map, and 1 from file.
175176

176-
Assert.assertThat(networkMapCache.allNodeHashes, IsIterableContainingInAnyOrder.containsInAnyOrder(
177+
assertThat(networkMapCache.allNodeHashes, IsIterableContainingInAnyOrder.containsInAnyOrder(
177178
signedNodeInfo1.raw.hash,
178179
signedNodeInfo2.raw.hash,
179180
signedNodeInfo3.raw.hash,
@@ -204,7 +205,7 @@ class NetworkMapUpdaterTest {
204205
Thread.sleep(2L * cacheExpiryMs)
205206

206207

207-
Assert.assertThat(networkMapCache.allNodeHashes, IsIterableContainingInAnyOrder.containsInAnyOrder(
208+
assertThat(networkMapCache.allNodeHashes, IsIterableContainingInAnyOrder.containsInAnyOrder(
208209
signedNodeInfo1.raw.hash,
209210
signedNodeInfo2.raw.hash,
210211
signedNodeInfo3.raw.hash,
@@ -248,7 +249,7 @@ class NetworkMapUpdaterTest {
248249
//TODO: Remove sleep in unit test.
249250
Thread.sleep(2L * cacheExpiryMs)
250251

251-
Assert.assertThat(networkMapCache.allNodeHashes, IsIterableContainingInAnyOrder.containsInAnyOrder(
252+
assertThat(networkMapCache.allNodeHashes, IsIterableContainingInAnyOrder.containsInAnyOrder(
252253
signedNodeInfo1.raw.hash,
253254
signedNodeInfo2.raw.hash
254255
))

node/src/test/kotlin/net/corda/node/services/persistence/DBCheckpointStorageTests.kt

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

node/src/test/kotlin/net/corda/notary/experimental/raft/RaftTransactionCommitLogTests.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ import net.corda.testing.internal.LogHelper
2626
import net.corda.testing.internal.TestingNamedCacheFactory
2727
import net.corda.testing.internal.configureDatabase
2828
import net.corda.testing.node.MockServices.Companion.makeTestDataSourceProperties
29+
import org.hamcrest.MatcherAssert.assertThat
2930
import org.hamcrest.Matchers.instanceOf
3031
import org.junit.After
31-
import org.junit.Assert.assertThat
3232
import org.junit.Before
3333
import org.junit.Rule
3434
import org.junit.Test

serialization-tests/src/test/kotlin/net/corda/serialization/internal/amqp/AbstractAMQPSerializationSchemeTest.kt

+4-4
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import net.corda.coretesting.internal.createTestSerializationEnv
1212
import org.hamcrest.CoreMatchers
1313
import org.hamcrest.CoreMatchers.`is`
1414
import org.hamcrest.Matchers
15-
import org.junit.Assert
15+
import org.hamcrest.MatcherAssert.assertThat
1616
import org.junit.Test
1717
import java.net.URLClassLoader
1818
import java.util.concurrent.ThreadLocalRandom
@@ -61,10 +61,10 @@ class AbstractAMQPSerializationSchemeTest {
6161
val testString = "TEST${ThreadLocalRandom.current().nextInt()}"
6262
val serialized = scheme.serialize(testString, context)
6363
val deserialized = serialized.deserialize(context = context, serializationFactory = serializationEnvironment.serializationFactory)
64-
Assert.assertThat(testString, `is`(deserialized))
65-
Assert.assertThat(backingMap.size, `is`(Matchers.lessThanOrEqualTo(maxFactories)))
64+
assertThat(testString, `is`(deserialized))
65+
assertThat(backingMap.size, `is`(Matchers.lessThanOrEqualTo(maxFactories)))
6666
}
67-
Assert.assertThat(backingMap.size, CoreMatchers.`is`(Matchers.lessThanOrEqualTo(maxFactories)))
67+
assertThat(backingMap.size, CoreMatchers.`is`(Matchers.lessThanOrEqualTo(maxFactories)))
6868
}
6969
}
7070

tools/bootstrapper/src/test/kotlin/net/corda/bootstrapper/NetworkBootstrapperRunnerTests.kt

+2-1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import java.nio.file.Path
2525
import java.nio.file.Paths
2626
import java.security.PublicKey
2727
import kotlin.io.path.Path
28+
import kotlin.io.path.createTempDirectory
2829
import kotlin.io.path.div
2930
import kotlin.test.assertEquals
3031
import kotlin.test.assertFailsWith
@@ -99,7 +100,7 @@ class NetworkBootstrapperRunnerTests {
99100
@Test(timeout=300_000)
100101
fun `test when base directory is specified it is passed through to the bootstrapper`() {
101102
val (runner, mockBootstrapper) = getRunner()
102-
val tempDir = createTempDir()
103+
val tempDir = createTempDirectory().toFile()
103104
runner.dir = tempDir.toPath()
104105
val exitCode = runner.runProgram()
105106
verify(mockBootstrapper).bootstrap(tempDir.toPath().toAbsolutePath().normalize(), CopyCordapps.FirstRunOnly, NetworkParametersOverrides())

tools/error-tool/src/test/kotlin/net/corda/errorUtilities/resourceGenerator/ResourceGeneratorTest.kt

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import junit.framework.TestCase.assertEquals
44
import net.corda.common.logging.errorReporting.ResourceBundleProperties
55
import org.junit.Test
66
import java.util.*
7+
import kotlin.io.path.createTempDirectory
78

89
class ResourceGeneratorTest {
910

@@ -42,7 +43,7 @@ class ResourceGeneratorTest {
4243
assertEquals(expectedCodes().map { "$it.properties" }.toSet(), missing.toSet())
4344

4445
// Now check that all resource files that should be created are
45-
val tempDir = createTempDir()
46+
val tempDir = createTempDirectory().toFile()
4647
resourceGenerator.createResources(missing, tempDir.toPath())
4748
val createdFiles = tempDir.walkTopDown().filter { it.isFile && it.extension == "properties" }.map { it.name }.toSet()
4849
assertEquals(missing.toSet(), createdFiles)

tools/loadtest/src/main/kotlin/net/corda/loadtest/ConnectionManager.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ fun setupJSchWithSshAgent(): JSch {
4444
override fun getName() = String(identity.comment)
4545
override fun isEncrypted() = false
4646
override fun getSignature(data: ByteArray?) = agentProxy.sign(identity.blob, data)
47-
@Suppress("OverridingDeprecatedMember")
47+
@Suppress("OVERRIDE_DEPRECATION")
4848
override fun decrypt() = true
4949

5050
override fun getPublicKeyBlob() = identity.blob

0 commit comments

Comments
 (0)