eclipse-platform / eclipse-platform/eclipse.platform

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

Open
#1,801 1 comment 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
Java
Stars
165
Forks
174
Avg merge
2d 8h
Merged PRs (30d)
22

Description

### Description
Enhance `ResourceAttributes.java`:

- `fromFile(java.io.File file)` now returns `Optional` 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` 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.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.