Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
@SuppressWarnings("serial")
public abstract class IntegrationEvent extends ApplicationEvent {

protected final Throwable cause; // NOSONAR protected final
protected final @Nullable Throwable cause; // NOSONAR protected final

public IntegrationEvent(Object source) {
this(source, null);
Expand All @@ -44,8 +44,7 @@ public IntegrationEvent(Object source, @Nullable Throwable cause) {
this.cause = cause;
}

@Nullable
public Throwable getCause() {
public @Nullable Throwable getCause() {
return this.cause;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/**
* ApplicationEvents generated by the Spring Integration framework.
*/
@org.jspecify.annotations.NullMarked
package org.springframework.integration.events;
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jspecify.annotations.Nullable;

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

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

private volatile Context leaderContext;
private volatile @Nullable Context leaderContext;

/**
* Instantiate a default candidate.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

package org.springframework.integration.leader.event;

import org.jspecify.annotations.Nullable;

import org.springframework.context.ApplicationEvent;
import org.springframework.integration.leader.Context;

Expand All @@ -30,9 +32,9 @@
@SuppressWarnings("serial")
public abstract class AbstractLeaderEvent extends ApplicationEvent {

private final Context context;
private final @Nullable Context context;

private final String role;
private final @Nullable String role;

/**
* Create a new ApplicationEvent.
Expand All @@ -50,7 +52,7 @@ public AbstractLeaderEvent(Object source) {
* @param context the context associated with this event
* @param role the role of the leader
*/
public AbstractLeaderEvent(Object source, Context context, String role) {
public AbstractLeaderEvent(Object source, @Nullable Context context, @Nullable String role) {
super(source);
this.context = context;
this.role = role;
Expand All @@ -61,7 +63,7 @@ public AbstractLeaderEvent(Object source, Context context, String role) {
*
* @return the context
*/
public Context getContext() {
public @Nullable Context getContext() {
return this.context;
}

Expand All @@ -70,7 +72,7 @@ public Context getContext() {
*
* @return the role
*/
public String getRole() {
public @Nullable String getRole() {
return this.role;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

package org.springframework.integration.leader.event;

import org.jspecify.annotations.Nullable;

import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.ApplicationEventPublisherAware;
import org.springframework.integration.leader.Context;
Expand All @@ -30,7 +32,7 @@
*/
public class DefaultLeaderEventPublisher implements LeaderEventPublisher, ApplicationEventPublisherAware {

private ApplicationEventPublisher applicationEventPublisher;
private @Nullable ApplicationEventPublisher applicationEventPublisher;

/**
* Instantiates a new leader event publisher.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/**
* Temporary package until s-c-c-core is released.
*/
@org.jspecify.annotations.NullMarked
package org.springframework.integration.leader.event;
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Temporary package until s-c-c-core is released.
*/
@org.springframework.lang.NonNullApi
@org.jspecify.annotations.NullMarked
package org.springframework.integration.leader;
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import java.util.Map;
import java.util.Objects;

import org.jspecify.annotations.Nullable;

import org.springframework.messaging.Message;
import org.springframework.messaging.MessageHeaders;
import org.springframework.messaging.support.GenericMessage;
Expand Down Expand Up @@ -81,18 +83,14 @@ public String toString() {
}

@Override
public boolean equals(Object o) {
if (this == o) {
public boolean equals(@Nullable Object o) {
if (super.equals(o)) {
return true;
}
if (!(o instanceof AdviceMessage)) {
return false;
}
if (!super.equals(o)) {
return false;
if (o instanceof AdviceMessage<?> that) {
return Objects.equals(this.inputMessage, that.inputMessage);
}
AdviceMessage<?> that = (AdviceMessage<?>) o;
return Objects.equals(this.inputMessage, that.inputMessage);
return false;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/**
* Provides concrete {@link org.springframework.messaging.Message} implementations.
*/
@org.jspecify.annotations.NullMarked
package org.springframework.integration.message;
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import java.util.Arrays;
import java.util.Collection;

import org.jspecify.annotations.Nullable;

import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.core.io.Resource;
Expand Down Expand Up @@ -47,11 +49,13 @@ public class ResourceRetrievingMessageSource extends AbstractMessageSource<Resou

private final String pattern;

@SuppressWarnings("NullAway.Init")
private volatile ApplicationContext applicationContext;

@SuppressWarnings("NullAway.Init")
private volatile ResourcePatternResolver patternResolver;

private volatile CollectionFilter<Resource> filter;
private volatile @Nullable CollectionFilter<Resource> filter;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

... and remove volatile on all the properties.
It is really an anti-pattern to change state of the component at runtime.
Therefore, we treat all of them as state fixed after initialization phase.
Therefore, no need in extra ticks over volatile barrier.


public ResourceRetrievingMessageSource(String pattern) {
Assert.hasText(pattern, "pattern must not be empty");
Expand Down Expand Up @@ -85,7 +89,7 @@ protected void onInit() {
}

@Override
protected Resource[] doReceive() {
protected Resource @Nullable [] doReceive() {
try {
Resource[] resources = this.patternResolver.getResources(this.pattern);
if (ObjectUtils.isEmpty(resources)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
* Provides classes related to messaging
* using Spring {@link org.springframework.core.io.Resource}s
*/
@org.jspecify.annotations.NullMarked
package org.springframework.integration.resource;
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
import org.springframework.integration.store.MessageMetadata;
import org.springframework.integration.store.MessageStore;
import org.springframework.integration.store.SimpleMessageGroup;
import org.springframework.integration.support.MessageBuilder;
import org.springframework.integration.support.MutableMessage;
import org.springframework.integration.support.MutableMessageBuilder;
import org.springframework.integration.support.converter.AllowListDeserializingConverter;
Expand Down Expand Up @@ -837,6 +838,9 @@ public AdviceMessage<?> convert(Document source) {
throw new IllegalStateException("failed to load class: " + inputMessageType, e);
}
}
else {
inputMessage = MessageBuilder.withPayload(new byte[0]).build();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is better to throw an exception instead.
How that happened that AdviceMessage was serialized without an inputMessage?
So, the state is illegal.
WDYT?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes sense. I wasn’t sure about the behavior in this case, so I decided to initialize the value.

}

AdviceMessage<?> message = new AdviceMessage<>(
MongoDbMessageStore.this.converter.extractPayload(source), headers, inputMessage);
Expand Down