Skip to content

Commit 7120506

Browse files
committed
GH-10621: Fix UUIDConverter for new nullability contract
Fixes: #10621 The `org.springframework.core.convert.converter.Converter` has now a flexible generic param nullability contract. * Fix `UUIDConverter` to mark a generic `UUID` argument as `@Nullable` to satisfy contract of super interface * Move Spring dependencies to the latest snapshots * Fix `DefaultLockRepositoryTests` timing race conditions * Fix warnings and some clean up in the `TcpNioConnectionTests`
1 parent f7d6ac0 commit 7120506

File tree

4 files changed

+41
-36
lines changed

4 files changed

+41
-36
lines changed

build.gradle

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,11 @@ ext {
101101
servletApiVersion = '6.1.0'
102102
smackVersion = '4.4.8'
103103
springAmqpVersion = '4.0.0'
104-
springDataVersion = '2025.1.0'
105-
springGraphqlVersion = '2.0.0'
106-
springKafkaVersion = '4.0.0'
107-
springSecurityVersion = '7.0.0'
108-
springVersion = '7.0.1'
104+
springDataVersion = '2025.1.1-SNAPSHOT'
105+
springGraphqlVersion = '2.0.1-SNAPSHOT'
106+
springKafkaVersion = '4.0.1-SNAPSHOT'
107+
springSecurityVersion = '7.0.1-SNAPSHOT'
108+
springVersion = '7.0.2-SNAPSHOT'
109109
springWsVersion = '5.0.0'
110110
testcontainersVersion = '2.0.2'
111111
tomcatVersion = '11.0.14'

spring-integration-core/src/main/java/org/springframework/integration/util/UUIDConverter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
* @author Artem Bilan
3939
* @author Ngoc Nhan
4040
*/
41-
public class UUIDConverter implements Converter<Object, UUID> {
41+
public class UUIDConverter implements Converter<Object, @Nullable UUID> {
4242

4343
private static final Pattern UUID_REGEX =
4444
Pattern.compile("^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$");

spring-integration-ip/src/test/java/org/springframework/integration/ip/tcp/connection/TcpNioConnectionTests.java

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@
7777
import org.springframework.messaging.Message;
7878
import org.springframework.messaging.MessagingException;
7979
import org.springframework.messaging.support.ErrorMessage;
80+
import org.springframework.messaging.support.GenericMessage;
8081
import org.springframework.scheduling.concurrent.SimpleAsyncTaskScheduler;
8182
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
8283
import org.springframework.util.ReflectionUtils;
@@ -150,9 +151,7 @@ public void testWriteTimeout(TestInfo testInfo) throws Exception {
150151
connection.send(MessageBuilder.withPayload(new byte[1000000]).build());
151152
}
152153
catch (MessagingException e) {
153-
assertThat(e.getCause() instanceof SocketTimeoutException)
154-
.as("Expected SocketTimeoutException, got " + e.getClass().getSimpleName() +
155-
":" + e.getMessage()).isTrue();
154+
assertThat(e).hasCauseInstanceOf(SocketTimeoutException.class);
156155
}
157156
done.countDown();
158157
factory.stop();
@@ -183,13 +182,13 @@ public void testReadTimeout(TestInfo testInfo) throws Exception {
183182
}
184183
});
185184
assertThat(latch.await(30, TimeUnit.SECONDS)).isTrue();
186-
TcpNioClientConnectionFactory factory = new TcpNioClientConnectionFactory("localhost",
187-
serverSocket.get().getLocalPort());
185+
TcpNioClientConnectionFactory factory =
186+
new TcpNioClientConnectionFactory("localhost", serverSocket.get().getLocalPort());
188187
factory.setApplicationEventPublisher(nullPublisher);
189188
factory.setSoTimeout(100);
190189
factory.start();
191190
TcpConnection connection = factory.getConnection();
192-
connection.send(MessageBuilder.withPayload("Test").build());
191+
connection.send(new GenericMessage<>("Test"));
193192
with().pollInterval(Duration.ofMillis(10))
194193
.await()
195194
.atMost(Duration.ofSeconds(10))
@@ -220,8 +219,8 @@ public void testMemoryLeak(TestInfo testInfo) throws Exception {
220219
}
221220
});
222221
assertThat(latch.await(30, TimeUnit.SECONDS)).isTrue();
223-
TcpNioClientConnectionFactory factory = new TcpNioClientConnectionFactory("localhost",
224-
serverSocket.get().getLocalPort());
222+
TcpNioClientConnectionFactory factory =
223+
new TcpNioClientConnectionFactory("localhost", serverSocket.get().getLocalPort());
225224
factory.setApplicationEventPublisher(nullPublisher);
226225
factory.setNioHarvestInterval(100);
227226
factory.start();
@@ -237,6 +236,7 @@ public void testMemoryLeak(TestInfo testInfo) throws Exception {
237236
}
238237

