mirror of
https://github.com/corda/corda.git
synced 2025-06-23 09:25:36 +00:00
TM-23 Fail build on compiler warnings (#5453)
* java compile respects compilation.allWarningsAsErrors * suppress or cleanup warnings * suppress warning * use non-deprecated kotlin dependency * rename property * handle property existence check * Deal with warnings
This commit is contained in:
@ -12,7 +12,7 @@ import rx.Observer
|
||||
// TODO Delete this file once the Future stuff is out of here
|
||||
|
||||
fun <A> CordaFuture<out A>.toObservable(): Observable<A> {
|
||||
return Observable.create { subscriber ->
|
||||
return Observable.unsafeCreate { subscriber ->
|
||||
thenMatch({
|
||||
subscriber.onNext(it)
|
||||
subscriber.onCompleted()
|
||||
|
@ -42,8 +42,14 @@ fun <C : CommandData> Collection<CommandWithParties<CommandData>>.select(klass:
|
||||
party: AbstractParty? = null) =
|
||||
mapNotNull { if (klass.isInstance(it.value)) uncheckedCast<CommandWithParties<CommandData>, CommandWithParties<C>>(it) else null }.
|
||||
filter { if (signer == null) true else signer in it.signers }.
|
||||
filter { if (party == null) true else party in it.signingParties }.
|
||||
map { CommandWithParties(it.signers, it.signingParties, it.value) }
|
||||
filter {
|
||||
@Suppress("DEPRECATION")
|
||||
if (party == null) true else party in it.signingParties
|
||||
}.
|
||||
map {
|
||||
@Suppress("DEPRECATION")
|
||||
CommandWithParties(it.signers, it.signingParties, it.value)
|
||||
}
|
||||
|
||||
/** Filters the command list by type, parties and public keys all at once. */
|
||||
inline fun <reified T : CommandData> Collection<CommandWithParties<CommandData>>.select(signers: Collection<PublicKey>?,
|
||||
@ -56,8 +62,14 @@ fun <C : CommandData> Collection<CommandWithParties<CommandData>>.select(klass:
|
||||
parties: Collection<Party>?) =
|
||||
mapNotNull { if (klass.isInstance(it.value)) uncheckedCast<CommandWithParties<CommandData>, CommandWithParties<C>>(it) else null }.
|
||||
filter { if (signers == null) true else it.signers.containsAll(signers) }.
|
||||
filter { if (parties == null) true else it.signingParties.containsAll(parties) }.
|
||||
map { CommandWithParties(it.signers, it.signingParties, it.value) }
|
||||
filter {
|
||||
@Suppress("DEPRECATION")
|
||||
if (parties == null) true else it.signingParties.containsAll(parties)
|
||||
}.
|
||||
map {
|
||||
@Suppress("DEPRECATION")
|
||||
CommandWithParties(it.signers, it.signingParties, it.value)
|
||||
}
|
||||
|
||||
/** Ensures that a transaction has only one command that is of the given type, otherwise throws an exception. */
|
||||
inline fun <reified T : CommandData> Collection<CommandWithParties<CommandData>>.requireSingleCommand() = requireSingleCommand(T::class.java)
|
||||
|
@ -48,10 +48,15 @@ val ContractState.requiredContractClassName: String? get() {
|
||||
*/
|
||||
fun AttachmentConstraint.canBeTransitionedFrom(input: AttachmentConstraint, attachment: ContractAttachment): Boolean {
|
||||
val output = this
|
||||
|
||||
@Suppress("DEPRECATION")
|
||||
fun AttachmentConstraint.isAutomaticHashConstraint() =
|
||||
this is AutomaticHashConstraint
|
||||
|
||||
return when {
|
||||
// These branches should not happen, as this has been already checked.
|
||||
input is AutomaticPlaceholderConstraint || output is AutomaticPlaceholderConstraint -> throw IllegalArgumentException("Illegal constraint: AutomaticPlaceholderConstraint.")
|
||||
input is AutomaticHashConstraint || output is AutomaticHashConstraint -> throw IllegalArgumentException("Illegal constraint: AutomaticHashConstraint.")
|
||||
input.isAutomaticHashConstraint() || output.isAutomaticHashConstraint() -> throw IllegalArgumentException("Illegal constraint: AutomaticHashConstraint.")
|
||||
|
||||
// Transition to the same constraint.
|
||||
input == output -> true
|
||||
|
@ -97,10 +97,12 @@ class TransactionDeserialisationException(groupEnum: ComponentGroupEnum, index:
|
||||
*
|
||||
* This method used the [deserialiseComponentGroup] method.
|
||||
*/
|
||||
fun deserialiseCommands(componentGroups: List<ComponentGroup>,
|
||||
forceDeserialize: Boolean = false,
|
||||
factory: SerializationFactory = SerializationFactory.defaultFactory,
|
||||
context: SerializationContext = factory.defaultContext): List<Command<*>> {
|
||||
fun deserialiseCommands(
|
||||
componentGroups: List<ComponentGroup>,
|
||||
forceDeserialize: Boolean = false,
|
||||
factory: SerializationFactory = SerializationFactory.defaultFactory,
|
||||
@Suppress("UNUSED_PARAMETER") context: SerializationContext = factory.defaultContext
|
||||
): List<Command<*>> {
|
||||
// TODO: we could avoid deserialising unrelated signers.
|
||||
// However, current approach ensures the transaction is not malformed
|
||||
// and it will throw if any of the signers objects is not List of public keys).
|
||||
|
@ -48,6 +48,7 @@ interface IdentityService {
|
||||
*/
|
||||
@Throws(UnknownAnonymousPartyException::class)
|
||||
fun assertOwnership(party: Party, anonymousParty: AnonymousParty) {
|
||||
@Suppress("DEPRECATION")
|
||||
val anonymousIdentity = certificateFromKey(anonymousParty.owningKey)
|
||||
?: throw UnknownAnonymousPartyException("Unknown $anonymousParty")
|
||||
val issuingCert = anonymousIdentity.certPath.certificates[1]
|
||||
@ -79,7 +80,9 @@ interface IdentityService {
|
||||
* @param key The owning [PublicKey] of the [Party].
|
||||
* @return Returns a [Party] with a matching owningKey if known, else returns null.
|
||||
*/
|
||||
fun partyFromKey(key: PublicKey): Party? = certificateFromKey(key)?.party
|
||||
fun partyFromKey(key: PublicKey): Party? =
|
||||
@Suppress("DEPRECATION")
|
||||
certificateFromKey(key)?.party
|
||||
|
||||
/**
|
||||
* Resolves a party name to the well known identity [Party] instance for this name. Where possible well known identity
|
||||
|
@ -390,5 +390,7 @@ private constructor(
|
||||
privacySalt: PrivacySalt = this.privacySalt,
|
||||
sigs: List<TransactionSignature> = this.sigs,
|
||||
networkParameters: NetworkParameters = this.networkParameters
|
||||
) = ContractUpgradeLedgerTransaction(inputs, notary, legacyContractAttachment, upgradedContractClassName, upgradedContractAttachment, id, privacySalt, sigs, networkParameters)
|
||||
) =
|
||||
@Suppress("DEPRECATION")
|
||||
ContractUpgradeLedgerTransaction(inputs, notary, legacyContractAttachment, upgradedContractClassName, upgradedContractAttachment, id, privacySalt, sigs, networkParameters)
|
||||
}
|
@ -98,7 +98,11 @@ data class NotaryChangeWireTransaction(
|
||||
* TODO - currently this uses the main classloader.
|
||||
*/
|
||||
@CordaInternal
|
||||
internal fun resolveOutputComponent(services: ServicesForResolution, stateRef: StateRef, params: NetworkParameters): SerializedBytes<TransactionState<ContractState>> {
|
||||
internal fun resolveOutputComponent(
|
||||
services: ServicesForResolution,
|
||||
stateRef: StateRef,
|
||||
@Suppress("UNUSED_PARAMETER") params: NetworkParameters
|
||||
): SerializedBytes<TransactionState<ContractState>> {
|
||||
return services.loadState(stateRef).serialize()
|
||||
}
|
||||
|
||||
|
@ -246,7 +246,9 @@ open class TransactionBuilder(
|
||||
* TODO also on the versions of the attachments of the transactions generating the input states. ( after we add versioning)
|
||||
*/
|
||||
private fun selectContractAttachmentsAndOutputStateConstraints(
|
||||
services: ServicesForResolution, serializationContext: SerializationContext?): Pair<Collection<SecureHash>, List<TransactionState<ContractState>>> {
|
||||
services: ServicesForResolution,
|
||||
@Suppress("UNUSED_PARAMETER") serializationContext: SerializationContext?
|
||||
): Pair<Collection<SecureHash>, List<TransactionState<ContractState>>> {
|
||||
|
||||
// Determine the explicitly set contract attachments.
|
||||
val explicitAttachmentContracts: List<Pair<ContractClassName, SecureHash>> = this.attachments
|
||||
@ -297,7 +299,10 @@ open class TransactionBuilder(
|
||||
return Pair(attachments, resolvedOutputStatesInTheOriginalOrder)
|
||||
}
|
||||
|
||||
private val automaticConstraints = setOf(AutomaticPlaceholderConstraint, AutomaticHashConstraint)
|
||||
private val automaticConstraints = setOf(
|
||||
AutomaticPlaceholderConstraint,
|
||||
@Suppress("DEPRECATION") AutomaticHashConstraint
|
||||
)
|
||||
|
||||
/**
|
||||
* Selects an attachment and resolves the constraints for the output states with [AutomaticPlaceholderConstraint].
|
||||
|
@ -107,7 +107,6 @@ class WireTransaction(componentGroups: List<ComponentGroup>, val privacySalt: Pr
|
||||
val hashToResolve = it ?: services.networkParametersService.defaultHash
|
||||
services.networkParametersService.lookup(hashToResolve)
|
||||
},
|
||||
resolveContractAttachment = { services.loadContractAttachment(it) },
|
||||
// `as?` is used due to [MockServices] not implementing [ServiceHubCoreInternal]
|
||||
isAttachmentTrusted = { (services as? ServiceHubCoreInternal)?.attachmentTrustCalculator?.calculate(it) ?: true }
|
||||
)
|
||||
@ -115,6 +114,7 @@ class WireTransaction(componentGroups: List<ComponentGroup>, val privacySalt: Pr
|
||||
|
||||
// Helper for deprecated toLedgerTransaction
|
||||
// TODO: revisit once Deterministic JVM code updated
|
||||
@Suppress("UNUSED") // not sure if this field can be removed safely??
|
||||
private val missingAttachment: Attachment by lazy {
|
||||
object : AbstractAttachment({ byteArrayOf() }, DEPLOYED_CORDAPP_UPLOADER ) {
|
||||
override val id: SecureHash get() = throw UnsupportedOperationException()
|
||||
@ -143,8 +143,6 @@ class WireTransaction(componentGroups: List<ComponentGroup>, val privacySalt: Pr
|
||||
resolveAttachment,
|
||||
{ stateRef -> resolveStateRef(stateRef)?.serialize() },
|
||||
{ null },
|
||||
// Returning a dummy `missingAttachment` Attachment allows this deprecated method to work and it disables "contract version no downgrade rule" as a dummy Attachment returns version 1
|
||||
{ resolveAttachment(it.txhash) ?: missingAttachment },
|
||||
{ it.isUploaderTrusted() }
|
||||
)
|
||||
}
|
||||
@ -161,7 +159,6 @@ class WireTransaction(componentGroups: List<ComponentGroup>, val privacySalt: Pr
|
||||
resolveAttachment,
|
||||
{ stateRef -> resolveStateRef(stateRef)?.serialize() },
|
||||
resolveParameters,
|
||||
{ resolveAttachment(it.txhash) ?: missingAttachment },
|
||||
{ true } // Any attachment loaded through the DJVM should be trusted
|
||||
)
|
||||
}
|
||||
@ -171,7 +168,6 @@ class WireTransaction(componentGroups: List<ComponentGroup>, val privacySalt: Pr
|
||||
resolveAttachment: (SecureHash) -> Attachment?,
|
||||
resolveStateRefAsSerialized: (StateRef) -> SerializedBytes<TransactionState<ContractState>>?,
|
||||
resolveParameters: (SecureHash?) -> NetworkParameters?,
|
||||
resolveContractAttachment: (StateRef) -> Attachment,
|
||||
isAttachmentTrusted: (Attachment) -> Boolean
|
||||
): LedgerTransaction {
|
||||
// Look up public keys to authenticated identities.
|
||||
|
@ -4,8 +4,6 @@ import com.nhaarman.mockito_kotlin.mock
|
||||
import org.assertj.core.api.Assertions.assertThat
|
||||
import org.assertj.core.api.Assertions.assertThatThrownBy
|
||||
import org.junit.Test
|
||||
import java.lang.IllegalArgumentException
|
||||
import java.lang.RuntimeException
|
||||
|
||||
class ClassLoadingUtilsTest {
|
||||
|
||||
@ -33,7 +31,7 @@ class ClassLoadingUtilsTest {
|
||||
|
||||
@Test(expected = IllegalArgumentException::class)
|
||||
fun throwsExceptionWhenClassDoesNotContainProperConstructors() {
|
||||
val classes = createInstancesOfClassesImplementing(BaseInterface::class.java.classLoader, BaseInterface2::class.java)
|
||||
createInstancesOfClassesImplementing(BaseInterface::class.java.classLoader, BaseInterface2::class.java)
|
||||
}
|
||||
|
||||
@Test
|
||||
|
Reference in New Issue
Block a user