SDK APIs can add new methods in later versions. If you call a method that doesn’t exist on an earlier Mule runtime version, you get a NoSuchMethodError.
The SDK doesn’t introspect which methods your code actually calls. Even if a method has @MinMuleVersion("4.12.0"), using it doesn’t automatically raise your component’s Minimum Mule Version. You are able to deploy a module to earlier versions where the method doesn’t exist. For this reason, you must check the Mule runtime version before calling new methods, and provide fallback behavior for older versions.
Example: Using a New Method with Fallback
The following example shows how to conditionally call a method that exists in Mule 4.12.0 and later:
import org.mule.runtime.api.meta.MuleVersion;
import org.mule.sdk.api.annotation.RuntimeVersion;
import org.mule.sdk.api.runtime.streaming.StreamingHelper;
public class MyOperations {
@RuntimeVersion
private MuleVersion runtimeVersion;
public void processStream(InputStream stream, StreamingHelper streamingHelper) {
if (runtimeVersion.atLeast("4.12.0")) {
// Use new reset() method available in 4.12.0
streamingHelper.reset(stream);
} else {
// Implement fallback for older runtimes where reset() doesn't exist
if (stream instanceof Cursor) {
((Cursor) stream).seek(0);
} else {
stream.reset();
}
}
}
}
If no fallback is possible, explicitly annotate your operation with @MinMuleVersion to restrict it to compatible versions.