Skip to content

Commit ea3af3d

Browse files
committed
DATACMNS-1449 - MethodInvocationRecorder now rejects final types.
1 parent 34507ec commit ea3af3d

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/main/java/org/springframework/data/util/MethodInvocationRecorder.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ private MethodInvocationRecorder() {
7373
public static <T> Recorded<T> forProxyOf(Class<T> type) {
7474

7575
Assert.notNull(type, "Type must not be null!");
76+
Assert.isTrue(!Modifier.isFinal(type.getModifiers()), "Type to record invocations on must not be final!");
7677

7778
return new MethodInvocationRecorder().create(type);
7879
}

src/test/java/org/springframework/data/util/MethodInvocationRecorderUnitTests.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,13 @@ public class MethodInvocationRecorderUnitTests {
3434

3535
Recorded<Foo> recorder = MethodInvocationRecorder.forProxyOf(Foo.class);
3636

37+
@Test // DATACMNS-1449
38+
public void rejectsFinalTypes() {
39+
40+
assertThatExceptionOfType(IllegalArgumentException.class) //
41+
.isThrownBy(() -> MethodInvocationRecorder.forProxyOf(FinalType.class));
42+
}
43+
3744
@Test // DATACMNS-1449
3845
public void createsPropertyPathForSimpleMethodReference() {
3946

@@ -71,14 +78,16 @@ public void registersLookupToFinalType() {
7178
assertThat(recorder.record(Foo::getName).getPropertyPath()).hasValue("name");
7279
}
7380

74-
@Test
81+
@Test // DATACMNS-1449
7582
public void recordsInvocationOnInterface() {
7683

7784
Recorded<Sample> recorder = MethodInvocationRecorder.forProxyOf(Sample.class);
7885

7986
assertThat(recorder.record(Sample::getName).getPropertyPath()).hasValue("name");
8087
}
8188

89+
static final class FinalType {}
90+
8291
@Getter
8392
static class Foo {
8493
Bar bar;

0 commit comments

Comments
 (0)