Skip to content

Commit f15e6ec

Browse files
ENT-11351 - Compiler warnings pass 2 (corda#7655)
* Addressed compiler warnings * Removed unchecked cast fixes - not for this PR * Sorted out detekt issues
1 parent a0ce265 commit f15e6ec

File tree

20 files changed

+113
-125
lines changed

20 files changed

+113
-125
lines changed

common/configuration-parsing/src/test/kotlin/net/corda/common/configuration/parsing/internal/SpecificationTest.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ class SpecificationTest {
6161

6262
override fun parseValid(configuration: Config, options: Configuration.Options): Valid<AtomicLong> {
6363
val config = configuration.withOptions(options)
64-
return valid(AtomicLong(config[maxElement]!!))
64+
return valid(AtomicLong(config[maxElement]))
6565
}
6666
}
6767

@@ -103,7 +103,7 @@ class SpecificationTest {
103103
if (elements.any { element -> element <= 1 }) {
104104
return invalid(Configuration.Validation.Error.BadValue.of("elements cannot be less than or equal to 1"))
105105
}
106-
return valid(elements.max()!!)
106+
return valid(elements.max())
107107
}
108108

109109
val spec = object : Configuration.Specification<AtomicLong>("AtomicLong") {

core-tests/src/test/kotlin/net/corda/coretests/contracts/AmountTests.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ class AmountTests {
5656
val splits = baseAmount.splitEvenly(partitionCount)
5757
assertEquals(partitionCount, splits.size)
5858
assertEquals(baseAmount, splits.sumOrZero(baseAmount.token))
59-
val min = splits.min()!!
60-
val max = splits.max()!!
59+
val min = splits.min()
60+
val max = splits.max()
6161
assertTrue(max.quantity - min.quantity <= 1L, "Amount quantities should differ by at most one token")
6262
}
6363
}

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ class CompatibleTransactionTests {
292292
ftxCompatibleNoInputs.verify()
293293
assertFailsWith<ComponentVisibilityException> { ftxCompatibleNoInputs.checkAllComponentsVisible(INPUTS_GROUP) }
294294
assertEquals(wireTransactionCompatibleA.componentGroups.size - 1, ftxCompatibleNoInputs.filteredComponentGroups.size)
295-
assertEquals(wireTransactionCompatibleA.componentGroups.map { it.groupIndex }.max()!!, ftxCompatibleNoInputs.groupHashes.size - 1)
295+
assertEquals(wireTransactionCompatibleA.componentGroups.map { it.groupIndex }.max(), ftxCompatibleNoInputs.groupHashes.size - 1)
296296
}
297297

298298
@Test(timeout=300_000)

core-tests/src/test/kotlin/net/corda/coretests/utilities/KotlinUtilsTest.kt

+12-14
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ import net.corda.testing.core.SerializationEnvironmentRule
1313
import org.assertj.core.api.Assertions.assertThat
1414
import org.junit.Rule
1515
import org.junit.Test
16-
import org.junit.rules.ExpectedException
16+
import org.junit.jupiter.api.assertThrows
17+
import kotlin.test.assertTrue
1718

1819
object EmptyWhitelist : ClassWhitelist {
1920
override fun hasListed(type: Class<*>): Boolean = false
@@ -23,9 +24,6 @@ class KotlinUtilsTest {
2324
@Rule
2425
@JvmField
2526
val testSerialization = SerializationEnvironmentRule()
26-
@JvmField
27-
@Rule
28-
val expectedEx: ExpectedException = ExpectedException.none()
2927

3028
private val KRYO_CHECKPOINT_NOWHITELIST_CONTEXT = CheckpointSerializationContextImpl(
3129
javaClass.classLoader,
@@ -54,10 +52,11 @@ class KotlinUtilsTest {
5452

5553
@Test(timeout=300_000)
5654
fun `deserialise transient property with non-capturing lambda`() {
57-
expectedEx.expect(KryoException::class.java)
58-
expectedEx.expectMessage("is not annotated or on the whitelist, so cannot be used in serialization")
59-
val original = NonCapturingTransientProperty()
60-
original.checkpointSerialize(context = KRYO_CHECKPOINT_CONTEXT).checkpointDeserialize(context = KRYO_CHECKPOINT_NOWHITELIST_CONTEXT)
55+
val anException = assertThrows<KryoException> {
56+
val original = NonCapturingTransientProperty()
57+
original.checkpointSerialize(context = KRYO_CHECKPOINT_CONTEXT).checkpointDeserialize(context = KRYO_CHECKPOINT_NOWHITELIST_CONTEXT)
58+
}
59+
anException.message?.let { assertTrue(it.contains("is not annotated or on the whitelist, so cannot be used in serialization")) }
6160
}
6261

6362
@Test(timeout=300_000)
@@ -73,12 +72,11 @@ class KotlinUtilsTest {
7372

7473
@Test(timeout=300_000)
7574
fun `deserialise transient property with capturing lambda`() {
76-
expectedEx.expect(KryoException::class.java)
77-
expectedEx.expectMessage("is not annotated or on the whitelist, so cannot be used in serialization")
78-
79-
val original = CapturingTransientProperty("Hello")
80-
81-
original.checkpointSerialize(context = KRYO_CHECKPOINT_CONTEXT).checkpointDeserialize(context = KRYO_CHECKPOINT_NOWHITELIST_CONTEXT)
75+
val anException = assertThrows<KryoException> {
76+
val original = CapturingTransientProperty("Hello")
77+
original.checkpointSerialize(context = KRYO_CHECKPOINT_CONTEXT).checkpointDeserialize(context = KRYO_CHECKPOINT_NOWHITELIST_CONTEXT)
78+
}
79+
anException.message?.let { assertTrue(it.contains("is not annotated or on the whitelist, so cannot be used in serialization")) }
8280
}
8381

8482
private class NullTransientProperty {

core/src/test/kotlin/net/corda/core/utilities/LazyMappedListTest.kt

+7-12
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,12 @@ import net.corda.core.internal.lazyMapped
55
import net.corda.core.internal.TransactionDeserialisationException
66
import net.corda.core.internal.eagerDeserialise
77
import net.corda.core.serialization.MissingAttachmentsException
8-
import org.junit.Rule
98
import org.junit.Test
10-
import org.junit.rules.ExpectedException
9+
import org.junit.jupiter.api.assertThrows
1110
import kotlin.test.assertEquals
1211

1312
class LazyMappedListTest {
1413

15-
@get:Rule
16-
val exception: ExpectedException = ExpectedException.none()
17-
1814
@Test(timeout=300_000)
1915
fun `LazyMappedList works`() {
2016
val originalList = (1 until 10).toList()
@@ -44,14 +40,13 @@ class LazyMappedListTest {
4440

4541
@Test(timeout=300_000)
4642
fun testMissingAttachments() {
47-
exception.expect(MissingAttachmentsException::class.java)
48-
exception.expectMessage("Uncatchable!")
49-
50-
val lazyList = (0 until 5).toList().lazyMapped<Int, Int> { _, _ ->
51-
throw MissingAttachmentsException(emptyList(), "Uncatchable!")
43+
val anException = assertThrows<MissingAttachmentsException> {
44+
val lazyList = (0 until 5).toList().lazyMapped<Int, Int> { _, _ ->
45+
throw MissingAttachmentsException(emptyList(), "Uncatchable!")
46+
}
47+
lazyList.eagerDeserialise { _, _ -> -999 }
5248
}
53-
54-
lazyList.eagerDeserialise { _, _ -> -999 }
49+
assertEquals("Uncatchable!", anException.message)
5550
}
5651

5752
@Test(timeout=300_000)

node-api-tests/src/test/kotlin/net/corda/nodeapitests/internal/network/NetworkBootstrapperTest.kt

+6-8
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ import org.junit.After
4040
import org.junit.AfterClass
4141
import org.junit.Rule
4242
import org.junit.Test
43-
import org.junit.rules.ExpectedException
43+
import org.junit.jupiter.api.assertThrows
4444
import org.junit.rules.TemporaryFolder
4545
import java.nio.file.Files
4646
import java.nio.file.Path
@@ -54,16 +54,13 @@ import kotlin.io.path.readBytes
5454
import kotlin.io.path.useDirectoryEntries
5555
import kotlin.io.path.writeBytes
5656
import kotlin.io.path.writeText
57+
import kotlin.test.assertEquals
5758

5859
class NetworkBootstrapperTest {
5960
@Rule
6061
@JvmField
6162
val tempFolder = TemporaryFolder()
6263

63-
@Rule
64-
@JvmField
65-
val expectedEx: ExpectedException = ExpectedException.none()
66-
6764
@Rule
6865
@JvmField
6966
val testSerialization = SerializationEnvironmentRule()
@@ -304,9 +301,10 @@ class NetworkBootstrapperTest {
304301
assertContainsPackageOwner("alice", mapOf(Pair(greedyNamespace, alice.publicKey)))
305302
// register overlapping package name
306303
createNodeConfFile("bob", bobConfig)
307-
expectedEx.expect(IllegalArgumentException::class.java)
308-
expectedEx.expectMessage("Multiple packages added to the packageOwnership overlap.")
309-
bootstrap(packageOwnership = mapOf(Pair(greedyNamespace, alice.publicKey), Pair(bobPackageName, bob.publicKey)))
304+
val anException = assertThrows<IllegalArgumentException> {
305+
bootstrap(packageOwnership = mapOf(Pair(greedyNamespace, alice.publicKey), Pair(bobPackageName, bob.publicKey)))
306+
}
307+
assertEquals("Multiple packages added to the packageOwnership overlap.", anException.message)
310308
}
311309

312310
@Test(timeout=300_000)

node/src/integration-test-slow/kotlin/net/corda/node/persistence/NodeStatePersistenceTests.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class NodeStatePersistenceTests {
6060
result
6161
}
6262
assertNotNull(stateAndRef)
63-
val retrievedMessage = stateAndRef!!.state.data.message
63+
val retrievedMessage = stateAndRef.state.data.message
6464
assertEquals(message, retrievedMessage)
6565
}
6666

@@ -96,7 +96,7 @@ class NodeStatePersistenceTests {
9696
result
9797
}
9898
assertNotNull(stateAndRef)
99-
val retrievedMessage = stateAndRef!!.state.data.message
99+
val retrievedMessage = stateAndRef.state.data.message
100100
assertEquals(message, retrievedMessage)
101101
}
102102
}

node/src/integration-test-slow/kotlin/net/corda/node/utilities/registration/NodeRegistrationTest.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ class NodeRegistrationTest {
6565
pollInterval = 1.seconds,
6666
hostAndPort = portAllocation.nextHostAndPort(),
6767
myHostNameValue = "localhost",
68-
additionalServices = *arrayOf(registrationHandler))
68+
additionalServices = arrayOf(registrationHandler))
6969
serverHostAndPort = server.start()
7070
}
7171

node/src/main/kotlin/net/corda/node/services/statemachine/StaffedFlowHospital.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -306,11 +306,11 @@ class StaffedFlowHospital(private val flowMessaging: FlowMessaging,
306306
log.info("Error ${index + 1} of ${errors.size}:", error)
307307
val diagnoses: Map<Diagnosis, List<Staff>> = staff.groupBy { it.consult(flowFiber, currentState, error, medicalHistory) }
308308
// We're only interested in the highest priority diagnosis for the error
309-
val (diagnosis, by) = diagnoses.entries.minBy { it.key }!!
309+
val (diagnosis, by) = diagnoses.entries.minBy { it.key }
310310
ConsultationReport(error, diagnosis, by)
311311
}
312312
// And we're only interested in the error with the highest priority diagnosis
313-
.minBy { it.diagnosis }!!
313+
.minBy { it.diagnosis }
314314
}
315315

316316
private data class ConsultationReport(val error: Throwable, val diagnosis: Diagnosis, val by: List<Staff>)

node/src/test/kotlin/net/corda/node/services/statemachine/FlowMetadataRecordingTest.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ class FlowMetadataRecordingTest {
412412
metadata!!.let {
413413
assertNull(it.finishInstant)
414414
assertNotNull(finishTime)
415-
assertTrue(finishTime!! >= it.startInstant)
415+
assertTrue(finishTime >= it.startInstant)
416416
}
417417
}
418418
}

node/src/test/kotlin/net/corda/node/services/vault/VaultQueryExceptionsTests.kt

-5
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import net.corda.testing.core.*
1111
import net.corda.testing.internal.vault.DummyLinearStateSchemaV1
1212
import org.assertj.core.api.Assertions.assertThatThrownBy
1313
import org.junit.*
14-
import org.junit.rules.ExpectedException
1514

1615
class VaultQueryExceptionsTests : VaultQueryParties by rule {
1716

@@ -30,10 +29,6 @@ class VaultQueryExceptionsTests : VaultQueryParties by rule {
3029
}
3130
}
3231

33-
@Rule
34-
@JvmField
35-
val expectedEx: ExpectedException = ExpectedException.none()
36-
3732
@Rule
3833
@JvmField
3934
val rollbackRule = VaultQueryRollbackRule(this)

node/src/test/kotlin/net/corda/node/services/vault/VaultQueryTests.kt

+31-34
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ import org.junit.ClassRule
4545
import org.junit.Ignore
4646
import org.junit.Rule
4747
import org.junit.Test
48-
import org.junit.rules.ExpectedException
48+
import org.junit.jupiter.api.Assertions.assertTrue
49+
import org.junit.jupiter.api.assertThrows
4950
import org.junit.rules.ExternalResource
5051
import java.time.Duration
5152
import java.time.Instant
@@ -148,7 +149,7 @@ open class VaultQueryTestRule(private val persistentServices: Boolean) : Externa
148149
cordappPackages,
149150
makeTestIdentityService(MEGA_CORP_IDENTITY, MINI_CORP_IDENTITY, dummyCashIssuer.identity, dummyNotary.identity),
150151
megaCorp,
151-
moreKeys = *arrayOf(DUMMY_NOTARY_KEY)
152+
moreKeys = arrayOf(DUMMY_NOTARY_KEY)
152153
)
153154
}
154155
database = databaseAndServices.first
@@ -184,10 +185,6 @@ class VaultQueryRollbackRule(private val vaultQueryParties: VaultQueryParties) :
184185

185186
abstract class VaultQueryTestsBase : VaultQueryParties {
186187

187-
@Rule
188-
@JvmField
189-
val expectedEx: ExpectedException = ExpectedException.none()
190-
191188
companion object {
192189
@ClassRule @JvmField
193190
val testSerialization = SerializationEnvironmentRule()
@@ -1006,10 +1003,11 @@ abstract class VaultQueryTestsBase : VaultQueryParties {
10061003
assertThat(resultsUnlockedAndByLockIds.states).hasSize(5)
10071004

10081005
// missing lockId
1009-
expectedEx.expect(VaultQueryException::class.java)
1010-
expectedEx.expectMessage("Must specify one or more lockIds")
1011-
val criteriaMissingLockId = VaultQueryCriteria(softLockingCondition = SoftLockingCondition(SoftLockingType.UNLOCKED_AND_SPECIFIED))
1012-
vaultService.queryBy<ContractState>(criteriaMissingLockId)
1006+
val anException = assertThrows<VaultQueryException> {
1007+
val criteriaMissingLockId = VaultQueryCriteria(softLockingCondition = SoftLockingCondition(SoftLockingType.UNLOCKED_AND_SPECIFIED))
1008+
vaultService.queryBy<ContractState>(criteriaMissingLockId)
1009+
}
1010+
anException.message?.let { assertTrue(it.contains("Must specify one or more lockIds")) }
10131011
}
10141012
}
10151013

@@ -1707,44 +1705,43 @@ abstract class VaultQueryTestsBase : VaultQueryParties {
17071705
// pagination: invalid page number
17081706
@Test(timeout=300_000)
17091707
fun `invalid page number`() {
1710-
expectedEx.expect(VaultQueryException::class.java)
1711-
expectedEx.expectMessage("Page specification: invalid page number")
1712-
1713-
database.transaction {
1714-
vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, 100, DUMMY_CASH_ISSUER)
1715-
val pagingSpec = PageSpecification(0, 10)
1716-
1717-
val criteria = VaultQueryCriteria(status = Vault.StateStatus.ALL)
1718-
vaultService.queryBy<ContractState>(criteria, paging = pagingSpec)
1708+
val anException = assertThrows<VaultQueryException> {
1709+
database.transaction {
1710+
vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, 100, DUMMY_CASH_ISSUER)
1711+
val pagingSpec = PageSpecification(0, 10)
1712+
val criteria = VaultQueryCriteria(status = Vault.StateStatus.ALL)
1713+
vaultService.queryBy<ContractState>(criteria, paging = pagingSpec)
1714+
}
17191715
}
1716+
anException.message?.let { assertTrue(it.contains("Page specification: invalid page number")) }
17201717
}
17211718

17221719
// pagination: invalid page size
17231720
@Suppress("INTEGER_OVERFLOW")
17241721
@Test(timeout=300_000)
17251722
fun `invalid page size`() {
1726-
expectedEx.expect(VaultQueryException::class.java)
1727-
expectedEx.expectMessage("Page specification: invalid page size")
1728-
1729-
database.transaction {
1730-
vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, 100, DUMMY_CASH_ISSUER)
1731-
val pagingSpec = PageSpecification(DEFAULT_PAGE_NUM, Integer.MAX_VALUE + 1) // overflow = -2147483648
1732-
val criteria = VaultQueryCriteria(status = Vault.StateStatus.ALL)
1733-
vaultService.queryBy<ContractState>(criteria, paging = pagingSpec)
1723+
val anException = assertThrows<VaultQueryException> {
1724+
database.transaction {
1725+
vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, 100, DUMMY_CASH_ISSUER)
1726+
val pagingSpec = PageSpecification(DEFAULT_PAGE_NUM, Integer.MAX_VALUE + 1) // overflow = -2147483648
1727+
val criteria = VaultQueryCriteria(status = Vault.StateStatus.ALL)
1728+
vaultService.queryBy<ContractState>(criteria, paging = pagingSpec)
1729+
}
17341730
}
1731+
anException.message?.let { assertTrue(it.contains("Page specification: invalid page size")) }
17351732
}
17361733

17371734
// pagination not specified but more than DEFAULT_PAGE_SIZE results available (fail-fast test)
17381735
@Test(timeout=300_000)
17391736
fun `pagination not specified but more than default results available`() {
1740-
expectedEx.expect(VaultQueryException::class.java)
1741-
expectedEx.expectMessage("provide a PageSpecification")
1742-
1743-
database.transaction {
1744-
vaultFiller.fillWithSomeTestCash(201.DOLLARS, notaryServices, 201, DUMMY_CASH_ISSUER)
1745-
val criteria = VaultQueryCriteria(status = Vault.StateStatus.ALL)
1746-
vaultService.queryBy<ContractState>(criteria)
1737+
val anException = assertThrows<VaultQueryException> {
1738+
database.transaction {
1739+
vaultFiller.fillWithSomeTestCash(201.DOLLARS, notaryServices, 201, DUMMY_CASH_ISSUER)
1740+
val criteria = VaultQueryCriteria(status = Vault.StateStatus.ALL)
1741+
vaultService.queryBy<ContractState>(criteria)
1742+
}
17471743
}
1744+
anException.message?.let { assertTrue(it.contains("provide a PageSpecification")) }
17481745
}
17491746

17501747
// example of querying states with paging using totalStatesAvailable

node/src/test/kotlin/net/corda/node/services/vault/VaultWithCashTest.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ class VaultWithCashTest {
8383
makeTestIdentityService(MEGA_CORP_IDENTITY, MINI_CORP_IDENTITY, dummyCashIssuer.identity, dummyNotary.identity),
8484
TestIdentity(MEGA_CORP.name, servicesKey),
8585
networkParameters,
86-
moreKeys = *arrayOf(dummyNotary.keyPair))
86+
moreKeys = arrayOf(dummyNotary.keyPair))
8787
database = databaseAndServices.first
8888
services = databaseAndServices.second
8989
vaultFiller = VaultFiller(services, dummyNotary)

samples/simm-valuation-demo/flows/src/main/kotlin/net/corda/vega/flows/SimmFlow.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ object SimmFlow {
131131

132132
val valuer = serviceHub.identityService.wellKnownPartyFromAnonymous(state.valuer)
133133
require(valuer != null) { "Valuer party must be known to this node" }
134-
val valuation = agreeValuation(portfolio, valuationDate, valuer!!)
134+
val valuation = agreeValuation(portfolio, valuationDate, valuer)
135135
val update = PortfolioState.Update(valuation = valuation)
136136
return subFlow(StateRevisionFlowRequester(otherPartySession, stateRef, update)).state.data
137137
}

samples/simm-valuation-demo/flows/src/main/kotlin/net/corda/vega/flows/SimmRevaluation.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ object SimmRevaluation {
2525
if (ourIdentity == curState.participants[0]) {
2626
val otherParty = serviceHub.identityService.wellKnownPartyFromAnonymous(curState.participants[1])
2727
require(otherParty != null) { "Other party must be known by this node" }
28-
subFlow(SimmFlow.Requester(otherParty!!, valuationDate, stateAndRef))
28+
subFlow(SimmFlow.Requester(otherParty, valuationDate, stateAndRef))
2929
}
3030
}
3131
}

0 commit comments

Comments
 (0)