eclipse.platform
eclipse.platform copied to clipboard
Enhance ResourceAttributes: Use Optional in fromFile() and Improve set() Method
Description
Enhance ResourceAttributes.java:
-
fromFile(java.io.File file)now returnsOptional<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 potentialnullreferences. - The
setmethod 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)returnsnullon failure.
How to reproduce (After Improvement)
-
ResourceAttributes.fromFile(file)returnsOptional.empty()on failure, makingnullchecks 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.
Should this be kept open given that the according PR #1802 was closed or may we close this issue as well?