-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Apply NullAbility to scripting module #10293
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
artembilan
merged 5 commits into
spring-projects:main
from
ngocnhan-tran1996:gh-10083-scripting-module
Aug 11, 2025
Merged
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
1054836
GH-10083: Apply NullAbility to scripting module
ngocnhan-tran1996 772669c
Add `@Nullable` for `GroovyScriptExecutingMessageProcessor#getScriptS…
ngocnhan-tran1996 2febe09
Remove `@Nullable`
ngocnhan-tran1996 ea9407b
Remove `@Nullable` in `ScriptExecutingMessageProcessor` class
ngocnhan-tran1996 2a1c94e
change to `byte[]`
ngocnhan-tran1996 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,20 +18,21 @@ | |
|
|
||
| import java.util.Map; | ||
|
|
||
| import org.jspecify.annotations.Nullable; | ||
|
|
||
| import org.springframework.beans.BeansException; | ||
| import org.springframework.beans.factory.BeanClassLoaderAware; | ||
| import org.springframework.beans.factory.BeanFactory; | ||
| import org.springframework.beans.factory.BeanFactoryAware; | ||
| import org.springframework.integration.handler.MessageProcessor; | ||
| import org.springframework.lang.Nullable; | ||
| import org.springframework.messaging.Message; | ||
| import org.springframework.scripting.ScriptSource; | ||
| import org.springframework.util.Assert; | ||
|
|
||
| /** | ||
| * Base {@link MessageProcessor} for scripting implementations to extend. | ||
| * | ||
| * @param <T> the paylaod type. | ||
| * @param <T> the payload type. | ||
| * | ||
| * @author Mark Fisher | ||
| * @author Stefan Reuter | ||
|
|
@@ -44,9 +45,9 @@ public abstract class AbstractScriptExecutingMessageProcessor<T> | |
|
|
||
| private final ScriptVariableGenerator scriptVariableGenerator; | ||
|
|
||
| private ClassLoader beanClassLoader; | ||
| private @Nullable ClassLoader beanClassLoader; | ||
|
|
||
| private BeanFactory beanFactory; | ||
| private @Nullable BeanFactory beanFactory; | ||
|
||
|
|
||
| protected AbstractScriptExecutingMessageProcessor() { | ||
| this(new DefaultScriptVariableGenerator()); | ||
|
|
@@ -71,20 +72,19 @@ protected ScriptVariableGenerator getScriptVariableGenerator() { | |
| return this.scriptVariableGenerator; | ||
| } | ||
|
|
||
| protected ClassLoader getBeanClassLoader() { | ||
| protected @Nullable ClassLoader getBeanClassLoader() { | ||
| return this.beanClassLoader; | ||
| } | ||
|
|
||
| protected BeanFactory getBeanFactory() { | ||
| protected @Nullable BeanFactory getBeanFactory() { | ||
| return this.beanFactory; | ||
| } | ||
|
|
||
| /** | ||
| * Execute the script and return the result. | ||
| */ | ||
| @Override | ||
| @Nullable | ||
| public final T processMessage(Message<?> message) { | ||
| public final @Nullable T processMessage(@Nullable Message<?> message) { | ||
| ScriptSource source = getScriptSource(message); | ||
| Map<String, Object> variables = this.scriptVariableGenerator.generateScriptVariables(message); | ||
| return executeScript(source, variables); | ||
|
|
@@ -96,7 +96,7 @@ public final T processMessage(Message<?> message) { | |
| * @param message the message being processed | ||
| * @return a ScriptSource to use to create a script | ||
| */ | ||
| protected abstract ScriptSource getScriptSource(Message<?> message); | ||
| protected abstract ScriptSource getScriptSource(@Nullable Message<?> message); | ||
|
|
||
| /** | ||
| * Subclasses must implement this method. In doing so, the execution context | ||
|
|
@@ -105,7 +105,6 @@ public final T processMessage(Message<?> message) { | |
| * @param variables The variables. | ||
| * @return The result of the execution. | ||
| */ | ||
| @Nullable | ||
| protected abstract T executeScript(ScriptSource scriptSource, Map<String, Object> variables); | ||
| protected abstract @Nullable T executeScript(ScriptSource scriptSource, Map<String, Object> variables); | ||
|
|
||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,6 +20,8 @@ | |
| import java.util.HashMap; | ||
| import java.util.Map; | ||
|
|
||
| import org.jspecify.annotations.Nullable; | ||
|
|
||
| import org.springframework.messaging.Message; | ||
| import org.springframework.util.CollectionUtils; | ||
|
|
||
|
|
@@ -44,8 +46,8 @@ public DefaultScriptVariableGenerator(Map<String, Object> variableMap) { | |
| this.variableMap = variableMap; | ||
| } | ||
|
|
||
| public Map<String, Object> generateScriptVariables(Message<?> message) { | ||
| Map<String, Object> scriptVariables = new HashMap<String, Object>(); | ||
| public Map<String, Object> generateScriptVariables(@Nullable Message<?> message) { | ||
|
||
| Map<String, Object> scriptVariables = new HashMap<>(); | ||
| // Add Message content | ||
| if (message != null) { | ||
| scriptVariables.put("payload", message.getPayload()); | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
...g/src/main/java/org/springframework/integration/scripting/config/jsr223/package-info.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| /** | ||
| * Provides classes for configuration - parsers, namespace handlers. | ||
| */ | ||
| @org.jspecify.annotations.NullMarked | ||
| package org.springframework.integration.scripting.config.jsr223; |
1 change: 1 addition & 0 deletions
1
...cripting/src/main/java/org/springframework/integration/scripting/config/package-info.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| /** | ||
| * Base package supporting configuration. | ||
| */ | ||
| @org.jspecify.annotations.NullMarked | ||
| package org.springframework.integration.scripting.config; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...n-scripting/src/main/java/org/springframework/integration/scripting/dsl/package-info.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| /** | ||
| * Provides Scripting Components support for Spring Integration Java DSL. | ||
| */ | ||
| @org.springframework.lang.NonNullApi | ||
| @org.jspecify.annotations.NullMarked | ||
| package org.springframework.integration.scripting.dsl; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's fix
ScriptExecutingMessageSourceinstead providing a fake message instance!The
MessageProcessorcotnract is to not accept null for themessageargument.That could be a
static finalproperty in theScriptExecutingMessageSourcewithbyte[0]as payload.