Skip to content

Conversation

axreldable
Copy link
Contributor

@axreldable axreldable commented Jul 7, 2025

Why are these changes needed?

Add encapsulation of fields and immutability for exposed structures such as maps and lists in classes within the io.ray.api.options module, as requested in issue #54310.

Related issue number

Closes #54310

Checks

  • I've signed off every commit(by using the -s flag, i.e., git commit -s) in this PR.
  • I've run scripts/format.sh to lint the changes in this PR.
  • I've included any doc changes needed for https://docs.ray.io/en/master/.
    • I've added any new APIs to the API Reference. For example, if I added a
      method in Tune, I've added it in doc/source/tune/api/ under the
      corresponding .rst file.
  • I've made sure the tests are passing. Note that there might be a few flaky tests, see the recent failures at https://flakey-tests.ray.io/
  • Testing Strategy
    • Unit tests
    • Release tests
    • This PR is not tested :(

@Copilot Copilot AI review requested due to automatic review settings July 7, 2025 15:49
Copilot

This comment was marked as outdated.

@axreldable axreldable force-pushed the java_encapsulation branch from 7b4a057 to 607a3e5 Compare July 7, 2025 16:03
@axreldable axreldable force-pushed the java_encapsulation branch from 607a3e5 to 14f7bd4 Compare July 7, 2025 16:08
@axreldable
Copy link
Contributor Author

axreldable commented Jul 7, 2025

Hi, @codope!
Could you please check if the PR addresses what you requested in the issue #54310?

@axreldable axreldable requested a review from Copilot July 7, 2025 17:04
Copilot

This comment was marked as outdated.

@axreldable axreldable requested a review from Copilot July 7, 2025 17:25
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR refactors several option classes to enforce encapsulation and immutability, and updates code sites to use the new getters.

  • Converted public fields in option classes to private finals with getters and builder patterns
  • Wrapped mutable collections (resources, bundles, concurrency groups) in unmodifiable views
  • Updated runtime/task submitter and core runtime code to replace field access with the new getters

Reviewed Changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
java/runtime/.../NativeTaskSubmitter.java Replaced direct field access with getters
java/runtime/.../LocalModeTaskSubmitter.java Replaced direct field access with getters
java/runtime/.../AbstractRayRuntime.java Switched to getters for jvmOptions
java/api/.../PlacementGroupCreationOptions.java Introduced builder pattern and immutable bundles
java/api/.../CallOptions.java Introduced builder pattern and getters
java/api/.../BaseTaskOptions.java Made resources map immutable with getter
java/api/.../ActorCreationOptions.java Introduced builder pattern and getters
Comments suppressed due to low confidence (4)

java/api/src/main/java/io/ray/api/options/CallOptions.java:43

  • [nitpick] The getter name getSerializedRuntimeEnvInfo differs from ActorCreationOptions' getSerializedRuntimeEnv; consider aligning these names for consistency.
  public String getSerializedRuntimeEnvInfo() {

java/api/src/main/java/io/ray/api/options/ActorCreationOptions.java:87

  • [nitpick] The getter name getSerializedRuntimeEnv is inconsistent with CallOptions' getSerializedRuntimeEnvInfo; unifying naming across option classes would improve API clarity.
  public String getSerializedRuntimeEnv() {

java/api/src/main/java/io/ray/api/options/CallOptions.java:117

  • Switching from a public constructor to a builder-only approach is a breaking change; consider deprecating the old constructor or providing migration notes in the API docs.
      return new CallOptions(this);

java/runtime/src/main/java/io/ray/runtime/task/NativeTaskSubmitter.java:63

  • [nitpick] The error message 'Actor of name %s exists' could be clearer; for example, 'An actor with name %s already exists.'
            !actor.isPresent(), String.format("Actor of name %s exists", options.getName()));

Comment on lines 49 to +57
Preconditions.checkArgument(
options.bundleIndex == -1
|| options.bundleIndex >= 0 && options.bundleIndex < group.getBundles().size(),
options.getBundleIndex() == -1
|| options.getBundleIndex() >= 0
&& options.getBundleIndex() < group.getBundles().size(),
String.format(
"Bundle index %s is invalid, the correct bundle index should be "
+ "either in the range of 0 to the number of bundles "
+ "or -1 which means put the task to any available bundles.",
options.bundleIndex));
options.getBundleIndex()));
Copy link
Preview

Copilot AI Jul 7, 2025

Choose a reason for hiding this comment

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

[nitpick] Consider assigning options.getBundleIndex() to a local variable to avoid repeated method calls and improve readability.

Copilot uses AI. Check for mistakes.

@codope codope added the go add ONLY when ready to merge, run all tests label Jul 8, 2025
Copy link
Contributor

@codope codope left a comment

Choose a reason for hiding this comment

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

@axreldable Thanks for the contribution! This is in line with my expectation. Left one minor comment.

@codope codope self-assigned this Jul 8, 2025
… BaseTaskOptions class + unit tests

Signed-off-by: axreldable <[email protected]>
@axreldable axreldable requested a review from codope July 8, 2025 13:19
@codope
Copy link
Contributor

codope commented Jul 8, 2025

@kfstorm @SongGuyang @WangTaoTheTonic @raulchen Could you please take a look and merge the PR?

@cszhu cszhu added community-contribution Contributed by the community core Issues that should be addressed in Ray Core labels Jul 9, 2025
@axreldable
Copy link
Contributor Author

Hi @kfstorm @SongGuyang @WangTaoTheTonic @raulchen ,
Could you kindly check the PR? Thank you!

@jjyao jjyao merged commit 7b9f799 into ray-project:master Jul 18, 2025
5 checks passed
dshepelev15 pushed a commit to dshepelev15/ray that referenced this pull request Jul 21, 2025
alimaazamat pushed a commit to alimaazamat/ray that referenced this pull request Jul 24, 2025
krishnakalyan3 pushed a commit to krishnakalyan3/ray that referenced this pull request Jul 30, 2025
@axreldable axreldable deleted the java_encapsulation branch August 10, 2025 10:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
community-contribution Contributed by the community core Issues that should be addressed in Ray Core go add ONLY when ready to merge, run all tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[core-language][Java][refactor] Task and actor creation options expose public fields breaking encapsulation
4 participants