239238
@Test
239+
@SuppressWarnings("unchecked")
240240
public void testCleanup() {
241241
TcpNioClientConnectionFactory factory = new TcpNioClientConnectionFactory("localhost", 0);
242242
factory.setApplicationEventPublisher(nullPublisher);
@@ -504,9 +504,10 @@ public void transferHeaders() throws Exception {
504504
outboundConnection.setMapper(outMapper);
505505
outboundConnection.setSerializer(new MapJsonSerializer());
506506

507-
Message<String> message = MessageBuilder.withPayload("foo")
508-
.setHeader("bar", "baz")
509-
.build();
507+
Message<String> message =
508+
MessageBuilder.withPayload("foo")
509+
.setHeader("bar", "baz")
510+
.build();
510511
outboundConnection.send(message);
511512

512513
AtomicReference<Message<?>> inboundMessage = new AtomicReference<>();
@@ -556,7 +557,7 @@ public void testAssemblerUsesSecondaryExecutor() throws Exception {
556557
}
557558
Thread.sleep(100);
558559
}
559-
assertThat(n < 100).as("Could not open socket to localhost:" + port).isTrue();
560+
assertThat(n).as("Could not open socket to localhost:" + port).isLessThan(100);
560561
socket.getOutputStream().write("foo\r\n".getBytes());
561562
socket.close();
562563

@@ -614,7 +615,7 @@ public void testAllMessagesDelivered() throws Exception {
614615
}
615616
Thread.sleep(1);
616617
}
617-
assertThat(n < 100).as("Could not open socket to localhost:" + port).isTrue();
618+
assertThat(n).as("Could not open socket to localhost:" + port).isLessThan(100);
618619
sockets[i] = socket;
619620
}
620621
for (int i = 0; i < numberOfSockets; i++) {
@@ -717,8 +718,8 @@ public void publishEvent(Object event) {
717718
DirectFieldAccessor dfa = new DirectFieldAccessor(connection);
718719
dfa.setPropertyValue("logger", logger);
719720

720-
ChannelInputStream cis = spy(TestUtils
721-
.getPropertyValue(connection, "channelInputStream", ChannelInputStream.class));
721+
ChannelInputStream cis =
722+
spy(TestUtils.getPropertyValue(connection, "channelInputStream", ChannelInputStream.class));
722723
dfa.setPropertyValue("channelInputStream", cis);
723724

724725
final CountDownLatch readerLatch = new CountDownLatch(4); // 3 dataAvailable, 1 continuing

spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/lock/DefaultLockRepositoryTests.java

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,21 @@ void clear() {
6363
this.client.close();
6464
}
6565

66+
@Test
67+
void testAcquired() {
68+
this.client.acquire("test", Duration.ofSeconds(10));
69+
assertThat(this.client.isAcquired("test")).isTrue();
70+
71+
this.client.delete("test");
72+
}
73+
74+
@Test
75+
void testDelete() {
76+
this.client.acquire("test", Duration.ofSeconds(10));
77+
assertThat(this.client.delete("test")).isTrue();
78+
assertThat(this.client.isAcquired("test")).isFalse();
79+
}
80+
6681
@Transactional
6782
@Test
6883
void testNewTransactionIsStartedWhenTransactionIsAlreadyActive() {
@@ -101,19 +116,14 @@ void testIsAcquiredFromRepeatableReadTransaction() {
101116
assertThat(this.client.isAcquired("test")).isFalse();
102117
}
103118

104-
@Test
105-
void testAcquired() {
106-
client.acquire("test", Duration.ofMillis(100));
107-
assertThat(this.client.isAcquired("test")).isTrue();
108-
}
109-
110119
@RetryingTest(10)
111120
void testAcquireSameLockTwiceAndTtlWillBeUpdated() throws InterruptedException {
112121
client.acquire("test", Duration.ofMillis(150));
113122
Thread.sleep(10);
114-
client.acquire("test", Duration.ofMillis(150));
123+
client.acquire("test", Duration.ofSeconds(10));
115124
Thread.sleep(60);
116125
assertThat(this.client.isAcquired("test")).isTrue();
126+
this.client.delete("test");
117127
}
118128

119129
@Test
@@ -167,9 +177,10 @@ void testIsAcquiredLockIsExpired() throws InterruptedException {
167177
void testRenew() throws InterruptedException {
168178
client.acquire("test", Duration.ofMillis(150));
169179
Thread.sleep(10);
170-
assertThat(client.renew("test", Duration.ofMillis(150))).isTrue();
180+
assertThat(client.renew("test", Duration.ofSeconds(1))).isTrue();
171181
Thread.sleep(60);
172182
assertThat(this.client.isAcquired("test")).isTrue();
183+
this.client.delete("test");
173184
}
174185

175186
@RetryingTest(10)
@@ -194,13 +205,6 @@ void testRenewLockIsAcquiredByAnotherProcess() {
194205
lockRepositoryOfAnotherProcess.close();
195206
}
196207

197-
@Test
198-
void testDelete() {
199-
this.client.acquire("test", Duration.ofSeconds(10));
200-
assertThat(this.client.delete("test")).isTrue();
201-
assertThat(this.client.isAcquired("test")).isFalse();
202-
}
203-
204208
@Test
205209
void testDeleteLockIsAcquiredByAnotherProcess() {
206210
DefaultLockRepository lockRepositoryOfAnotherProcess = new DefaultLockRepository(dataSource);

0 commit comments

Comments
 (0)