mirror of
https://github.com/corda/corda.git
synced 2025-06-23 01:19:00 +00:00
Enabled warnings as errors (#3514)
This commit is contained in:
@ -13,7 +13,7 @@ public class JavaGenericsTest {
|
||||
private final Integer v;
|
||||
|
||||
private Inner(Integer v) { this.v = v; }
|
||||
public Integer getV() { return v; }
|
||||
Integer getV() { return v; }
|
||||
}
|
||||
|
||||
private static class A<T> {
|
||||
@ -25,7 +25,7 @@ public class JavaGenericsTest {
|
||||
|
||||
@Test
|
||||
public void basicGeneric() throws NotSerializableException {
|
||||
A a1 = new A(1);
|
||||
A a1 = new A<>(1);
|
||||
|
||||
SerializerFactory factory = testDefaultFactory();
|
||||
|
||||
@ -66,7 +66,7 @@ public class JavaGenericsTest {
|
||||
|
||||
@Test
|
||||
public void forceWildcard() throws NotSerializableException {
|
||||
SerializedBytes<?> bytes = forceWildcardSerialize(new A(new Inner(29)));
|
||||
SerializedBytes<?> bytes = forceWildcardSerialize(new A<>(new Inner(29)));
|
||||
Inner i = (Inner)forceWildcardDeserialize(bytes).getT();
|
||||
assertEquals(29, i.getV());
|
||||
}
|
||||
@ -75,7 +75,7 @@ public class JavaGenericsTest {
|
||||
public void forceWildcardSharedFactory() throws NotSerializableException {
|
||||
SerializerFactory factory = testDefaultFactory();
|
||||
|
||||
SerializedBytes<?> bytes = forceWildcardSerializeFactory(new A(new Inner(29)), factory);
|
||||
SerializedBytes<?> bytes = forceWildcardSerializeFactory(new A<>(new Inner(29)), factory);
|
||||
Inner i = (Inner)forceWildcardDeserializeFactory(bytes, factory).getT();
|
||||
|
||||
assertEquals(29, i.getV());
|
||||
|
@ -7,6 +7,7 @@ import java.io.NotSerializableException;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.Map;
|
||||
|
||||
import static net.corda.core.internal.InternalUtils.uncheckedCast;
|
||||
import static net.corda.serialization.internal.amqp.testutils.AMQPTestUtilsKt.testDefaultFactory;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
@ -30,6 +31,7 @@ public class JavaPrivatePropertyTests {
|
||||
|
||||
B(Boolean b) { this.b = b; }
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public Boolean isB() {
|
||||
return this.b;
|
||||
}
|
||||
@ -38,6 +40,7 @@ public class JavaPrivatePropertyTests {
|
||||
static class B2 {
|
||||
private Boolean b;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public Boolean isB() {
|
||||
return this.b;
|
||||
}
|
||||
@ -50,6 +53,7 @@ public class JavaPrivatePropertyTests {
|
||||
static class B3 {
|
||||
private Boolean b;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
// break the BEAN format explicitly (i.e. it's not isB)
|
||||
public Boolean isb() {
|
||||
return this.b;
|
||||
@ -67,6 +71,7 @@ public class JavaPrivatePropertyTests {
|
||||
return this.a;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public Boolean isA() {
|
||||
return this.a > 0;
|
||||
}
|
||||
@ -145,7 +150,7 @@ public class JavaPrivatePropertyTests {
|
||||
Field f = SerializerFactory.class.getDeclaredField("serializersByDescriptor");
|
||||
f.setAccessible(true);
|
||||
|
||||
Map<?, AMQPSerializer<?>> serializersByDescriptor = (Map<?, AMQPSerializer<?>>) f.get(factory);
|
||||
Map<?, AMQPSerializer<?>> serializersByDescriptor = uncheckedCast(f.get(factory));
|
||||
|
||||
assertEquals(1, serializersByDescriptor.size());
|
||||
ObjectSerializer cSerializer = ((ObjectSerializer)serializersByDescriptor.values().toArray()[0]);
|
||||
@ -172,7 +177,7 @@ public class JavaPrivatePropertyTests {
|
||||
//
|
||||
Field f = SerializerFactory.class.getDeclaredField("serializersByDescriptor");
|
||||
f.setAccessible(true);
|
||||
Map<?, AMQPSerializer<?>> serializersByDescriptor = (Map<?, AMQPSerializer<?>>) f.get(factory);
|
||||
Map<?, AMQPSerializer<?>> serializersByDescriptor = uncheckedCast(f.get(factory));
|
||||
|
||||
assertEquals(1, serializersByDescriptor.size());
|
||||
ObjectSerializer cSerializer = ((ObjectSerializer)serializersByDescriptor.values().toArray()[0]);
|
||||
|
@ -17,7 +17,6 @@ import org.junit.Test
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
class ContractAttachmentSerializerTest {
|
||||
|
||||
@Rule
|
||||
@JvmField
|
||||
val testSerialization = SerializationEnvironmentRule()
|
||||
@ -51,7 +50,7 @@ class ContractAttachmentSerializerTest {
|
||||
fun `write contract attachment and read it back using token context`() {
|
||||
val attachment = GeneratedAttachment("test".toByteArray())
|
||||
|
||||
mockServices.attachments.importAttachment(attachment.open())
|
||||
mockServices.attachments.importAttachment(attachment.open(), "test", null)
|
||||
|
||||
val contractAttachment = ContractAttachment(attachment, DummyContract.PROGRAM_ID)
|
||||
val serialized = contractAttachment.serialize(factory, contextWithToken)
|
||||
@ -68,7 +67,7 @@ class ContractAttachmentSerializerTest {
|
||||
val largeAttachmentSize = 1024 * 1024
|
||||
val attachment = GeneratedAttachment(ByteArray(largeAttachmentSize))
|
||||
|
||||
mockServices.attachments.importAttachment(attachment.open())
|
||||
mockServices.attachments.importAttachment(attachment.open(), "test", null)
|
||||
|
||||
val contractAttachment = ContractAttachment(attachment, DummyContract.PROGRAM_ID)
|
||||
val serialized = contractAttachment.serialize(factory, contextWithToken)
|
||||
|
@ -2,10 +2,9 @@ package net.corda.serialization.internal.amqp
|
||||
|
||||
import net.corda.serialization.internal.amqp.testutils.TestSerializationOutput
|
||||
import net.corda.serialization.internal.amqp.testutils.deserialize
|
||||
import net.corda.serialization.internal.amqp.testutils.serialize
|
||||
import net.corda.serialization.internal.amqp.testutils.testDefaultFactory
|
||||
import net.corda.serialization.internal.amqp.testutils.testName
|
||||
import org.assertj.core.api.Assertions
|
||||
import org.assertj.core.api.Assertions.assertThatThrownBy
|
||||
import org.junit.Ignore
|
||||
import org.junit.Test
|
||||
import java.io.NotSerializableException
|
||||
@ -28,7 +27,7 @@ class ErrorMessagesTests {
|
||||
|
||||
val testname = "${javaClass.name}\$${testName()}"
|
||||
|
||||
Assertions.assertThatThrownBy {
|
||||
assertThatThrownBy {
|
||||
TestSerializationOutput(VERBOSE, sf).serialize(C(1))
|
||||
}.isInstanceOf(NotSerializableException::class.java).hasMessage(errMsg("a", testname))
|
||||
}
|
||||
@ -43,7 +42,7 @@ class ErrorMessagesTests {
|
||||
|
||||
val testname = "${javaClass.name}\$${testName()}"
|
||||
|
||||
Assertions.assertThatThrownBy {
|
||||
assertThatThrownBy {
|
||||
TestSerializationOutput(VERBOSE, sf).serialize(C(1, 2))
|
||||
}.isInstanceOf(NotSerializableException::class.java).hasMessage(errMsg("b", testname))
|
||||
}
|
||||
@ -55,28 +54,27 @@ class ErrorMessagesTests {
|
||||
// despite b being private, the getter we've added is public and thus allows for the serialisation
|
||||
// of the object
|
||||
data class C(val a: Int, private val b: Int) {
|
||||
public fun getB() = b
|
||||
@Suppress("unused")
|
||||
fun getB() = b
|
||||
}
|
||||
|
||||
val sf = testDefaultFactory()
|
||||
|
||||
val testname = "${javaClass.name}\$${testName()}"
|
||||
|
||||
val bytes = TestSerializationOutput(VERBOSE, sf).serialize(C(1, 2))
|
||||
val c = DeserializationInput(sf).deserialize(bytes)
|
||||
DeserializationInput(sf).deserialize(bytes)
|
||||
}
|
||||
|
||||
// Java allows this to be set at the class level yet Kotlin doesn't for some reason
|
||||
@Ignore("Current behaviour allows for the serialization of objects with private members, this will be disallowed at some point in the future")
|
||||
@Test
|
||||
fun protectedProperty() {
|
||||
data class C(protected val a: Int)
|
||||
open class C(@Suppress("unused") protected val a: Int)
|
||||
|
||||
val sf = testDefaultFactory()
|
||||
|
||||
val testname = "${javaClass.name}\$${testName()}"
|
||||
|
||||
Assertions.assertThatThrownBy {
|
||||
assertThatThrownBy {
|
||||
TestSerializationOutput(VERBOSE, sf).serialize(C(1))
|
||||
}.isInstanceOf(NotSerializableException::class.java).hasMessage(errMsg("a", testname))
|
||||
}
|
||||
|
@ -277,7 +277,7 @@ class GenericsTests {
|
||||
private fun fingerprintingDiffersStrip(state: Any) {
|
||||
class cl : ClassLoader()
|
||||
|
||||
val m = ClassLoader::class.java.getDeclaredMethod("findLoadedClass", *arrayOf<Class<*>>(String::class.java))
|
||||
val m = ClassLoader::class.java.getDeclaredMethod("findLoadedClass", String::class.java)
|
||||
m.isAccessible = true
|
||||
|
||||
val factory1 = testDefaultFactory()
|
||||
@ -295,16 +295,16 @@ class GenericsTests {
|
||||
// now deserialise those objects
|
||||
val factory3 = testDefaultFactory()
|
||||
factory3.register(net.corda.serialization.internal.amqp.custom.PublicKeySerializer)
|
||||
val des1 = DeserializationInput(factory3).deserializeAndReturnEnvelope(ser1.obj)
|
||||
DeserializationInput(factory3).deserializeAndReturnEnvelope(ser1.obj)
|
||||
|
||||
val factory4 = SerializerFactory(AllWhitelist, cl())
|
||||
factory4.register(net.corda.serialization.internal.amqp.custom.PublicKeySerializer)
|
||||
val des2 = DeserializationInput(factory4).deserializeAndReturnEnvelope(ser2.obj)
|
||||
DeserializationInput(factory4).deserializeAndReturnEnvelope(ser2.obj)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun fingerprintingDiffers() {
|
||||
val state = TransactionState<TestContractState> (
|
||||
val state = TransactionState(
|
||||
TestContractState(listOf(miniCorp.party)),
|
||||
"wibble", miniCorp.party,
|
||||
encumbrance = null,
|
||||
@ -317,7 +317,7 @@ class GenericsTests {
|
||||
|
||||
@Test
|
||||
fun fingerprintingDiffersList() {
|
||||
val state = TransactionState<TestContractState> (
|
||||
val state = TransactionState(
|
||||
TestContractState(listOf(miniCorp.party)),
|
||||
"wibble", miniCorp.party,
|
||||
encumbrance = null,
|
||||
|
@ -97,7 +97,7 @@ class PrivatePropertyTests {
|
||||
@ConstructorForDeserialization
|
||||
constructor() : this(0, 0)
|
||||
|
||||
fun setA(a: Int, b: Int) { this.a = a }
|
||||
fun setA(a: Int, @Suppress("UNUSED_PARAMETER") b: Int) { this.a = a }
|
||||
fun getA() = a
|
||||
}
|
||||
|
||||
|
@ -4,7 +4,8 @@ import net.corda.core.serialization.ConstructorForDeserialization
|
||||
import net.corda.serialization.internal.amqp.testutils.deserialize
|
||||
import net.corda.serialization.internal.amqp.testutils.serialize
|
||||
import net.corda.serialization.internal.amqp.testutils.testDefaultFactoryNoEvolution
|
||||
import org.assertj.core.api.Assertions
|
||||
import org.assertj.core.api.Assertions.assertThat
|
||||
import org.assertj.core.api.Assertions.assertThatThrownBy
|
||||
import org.junit.Test
|
||||
|
||||
class RoundTripTests {
|
||||
@ -16,20 +17,15 @@ class RoundTripTests {
|
||||
val bytes = SerializationOutput(factory).serialize(C(mutableListOf("a", "b", "c")))
|
||||
val newC = DeserializationInput(factory).deserialize(bytes)
|
||||
|
||||
Assertions.assertThatThrownBy {
|
||||
assertThatThrownBy {
|
||||
newC.l.add("d")
|
||||
}.isInstanceOf(UnsupportedOperationException::class.java)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun mutableStillMutable() {
|
||||
class C {
|
||||
val l: MutableList<String>
|
||||
|
||||
@Suppress("Unused")
|
||||
constructor (l: MutableList<String>) {
|
||||
this.l = l.toMutableList()
|
||||
}
|
||||
class C(l: MutableList<String>) {
|
||||
val l: MutableList<String> = l.toMutableList()
|
||||
}
|
||||
|
||||
val factory = testDefaultFactoryNoEvolution()
|
||||
@ -37,6 +33,7 @@ class RoundTripTests {
|
||||
val newC = DeserializationInput(factory).deserialize(bytes)
|
||||
|
||||
newC.l.add("d")
|
||||
assertThat(newC.l).containsExactly("a", "b", "c", "d")
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -52,6 +49,7 @@ class RoundTripTests {
|
||||
val newC = DeserializationInput(factory).deserialize(bytes)
|
||||
|
||||
newC.l.add("d")
|
||||
assertThat(newC.l).containsExactly("a", "b", "c", "d")
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -61,6 +59,6 @@ class RoundTripTests {
|
||||
val factory = testDefaultFactoryNoEvolution()
|
||||
val bytes = SerializationOutput(factory).serialize(C(listOf("a", "b", "c")))
|
||||
val newC = DeserializationInput(factory).deserialize(bytes)
|
||||
val newC2 = newC.copy(l = (newC.l + "d"))
|
||||
newC.copy(l = (newC.l + "d"))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -888,6 +888,7 @@ class SerializationOutputTests(private val compression: CordaSerializationEncodi
|
||||
|
||||
class GenericSubclass(param: OtherGeneric<String>) : GenericSuperclass<String>(param) {
|
||||
override fun equals(other: Any?): Boolean = other is GenericSubclass // This is a bit lame but we just want to check it doesn't throw exceptions
|
||||
override fun hashCode(): Int = javaClass.hashCode()
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -966,8 +967,10 @@ class SerializationOutputTests(private val compression: CordaSerializationEncodi
|
||||
assertSame(objCopy.a, objCopy.b)
|
||||
}
|
||||
|
||||
data class Spike private constructor(val a: String) {
|
||||
class Spike private constructor(val a: String) {
|
||||
constructor() : this("a")
|
||||
override fun equals(other: Any?): Boolean = other is Spike && other.a == this.a
|
||||
override fun hashCode(): Int = a.hashCode()
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -1028,7 +1031,7 @@ class SerializationOutputTests(private val compression: CordaSerializationEncodi
|
||||
serdes(obj, factory, factory2)
|
||||
}
|
||||
|
||||
data class ByteArrays(val a: ByteArray, val b: ByteArray)
|
||||
class ByteArrays(val a: ByteArray, val b: ByteArray)
|
||||
|
||||
@Test
|
||||
fun `test byte arrays not reference counted`() {
|
||||
@ -1162,7 +1165,7 @@ class SerializationOutputTests(private val compression: CordaSerializationEncodi
|
||||
}
|
||||
|
||||
//
|
||||
// Example stacktrace that this test is tryint to reproduce
|
||||
// Example stacktrace that this test is trying to reproduce
|
||||
//
|
||||
// java.lang.IllegalArgumentException:
|
||||
// net.corda.core.contracts.TransactionState ->
|
||||
@ -1179,10 +1182,6 @@ class SerializationOutputTests(private val compression: CordaSerializationEncodi
|
||||
//
|
||||
@Test
|
||||
fun reproduceWrongNumberOfArguments() {
|
||||
val field = SerializerFactory::class.java.getDeclaredField("serializersByType").apply {
|
||||
this.isAccessible = true
|
||||
}
|
||||
|
||||
data class C(val a: Amount<Currency>)
|
||||
|
||||
val factory = testDefaultFactoryNoEvolution()
|
||||
@ -1337,7 +1336,7 @@ class SerializationOutputTests(private val compression: CordaSerializationEncodi
|
||||
val bytes = SerializationOutput(testDefaultFactory()).serialize(i)
|
||||
|
||||
try {
|
||||
val i2 = DeserializationInput(testDefaultFactory()).deserialize(bytes)
|
||||
DeserializationInput(testDefaultFactory()).deserialize(bytes)
|
||||
} catch (e: NotSerializableException) {
|
||||
throw Error("Deserializing serialized \$C should not throw")
|
||||
}
|
||||
|
@ -35,7 +35,7 @@ class SerializationPropertyOrdering {
|
||||
|
||||
val u = User(l,l)
|
||||
val output = TestSerializationOutput(VERBOSE, sf).serializeAndReturnSchema(u)
|
||||
val input = DeserializationInput(sf).deserialize(output.obj)
|
||||
DeserializationInput(sf).deserialize(output.obj)
|
||||
}
|
||||
|
||||
@Test
|
||||
|
Reference in New Issue
Block a user