diff --git a/core/src/main/kotlin/net/corda/core/concurrent/ConcurrencyUtils.kt b/core/src/main/kotlin/net/corda/core/concurrent/ConcurrencyUtils.kt index 8ab4d6f4e1..3ebef1c7b3 100644 --- a/core/src/main/kotlin/net/corda/core/concurrent/ConcurrencyUtils.kt +++ b/core/src/main/kotlin/net/corda/core/concurrent/ConcurrencyUtils.kt @@ -1,9 +1,9 @@ package net.corda.core.concurrent -import com.google.common.annotations.VisibleForTesting import com.google.common.util.concurrent.ListenableFuture import com.google.common.util.concurrent.SettableFuture import net.corda.core.catch +import net.corda.core.internal.VisibleForTesting import net.corda.core.match import net.corda.core.then import org.slf4j.Logger diff --git a/core/src/main/kotlin/net/corda/core/contracts/UniqueIdentifier.kt b/core/src/main/kotlin/net/corda/core/contracts/UniqueIdentifier.kt index 2be023d047..5f62e064de 100644 --- a/core/src/main/kotlin/net/corda/core/contracts/UniqueIdentifier.kt +++ b/core/src/main/kotlin/net/corda/core/contracts/UniqueIdentifier.kt @@ -1,6 +1,6 @@ package net.corda.core.contracts -import com.google.common.annotations.VisibleForTesting +import net.corda.core.internal.VisibleForTesting import net.corda.core.serialization.CordaSerializable import java.util.* diff --git a/core/src/main/kotlin/net/corda/core/crypto/SecureHash.kt b/core/src/main/kotlin/net/corda/core/crypto/SecureHash.kt index fcefe20a5b..af2114ab6d 100644 --- a/core/src/main/kotlin/net/corda/core/crypto/SecureHash.kt +++ b/core/src/main/kotlin/net/corda/core/crypto/SecureHash.kt @@ -1,8 +1,9 @@ package net.corda.core.crypto -import com.google.common.io.BaseEncoding import net.corda.core.serialization.CordaSerializable import net.corda.core.utilities.OpaqueBytes +import net.corda.core.utilities.parseAsHex +import net.corda.core.utilities.toHexString import java.security.MessageDigest /** @@ -18,7 +19,7 @@ sealed class SecureHash(bytes: ByteArray) : OpaqueBytes(bytes) { } } - override fun toString(): String = BaseEncoding.base16().encode(bytes) + override fun toString(): String = bytes.toHexString() fun prefixChars(prefixLen: Int = 6) = toString().substring(0, prefixLen) fun hashConcat(other: SecureHash) = (this.bytes + other.bytes).sha256() @@ -26,7 +27,7 @@ sealed class SecureHash(bytes: ByteArray) : OpaqueBytes(bytes) { // Like static methods in Java, except the 'companion' is a singleton that can have state. companion object { @JvmStatic - fun parse(str: String) = BaseEncoding.base16().decode(str.toUpperCase()).let { + fun parse(str: String) = str.toUpperCase().parseAsHex().let { when (it.size) { 32 -> SHA256(it) else -> throw IllegalArgumentException("Provided string is ${it.size} bytes not 32 bytes in hex: $str") diff --git a/core/src/main/kotlin/net/corda/core/internal/InternalUtils.kt b/core/src/main/kotlin/net/corda/core/internal/InternalUtils.kt index 0e70327c02..e0d9f37580 100644 --- a/core/src/main/kotlin/net/corda/core/internal/InternalUtils.kt +++ b/core/src/main/kotlin/net/corda/core/internal/InternalUtils.kt @@ -1,6 +1,5 @@ package net.corda.core.internal -import com.google.common.base.Throwables import net.corda.core.crypto.SecureHash import net.corda.core.crypto.sha256 import org.slf4j.Logger @@ -8,10 +7,7 @@ import rx.Observable import rx.Observer import rx.subjects.PublishSubject import rx.subjects.UnicastSubject -import java.io.ByteArrayInputStream -import java.io.ByteArrayOutputStream -import java.io.InputStream -import java.io.OutputStream +import java.io.* import java.lang.reflect.Field import java.math.BigDecimal import java.nio.charset.Charset @@ -30,7 +26,8 @@ import java.util.zip.ZipEntry import java.util.zip.ZipOutputStream import kotlin.reflect.KClass -inline val Throwable.rootCause: Throwable get() = Throwables.getRootCause(this) +val Throwable.rootCause: Throwable get() = cause?.rootCause ?: this +fun Throwable.getStackTraceAsString() = StringWriter().also { printStackTrace(PrintWriter(it)) }.toString() infix fun Temporal.until(endExclusive: Temporal): Duration = Duration.between(this, endExclusive) @@ -249,3 +246,13 @@ class DeclaredField(clazz: Class<*>, name: String, private val receiver: Any? get() = javaField.get(receiver) as T set(value) = javaField.set(receiver, value) } + +/** The annotated object would have a more restricted visibility were it not needed in tests. */ +@Target(AnnotationTarget.CLASS, + AnnotationTarget.PROPERTY, + AnnotationTarget.CONSTRUCTOR, + AnnotationTarget.FUNCTION, + AnnotationTarget.TYPEALIAS) +@Retention(AnnotationRetention.SOURCE) +@MustBeDocumented +annotation class VisibleForTesting diff --git a/core/src/main/kotlin/net/corda/core/node/ServiceHub.kt b/core/src/main/kotlin/net/corda/core/node/ServiceHub.kt index b7efe3598c..492499a4da 100644 --- a/core/src/main/kotlin/net/corda/core/node/ServiceHub.kt +++ b/core/src/main/kotlin/net/corda/core/node/ServiceHub.kt @@ -1,6 +1,5 @@ package net.corda.core.node -import com.google.common.collect.Lists import net.corda.core.contracts.* import net.corda.core.crypto.DigitalSignature import net.corda.core.node.services.* @@ -76,7 +75,7 @@ interface ServiceHub : ServicesForResolution { * further processing. This is expected to be run within a database transaction. */ fun recordTransactions(first: SignedTransaction, vararg remaining: SignedTransaction) { - recordTransactions(Lists.asList(first, remaining)) + recordTransactions(listOf(first, *remaining)) } /** diff --git a/core/src/main/kotlin/net/corda/core/serialization/Kryo.kt b/core/src/main/kotlin/net/corda/core/serialization/Kryo.kt index bc780a3cff..f9321aed78 100644 --- a/core/src/main/kotlin/net/corda/core/serialization/Kryo.kt +++ b/core/src/main/kotlin/net/corda/core/serialization/Kryo.kt @@ -4,11 +4,11 @@ import com.esotericsoftware.kryo.* import com.esotericsoftware.kryo.io.Input import com.esotericsoftware.kryo.io.Output import com.esotericsoftware.kryo.util.MapReferenceResolver -import com.google.common.annotations.VisibleForTesting import net.corda.core.contracts.* import net.corda.core.crypto.* import net.corda.core.crypto.composite.CompositeKey import net.corda.core.identity.Party +import net.corda.core.internal.VisibleForTesting import net.corda.core.transactions.CoreTransaction import net.corda.core.transactions.NotaryChangeWireTransaction import net.corda.core.transactions.SignedTransaction diff --git a/core/src/main/kotlin/net/corda/core/serialization/amqp/DeserializationInput.kt b/core/src/main/kotlin/net/corda/core/serialization/amqp/DeserializationInput.kt index 55d14a1489..931f876c1c 100644 --- a/core/src/main/kotlin/net/corda/core/serialization/amqp/DeserializationInput.kt +++ b/core/src/main/kotlin/net/corda/core/serialization/amqp/DeserializationInput.kt @@ -1,6 +1,6 @@ package net.corda.core.serialization.amqp -import com.google.common.base.Throwables +import net.corda.core.internal.getStackTraceAsString import net.corda.core.serialization.SerializedBytes import org.apache.qpid.proton.amqp.Binary import org.apache.qpid.proton.amqp.DescribedType @@ -92,7 +92,7 @@ class DeserializationInput(internal val serializerFactory: SerializerFactory = S } catch(nse: NotSerializableException) { throw nse } catch(t: Throwable) { - throw NotSerializableException("Unexpected throwable: ${t.message} ${Throwables.getStackTraceAsString(t)}") + throw NotSerializableException("Unexpected throwable: ${t.message} ${t.getStackTraceAsString()}") } finally { objectHistory.clear() } diff --git a/core/src/main/kotlin/net/corda/core/utilities/ByteArrays.kt b/core/src/main/kotlin/net/corda/core/utilities/ByteArrays.kt index 866170ed4f..a43f86d4ab 100644 --- a/core/src/main/kotlin/net/corda/core/utilities/ByteArrays.kt +++ b/core/src/main/kotlin/net/corda/core/utilities/ByteArrays.kt @@ -2,9 +2,9 @@ package net.corda.core.utilities -import com.google.common.io.BaseEncoding import net.corda.core.serialization.CordaSerializable import java.io.ByteArrayInputStream +import javax.xml.bind.DatatypeConverter /** * An abstraction of a byte array, with offset and size that does no copying of bytes unless asked to. @@ -109,7 +109,7 @@ sealed class ByteSequence : Comparable { return result } - override fun toString(): String = "[${BaseEncoding.base16().encode(bytes, offset, size)}]" + override fun toString(): String = "[${bytes.copyOfRange(offset, offset + size).toHexString()}]" } /** @@ -136,12 +136,12 @@ fun ByteArray.opaque(): OpaqueBytes = OpaqueBytes(this) fun ByteArray.sequence(offset: Int = 0, size: Int = this.size) = ByteSequence.of(this, offset, size) -fun ByteArray.toHexString(): String = BaseEncoding.base16().encode(this) -fun String.parseAsHex(): ByteArray = BaseEncoding.base16().decode(this) +fun ByteArray.toHexString(): String = DatatypeConverter.printHexBinary(this) +fun String.parseAsHex(): ByteArray = DatatypeConverter.parseHexBinary(this) private class OpaqueBytesSubSequence(override val bytes: ByteArray, override val offset: Int, override val size: Int) : ByteSequence() { init { require(offset >= 0 && offset < bytes.size) require(size >= 0 && size <= bytes.size) } -} \ No newline at end of file +} diff --git a/core/src/main/kotlin/net/corda/core/utilities/NonEmptySet.kt b/core/src/main/kotlin/net/corda/core/utilities/NonEmptySet.kt index 96a955baac..9e364769e2 100644 --- a/core/src/main/kotlin/net/corda/core/utilities/NonEmptySet.kt +++ b/core/src/main/kotlin/net/corda/core/utilities/NonEmptySet.kt @@ -1,6 +1,5 @@ package net.corda.core.utilities -import com.google.common.collect.Iterators import java.util.* import java.util.function.Consumer import java.util.stream.Stream @@ -50,7 +49,7 @@ class NonEmptySet private constructor(private val elements: Set) : Set /** Returns the first element of the set. */ fun head(): T = elements.iterator().next() override fun isEmpty(): Boolean = false - override fun iterator(): Iterator = Iterators.unmodifiableIterator(elements.iterator()) + override fun iterator() = object : Iterator by elements.iterator() {} // Following methods are not delegated by Kotlin's Class delegation override fun forEach(action: Consumer) = elements.forEach(action)