Skip to content

Priority comparator overflow in ServicePriority #1797

Closed

Description

@mathecruz

What happened:
ServicePriority.compareTo uses a subtraction-based comparator, the same anti-pattern as #1795:

public interface ServicePriority extends Comparable<ServicePriority> {
  static final int DEFAULT_PRIORITY = 1000;
  default int priority() { return DEFAULT_PRIORITY; }

  @Override
  default int compareTo(ServicePriority other) {
    return this.priority() - other.priority();
  }
}

ServicePriority backs WorkflowUtils.loadFirst, the ServiceLoader-based selection mechanism used by most extension points in the SDK (WorkflowModelFactory, SchemaValidatorFactory, TaskExecutorFactory, EventConsumer, CronResolverFactory, ConfigManager, SecretManager, URITemplateResolver, FunctionReader, CloudEventPredicateFactory, ObjectMapperFactory, AccessTokenProviderFactory, CustomObjectMarshaller, WorkflowDecorator, among others).

What you expected to happen:

This overflows int when an implementor returns a priority() close to Integer.MIN_VALUE/Integer.MAX_VALUE to force "always win"/"always lose" semantics, causing the wrong implementation to be picked by WorkflowUtils.loadFirst silently, with no exception. Same root cause as #1795, but affecting the shared mechanism behind nearly every ServiceLoader-based extension point in the SDK, not just ExpressionFactory.

How to reproduce it:

Register two ServicePriority implementations via ServiceLoader: one with the plain DEFAULT_PRIORITY, another overriding priority() to return Integer.MIN_VALUE so it should always win. Call WorkflowUtils.loadFirst. The DEFAULT_PRIORITY one wins instead.

Anything else we need to know?:

Same fix as #1795: replace the subtraction with Integer.compare(this.priority(), other.priority()).

Environment:

  • Specification version used:

Activity

  1. added
    javaPull requests that update java code
    on Oct 22, 2026
  2. self-assigned this
    on Oct 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

javaPull requests that update java code

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions