Skip to content

Commit 9b79479

Browse files
ENT-11351 - Compiler warnings pass 4 (corda#7663)
* Compiler warnings * Resolve detekt errors * Reverted code change; added warning suppression * Address PR review comments
1 parent a7d0684 commit 9b79479

File tree

19 files changed

+39
-26
lines changed

19 files changed

+39
-26
lines changed

client/jackson/src/main/kotlin/net/corda/client/jackson/JacksonSupport.kt

+1-2
Original file line numberDiff line numberDiff line change
@@ -315,8 +315,7 @@ object JacksonSupport {
315315

316316
private class CertPathSerializer : JsonSerializer<CertPath>() {
317317
override fun serialize(value: CertPath, gen: JsonGenerator, serializers: SerializerProvider) {
318-
val certificates = value.certificates as List<X509Certificate>
319-
gen.writeObject(CertPathWrapper(value.type, certificates))
318+
gen.writeObject(CertPathWrapper(value.type, uncheckedCast(value.certificates)))
320319
}
321320
}
322321

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ class FastThreadLocalTest {
8585
}
8686

8787
private class UnserializableObj {
88-
@Suppress("unused")
88+
@Suppress("unused", "IMPLICIT_NOTHING_TYPE_ARGUMENT_IN_RETURN_POSITION")
8989
private val fail: Nothing by lazy { throw UnsupportedOperationException("Nice try.") }
9090
}
9191

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ class FlowExternalOperationTest : AbstractFlowExternalOperationTest() {
257257
@Suspendable
258258
override fun testCode() {
259259
val e = createException()
260-
await(ExternalOperation(serviceHub, (SerializableLambda2 { _, _ -> throw e })))
260+
await<Nothing>(ExternalOperation(serviceHub, (SerializableLambda2 { _, _ -> throw e })))
261261
}
262262

263263
private fun createException() = when (exceptionType) {
@@ -273,7 +273,7 @@ class FlowExternalOperationTest : AbstractFlowExternalOperationTest() {
273273

274274
@Suspendable
275275
override fun testCode(): Any = try {
276-
await(ExternalOperation(serviceHub) { _, _ ->
276+
await<Nothing>(ExternalOperation(serviceHub) { _, _ ->
277277
throw IllegalStateException("threw exception in background process")
278278
})
279279
} catch (e: IllegalStateException) {
@@ -287,7 +287,7 @@ class FlowExternalOperationTest : AbstractFlowExternalOperationTest() {
287287

288288
@Suspendable
289289
override fun testCode(): Any =
290-
await(ExternalOperation(serviceHub) { serviceHub, _ ->
290+
await<Nothing>(ExternalOperation(serviceHub) { serviceHub, _ ->
291291
serviceHub.cordaService(FutureService::class.java).throwHospitalHandledException()
292292
})
293293
}
@@ -298,7 +298,7 @@ class FlowExternalOperationTest : AbstractFlowExternalOperationTest() {
298298
@Suspendable
299299
override fun testCode(): Any {
300300
try {
301-
await(ExternalOperation(serviceHub) { _, _ ->
301+
await<Nothing>(ExternalOperation(serviceHub) { _, _ ->
302302
serviceHub.cordaService(FutureService::class.java).throwHospitalHandledException()
303303
})
304304
} catch (e: NullPointerException) {

experimental/blobwriter/src/main/kotlin/net/corda/blobwriter/BlobWriter.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,12 @@ data class _L_i__ (val listy: List<_i_>)
7474

7575
data class _ALd_ (val a: Array<List<Double>>)
7676

77-
@Suppress("UNUSED_PARAMETER")
77+
@Suppress("UNUSED_PARAMETER", "PLATFORM_CLASS_MAPPED_TO_KOTLIN")
7878
fun main (args: Array<String>) {
7979
initialiseSerialization()
8080
val path = "../cpp-serializer/bin/test-files";
8181
File("$path/_i_").writeBytes (_i_ (69).serialize().bytes)
82-
File("$path/_Oi_").writeBytes (_Oi_ (Integer (1)).serialize().bytes)
82+
File("$path/_Oi_").writeBytes (_Oi_ (Integer.valueOf (1) as Integer).serialize().bytes)
8383
File("$path/_l_").writeBytes (_l_ (100000000000L).serialize().bytes)
8484
File("$path/_Li_").writeBytes (_Li_(listOf (1, 2, 3, 4, 5, 6)).serialize().bytes)
8585
File("$path/_Ai_").writeBytes (_Ai_(arrayOf (1, 2, 3, 4, 5, 6)).serialize().bytes)

finance/workflows/src/main/kotlin/net/corda/finance/workflows/asset/selection/AbstractCashSelection.kt

+1
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ abstract class AbstractCashSelection(private val maxRetries : Int = 8, private v
138138

139139
if (stateRefs.isNotEmpty()) {
140140
// TODO: future implementation to retrieve contract states from a Vault BLOB store
141+
@Suppress("UNCHECKED_CAST")
141142
stateAndRefs.addAll(services.loadStates(stateRefs) as Collection<out StateAndRef<Cash.State>>)
142143
}
143144

node-api/src/main/kotlin/net/corda/nodeapi/internal/crypto/X509Utilities.kt

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import net.corda.core.crypto.newSecureRandom
88
import net.corda.core.internal.CertRole
99
import net.corda.core.internal.SignedDataWithCert
1010
import net.corda.core.internal.signWithCert
11+
import net.corda.core.internal.uncheckedCast
1112
import net.corda.core.internal.validate
1213
import net.corda.core.utilities.days
1314
import net.corda.core.utilities.millis
@@ -424,7 +425,7 @@ val CertPath.x509Certificates: List<X509Certificate>
424425
get() {
425426
require(type == "X.509") { "Not an X.509 cert path: $this" }
426427
// We're not mapping the list to avoid creating a new one.
427-
return certificates as List<X509Certificate>
428+
return uncheckedCast(certificates)
428429
}
429430

430431
val Certificate.x509: X509Certificate get() = requireNotNull(this as? X509Certificate) { "Not an X.509 certificate: $this" }

node-api/src/main/kotlin/net/corda/nodeapi/internal/serialization/kryo/Kryo.kt

+2-1
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,8 @@ class ThrowableSerializer<T>(kryo: Kryo, type: Class<T>) : Serializer<Throwable>
490490
}
491491
}
492492

493-
private val delegate: Serializer<Throwable> = uncheckedCast(SerializerFactory.ReflectionSerializerFactory.newSerializer(kryo, FieldSerializer::class.java, type)) as Serializer<Throwable>
493+
@Suppress("UNCHECKED_CAST")
494+
private val delegate: Serializer<Throwable> = SerializerFactory.ReflectionSerializerFactory.newSerializer(kryo, FieldSerializer::class.java, type) as Serializer<Throwable>
494495

495496
override fun write(kryo: Kryo, output: Output, throwable: Throwable) {
496497
delegate.write(kryo, output, throwable)

node/src/main/kotlin/net/corda/node/services/messaging/NodeSSLContextFactory.kt

+9-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import org.apache.activemq.artemis.core.remoting.impl.ssl.DefaultOpenSSLContextF
99
import org.apache.activemq.artemis.core.remoting.impl.ssl.DefaultSSLContextFactory
1010
import org.apache.activemq.artemis.spi.core.remoting.ssl.SSLContextConfig
1111
import org.apache.activemq.artemis.utils.ClassloadingUtil
12-
import org.apache.commons.io.IOUtils
1312
import java.io.File
1413
import java.io.InputStream
1514
import java.net.MalformedURLException
@@ -125,4 +124,12 @@ private fun findResource(resourceName: String): URL {
125124
* This is an inline function for [InputStream] so it can be closed and
126125
* ignore an exception.
127126
*/
128-
private fun InputStream?.closeQuietly() = IOUtils.closeQuietly(this)
127+
private fun InputStream?.closeQuietly() {
128+
try {
129+
this?.close()
130+
}
131+
catch ( ex : Exception ) {
132+
// quietly absorb problems
133+
}
134+
}
135+

node/src/main/kotlin/net/corda/node/services/persistence/AbstractPartyDescriptor.kt

+2-1
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,14 @@ class AbstractPartyDescriptor(private val wellKnownPartyFromX500Name: (CordaX500
5252
}
5353
}
5454

55+
@Suppress("UNCHECKED_CAST")
5556
override fun <X : Any> unwrap(value: AbstractParty?, type: Class<X>, options: WrapperOptions): X? {
5657
return if (value != null) {
5758
if (AbstractParty::class.java.isAssignableFrom(type)) {
5859
return uncheckedCast(value)
5960
}
6061
if (String::class.java.isAssignableFrom(type)) {
61-
return uncheckedCast(toString(value)) as X?
62+
return toString(value) as X?
6263
}
6364
throw unknownUnwrap(type)
6465
} else {

node/src/main/kotlin/net/corda/node/services/rpc/CheckpointDumperImpl.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ import net.corda.core.internal.FlowIORequest
3838
import net.corda.core.internal.WaitForStateConsumption
3939
import net.corda.core.internal.declaredField
4040
import net.corda.core.internal.objectOrNewInstance
41-
import net.corda.core.internal.uncheckedCast
4241
import net.corda.core.node.AppServiceHub.Companion.SERVICE_PRIORITY_NORMAL
4342
import net.corda.core.node.ServiceHub
4443
import net.corda.core.serialization.SerializeAsToken
@@ -594,6 +593,7 @@ class CheckpointDumperImpl(private val checkpointStorage: CheckpointStorage, pri
594593
gen.writeEndArray()
595594
}
596595

597-
override fun handledType(): Class<Map<Any, Any>> = uncheckedCast(Map::class.java) as Class<Map<Any, Any>>
596+
@Suppress("UNCHECKED_CAST")
597+
override fun handledType(): Class<Map<Any, Any>> = Map::class.java as Class<Map<Any, Any>>
598598
}
599599
}

node/src/main/kotlin/net/corda/node/services/rpc/RpcBrokerConfiguration.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ internal class RpcBrokerConfiguration(baseDirectory: Path, maxMessageSize: Int,
4040
queueConfigs = queueConfigurations()
4141

4242
managementNotificationAddress = SimpleString(ArtemisMessagingComponent.NOTIFICATIONS_ADDRESS)
43-
addressesSettings = mapOf(
43+
addressSettings = mapOf(
4444
"${RPCApi.RPC_CLIENT_QUEUE_NAME_PREFIX}.#" to AddressSettings().apply {
4545
maxSizeBytes = 5L * maxMessageSize
4646
addressFullMessagePolicy = AddressFullMessagePolicy.PAGE

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

+1
Original file line numberDiff line numberDiff line change
@@ -1239,6 +1239,7 @@ internal class SingleThreadedStateMachineManager(
12391239
null
12401240
} else {
12411241
val existingFuture = activeOrRemovedClientIdFutureForReattach(it, clientId)
1242+
@Suppress("UNCHECKED_CAST")
12421243
existingFuture?.let {existingFuture.get() } as FlowStateMachineHandle<T>
12431244
}
12441245
}

node/src/main/kotlin/net/corda/node/services/vault/NodeVaultService.kt

+2-1
Original file line numberDiff line numberDiff line change
@@ -839,7 +839,8 @@ class NodeVaultService(
839839
@Throws(VaultQueryException::class)
840840
override fun <T : ContractState> _trackBy(criteria: QueryCriteria, paging: PageSpecification, sorting: Sort, contractStateType: Class<out T>): DataFeed<Vault.Page<T>, Vault.Update<T>> {
841841
return mutex.locked {
842-
val updates: Observable<Vault.Update<T>> = uncheckedCast(_updatesPublisher.bufferUntilSubscribed()) as Observable<Vault.Update<T>>
842+
@Suppress("UNCHECKED_CAST")
843+
val updates: Observable<Vault.Update<T>> = _updatesPublisher.bufferUntilSubscribed() as Observable<Vault.Update<T>>
843844
if (contextTransactionOrNull != null) {
844845
log.warn("trackBy is called with an already existing, open DB transaction. As a result, there might be states missing from both the snapshot and observable, included in the returned data feed, because of race conditions.")
845846
}

node/src/main/kotlin/net/corda/notary/experimental/bftsmart/BFTSmart.kt

+2-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import net.corda.core.internal.notary.NotaryInternalException
2626
import net.corda.core.internal.notary.isConsumedByTheSameTx
2727
import net.corda.core.internal.notary.validateTimeWindow
2828
import net.corda.core.internal.toTypedArray
29+
import net.corda.core.internal.uncheckedCast
2930
import net.corda.core.schemas.PersistentStateRef
3031
import net.corda.core.serialization.CordaSerializable
3132
import net.corda.core.serialization.SingletonSerializeAsToken
@@ -215,7 +216,7 @@ object BFTSmart {
215216
}
216217

217218
override fun appExecuteBatch(command: Array<ByteArray>, mcs: Array<MessageContext>): Array<ByteArray?> {
218-
return Arrays.stream(command).map(this::executeCommand).toTypedArray() as Array<ByteArray?>
219+
return uncheckedCast(Arrays.stream(command).map(this::executeCommand).toTypedArray())
219220
}
220221

221222
/**

node/src/test/kotlin/net/corda/node/CordaRPCOpsImplTest.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import net.corda.core.flows.StartableByRPC
1515
import net.corda.core.flows.StateMachineRunId
1616
import net.corda.core.identity.Party
1717
import net.corda.core.internal.RPC_UPLOADER
18-
import net.corda.core.internal.uncheckedCast
1918
import net.corda.core.messaging.CordaRPCOps
2019
import net.corda.core.messaging.StateMachineUpdate
2120
import net.corda.core.messaging.startFlow
@@ -408,7 +407,8 @@ class CordaRPCOpsImplTest {
408407
@Test(timeout=300_000)
409408
fun `non-ContractState class for the contractStateType param in vault queries`() {
410409
CURRENT_RPC_CONTEXT.set(RpcAuthContext(InvocationContext.rpc(testActor()), buildSubject("TEST_USER", emptySet())))
411-
val nonContractStateClass = uncheckedCast(Cash::class.java) as Class<ContractState>
410+
@Suppress("UNCHECKED_CAST")
411+
val nonContractStateClass = Cash::class.java as Class<ContractState>
412412
withPermissions(invokeRpc("vaultTrack"), invokeRpc("vaultQuery")) {
413413
assertThatThrownBy { rpc.vaultQuery(nonContractStateClass) }.hasMessageContaining(Cash::class.java.name)
414414
assertThatThrownBy { rpc.vaultTrack(nonContractStateClass) }.hasMessageContaining(Cash::class.java.name)

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -598,7 +598,7 @@ class FlowClientIdTests {
598598
@Test(timeout = 300_000)
599599
fun `flow that fails does not retain its checkpoint nor its exception in the database if not started with a client id`() {
600600
assertFailsWith<IllegalStateException> {
601-
aliceNode.services.startFlow(ExceptionFlow { IllegalStateException("another exception") }).resultFuture.getOrThrow()
601+
aliceNode.services.startFlow(ExceptionFlow { IllegalStateException("another exception") }).resultFuture.getOrThrow<Nothing>()
602602
}
603603

604604
aliceNode.services.database.transaction {

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -775,7 +775,7 @@ class FlowFrameworkTests {
775775
assertFailsWith<TimeoutException> {
776776
val fiber = aliceNode.services.startFlow(ExceptionFlow { HospitalizeFlowException("Overnight observation") })
777777
flowId = fiber.id
778-
fiber.resultFuture.getOrThrow(10.seconds)
778+
fiber.resultFuture.getOrThrow<Nothing>(10.seconds)
779779
}
780780

781781
aliceNode.database.transaction {

testing/node-driver/src/main/kotlin/net/corda/testing/node/internal/RPCDriver.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ data class RPCDriverDSL(
204204
QueueConfiguration(RPCApi.RPC_CLIENT_BINDING_ADDITIONS).setAddress(NOTIFICATION_ADDRESS)
205205
.setFilterString(RPCApi.RPC_CLIENT_BINDING_ADDITION_FILTER_EXPRESSION).setDurable(false)
206206
)
207-
addressesSettings = mapOf(
207+
addressSettings = mapOf(
208208
"${RPCApi.RPC_CLIENT_QUEUE_NAME_PREFIX}.#" to AddressSettings().apply {
209209
maxSizeBytes = maxBufferedBytesPerClient
210210
addressFullMessagePolicy = AddressFullMessagePolicy.PAGE

testing/testserver/src/main/kotlin/net/corda/webserver/converters/Converters.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package net.corda.webserver.converters
22

33
import net.corda.core.identity.CordaX500Name
4-
import net.corda.core.internal.uncheckedCast
54
import java.lang.reflect.Type
65
import javax.ws.rs.ext.ParamConverter
76
import javax.ws.rs.ext.ParamConverterProvider
@@ -14,9 +13,10 @@ object CordaX500NameConverter : ParamConverter<CordaX500Name> {
1413

1514
@Provider
1615
object CordaConverterProvider : ParamConverterProvider {
16+
@Suppress("UNCHECKED_CAST")
1717
override fun <T : Any> getConverter(rawType: Class<T>, genericType: Type?, annotations: Array<out Annotation>?): ParamConverter<T>? {
1818
if (rawType == CordaX500Name::class.java) {
19-
return uncheckedCast(CordaX500NameConverter) as ParamConverter<T>?
19+
return CordaX500NameConverter as ParamConverter<T>?
2020
}
2121
return null
2222
}

0 commit comments

Comments
 (0)