diff --git a/src/main/java/org/springframework/data/util/MethodInvocationRecorder.java b/src/main/java/org/springframework/data/util/MethodInvocationRecorder.java index cfcc848be..d130c8205 100644 --- a/src/main/java/org/springframework/data/util/MethodInvocationRecorder.java +++ b/src/main/java/org/springframework/data/util/MethodInvocationRecorder.java @@ -73,6 +73,7 @@ public class MethodInvocationRecorder { public static Recorded forProxyOf(Class type) { Assert.notNull(type, "Type must not be null!"); + Assert.isTrue(!Modifier.isFinal(type.getModifiers()), "Type to record invocations on must not be final!"); return new MethodInvocationRecorder().create(type); } diff --git a/src/test/java/org/springframework/data/util/MethodInvocationRecorderUnitTests.java b/src/test/java/org/springframework/data/util/MethodInvocationRecorderUnitTests.java index cd6f7ede5..0ca493e79 100644 --- a/src/test/java/org/springframework/data/util/MethodInvocationRecorderUnitTests.java +++ b/src/test/java/org/springframework/data/util/MethodInvocationRecorderUnitTests.java @@ -34,6 +34,13 @@ public class MethodInvocationRecorderUnitTests { Recorded recorder = MethodInvocationRecorder.forProxyOf(Foo.class); + @Test // DATACMNS-1449 + public void rejectsFinalTypes() { + + assertThatExceptionOfType(IllegalArgumentException.class) // + .isThrownBy(() -> MethodInvocationRecorder.forProxyOf(FinalType.class)); + } + @Test // DATACMNS-1449 public void createsPropertyPathForSimpleMethodReference() { @@ -71,7 +78,7 @@ public class MethodInvocationRecorderUnitTests { assertThat(recorder.record(Foo::getName).getPropertyPath()).hasValue("name"); } - @Test + @Test // DATACMNS-1449 public void recordsInvocationOnInterface() { Recorded recorder = MethodInvocationRecorder.forProxyOf(Sample.class); @@ -79,6 +86,8 @@ public class MethodInvocationRecorderUnitTests { assertThat(recorder.record(Sample::getName).getPropertyPath()).hasValue("name"); } + static final class FinalType {} + @Getter static class Foo { Bar bar;