Skip to content

Commit 10d4867

Browse files
GH-10083: Apply Nullability to core events, leader, message and resource packages
Related to: #10083 * Remove `volatile` and throw exception for illegal state in the `MongoDbMessageStore` Signed-off-by: Tran Ngoc Nhan <[email protected]>
1 parent 51ddca0 commit 10d4867

File tree

12 files changed

+35
-24
lines changed

12 files changed

+35
-24
lines changed

spring-integration-core/src/main/java/org/springframework/integration/events/IntegrationEvent.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
@SuppressWarnings("serial")
3434
public abstract class IntegrationEvent extends ApplicationEvent {
3535

36-
protected final Throwable cause; // NOSONAR protected final
36+
protected final @Nullable Throwable cause; // NOSONAR protected final
3737

3838
public IntegrationEvent(Object source) {
3939
this(source, null);
@@ -44,8 +44,7 @@ public IntegrationEvent(Object source, @Nullable Throwable cause) {
4444
this.cause = cause;
4545
}
4646

47-
@Nullable
48-
public Throwable getCause() {
47+
public @Nullable Throwable getCause() {
4948
return this.cause;
5049
}
5150

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/**
22
* ApplicationEvents generated by the Spring Integration framework.
33
*/
4+
@org.jspecify.annotations.NullMarked
45
package org.springframework.integration.events;

spring-integration-core/src/main/java/org/springframework/integration/leader/DefaultCandidate.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import org.apache.commons.logging.Log;
2020
import org.apache.commons.logging.LogFactory;
21+
import org.jspecify.annotations.Nullable;
2122

2223
/**
2324
* Simple {@link Candidate} for leadership.
@@ -32,7 +33,7 @@ public class DefaultCandidate extends AbstractCandidate {
3233

3334
private final Log logger = LogFactory.getLog(getClass());
3435

35-
private volatile Context leaderContext;
36+
private volatile @Nullable Context leaderContext;
3637

3738
/**
3839
* Instantiate a default candidate.

spring-integration-core/src/main/java/org/springframework/integration/leader/event/AbstractLeaderEvent.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
package org.springframework.integration.leader.event;
1818

19+
import org.jspecify.annotations.Nullable;
20+
1921
import org.springframework.context.ApplicationEvent;
2022
import org.springframework.integration.leader.Context;
2123

@@ -30,9 +32,9 @@
3032
@SuppressWarnings("serial")
3133
public abstract class AbstractLeaderEvent extends ApplicationEvent {
3234

33-
private final Context context;
35+
private final @Nullable Context context;
3436

35-
private final String role;
37+
private final @Nullable String role;
3638

3739
/**
3840
* Create a new ApplicationEvent.
@@ -50,7 +52,7 @@ public AbstractLeaderEvent(Object source) {
5052
* @param context the context associated with this event
5153
* @param role the role of the leader
5254
*/
53-
public AbstractLeaderEvent(Object source, Context context, String role) {
55+
public AbstractLeaderEvent(Object source, @Nullable Context context, @Nullable String role) {
5456
super(source);
5557
this.context = context;
5658
this.role = role;
@@ -61,7 +63,7 @@ public AbstractLeaderEvent(Object source, Context context, String role) {
6163
*
6264
* @return the context
6365
*/
64-
public Context getContext() {
66+
public @Nullable Context getContext() {
6567
return this.context;
6668
}
6769

@@ -70,7 +72,7 @@ public Context getContext() {
7072
*
7173
* @return the role
7274
*/
73-
public String getRole() {
75+
public @Nullable String getRole() {
7476
return this.role;
7577
}
7678

spring-integration-core/src/main/java/org/springframework/integration/leader/event/DefaultLeaderEventPublisher.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
package org.springframework.integration.leader.event;
1818

19+
import org.jspecify.annotations.Nullable;
20+
1921
import org.springframework.context.ApplicationEventPublisher;
2022
import org.springframework.context.ApplicationEventPublisherAware;
2123
import org.springframework.integration.leader.Context;
@@ -30,7 +32,7 @@
3032
*/
3133
public class DefaultLeaderEventPublisher implements LeaderEventPublisher, ApplicationEventPublisherAware {
3234

33-
private ApplicationEventPublisher applicationEventPublisher;
35+
private @Nullable ApplicationEventPublisher applicationEventPublisher;
3436

3537
/**
3638
* Instantiates a new leader event publisher.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/**
22
* Temporary package until s-c-c-core is released.
33
*/
4+
@org.jspecify.annotations.NullMarked
45
package org.springframework.integration.leader.event;
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
22
* Temporary package until s-c-c-core is released.
33
*/
4-
@org.springframework.lang.NonNullApi
4+
@org.jspecify.annotations.NullMarked
55
package org.springframework.integration.leader;

spring-integration-core/src/main/java/org/springframework/integration/message/AdviceMessage.java

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
import java.util.Map;
2020
import java.util.Objects;
2121

22+
import org.jspecify.annotations.Nullable;
23+
2224
import org.springframework.messaging.Message;
2325
import org.springframework.messaging.MessageHeaders;
2426
import org.springframework.messaging.support.GenericMessage;
@@ -81,18 +83,14 @@ public String toString() {
8183
}
8284

8385
@Override
84-
public boolean equals(Object o) {
85-
if (this == o) {
86+
public boolean equals(@Nullable Object o) {
87+
if (super.equals(o)) {
8688
return true;
8789
}
88-
if (!(o instanceof AdviceMessage)) {
89-
return false;
90-
}
91-
if (!super.equals(o)) {
92-
return false;
90+
if (o instanceof AdviceMessage<?> that) {
91+
return Objects.equals(this.inputMessage, that.inputMessage);
9392
}
94-
AdviceMessage<?> that = (AdviceMessage<?>) o;
95-
return Objects.equals(this.inputMessage, that.inputMessage);
93+
return false;
9694
}
9795

9896
@Override
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/**
22
* Provides concrete {@link org.springframework.messaging.Message} implementations.
33
*/
4+
@org.jspecify.annotations.NullMarked
45
package org.springframework.integration.message;

spring-integration-core/src/main/java/org/springframework/integration/resource/ResourceRetrievingMessageSource.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
import java.util.Arrays;
2020
import java.util.Collection;
2121

22+
import org.jspecify.annotations.Nullable;
23+
2224
import org.springframework.context.ApplicationContext;
2325
import org.springframework.context.ApplicationContextAware;
2426
import org.springframework.core.io.Resource;
@@ -47,11 +49,13 @@ public class ResourceRetrievingMessageSource extends AbstractMessageSource<Resou
4749

4850
private final String pattern;
4951

50-
private volatile ApplicationContext applicationContext;
52+
@SuppressWarnings("NullAway.Init")
53+
private ApplicationContext applicationContext;
5154

52-
private volatile ResourcePatternResolver patternResolver;
55+
@SuppressWarnings("NullAway.Init")
56+
private ResourcePatternResolver patternResolver;
5357

54-
private volatile CollectionFilter<Resource> filter;
58+
private @Nullable CollectionFilter<Resource> filter;
5559

5660
public ResourceRetrievingMessageSource(String pattern) {
5761
Assert.hasText(pattern, "pattern must not be empty");
@@ -85,7 +89,7 @@ protected void onInit() {
8589
}
8690

8791
@Override
88-
protected Resource[] doReceive() {
92+
protected Resource @Nullable [] doReceive() {
8993
try {
9094
Resource[] resources = this.patternResolver.getResources(this.pattern);
9195
if (ObjectUtils.isEmpty(resources)) {

0 commit comments

Comments
 (0)