eclipse.platform icon indicating copy to clipboard operation
eclipse.platform copied to clipboard

Enhance ResourceAttributes: Use Optional in fromFile() and Improve set() Method

Open SIMJIYEON93 opened this issue 9 months ago • 1 comments

Description

Enhance ResourceAttributes.java:

  • fromFile(java.io.File file) now returns Optional<ResourceAttributes> instead of a nullable object.
  • Improved set(int mask, boolean value) method for better readability and maintainability.
  • Updated Javadoc comments to reflect the new behavior.

Expected behavior

  • Returning Optional<ResourceAttributes> makes the API safer by avoiding potential null references.
  • The set method becomes clearer and more robust.
  • Updated documentation helps future developers understand the new behavior precisely.

Benefits

  • Increases null-safety and code clarity.
  • Improves API usability and developer experience.
  • Aligns with modern Java best practices.

How to reproduce (Current Behavior)

  • ResourceAttributes.fromFile(file) returns null on failure.

How to reproduce (After Improvement)

  • ResourceAttributes.fromFile(file) returns Optional.empty() on failure, making null checks unnecessary.

Additional context

  • All modifications are isolated to org.eclipse.core.resources.ResourceAttributes.
  • No breaking change for existing code unless fromFile() is used without null checking.

Environment

  • Java version: 17
  • Eclipse Platform repository: https://github.com/eclipse-platform/eclipse.platform
  • Module: org.eclipse.core.resources
  • Files involved: ResourceAttributes.java

Community

  • [x] I understand suggesting an enhancement doesn't mandate anyone to implement it. Other contributors may consider this suggestion, or not, at their own convenience. The most efficient way to get it fixed is that I implement it myself and contribute it back as a good quality patch to the project.

SIMJIYEON93 avatar Apr 05 '25 09:04 SIMJIYEON93

Should this be kept open given that the according PR #1802 was closed or may we close this issue as well?

HeikoKlare avatar Apr 14 '25 10:04 HeikoKlare