Skip to content

Conversation

@basil
Copy link
Member

@basil basil commented Sep 13, 2023

Recent versions of Java have deprecated Object#finalize and marked it for removal:

[WARNING] AtomicFileWriter.java:[229,19] [removal] finalize() in Object has been deprecated and marked for removal
[WARNING] AtomicFileWriter.java:[233,17] [removal] finalize() in Object has been deprecated and marked for removal

In this PR we proactively migrate away from this deprecated API in favor of its Java 9+ replacement.

As a bonus, we also implement the advice given by Joshua Bloch in Effective Java (emphasis not mine):

So what, if anything, are finalizers good for? […] One is to act as a “safety net” in case the owner of an object forgets to call its explicit termination method. While there’s no guarantee that the finalizer will be invoked promptly, it may be better to free the resource late than never, in those (hopefully rare) cases when the client fails to call the explicit termination method. But the finalizer should log a warning if it finds that the resource has not been terminated, as this indicates a bug in the client code, which should be fixed.

We also add test coverage for this functionality. The new test passes before the changes to src/main, demonstrating there is no regression.

Testing done

Ran AtomicFileWriterTest on Java 17 on both Linux and Windows.

Proposed changelog entries

N/A

Proposed upgrade guidelines

N/A

### Submitter checklist
- [ ] The Jira issue, if it exists, is well-described.
- [ ] The changelog entries and upgrade guidelines are appropriate for the audience affected by the change (users or developers, depending on the change) and are in the imperative mood (see [examples](https://github.com/jenkins-infra/jenkins.io/blob/master/content/_data/changelogs/weekly.yml)). Fill in the **Proposed upgrade guidelines** section only if there are breaking changes or changes that may require extra steps from users during upgrade.
- [ ] There is automated testing or an explanation as to why this change has no tests.
- [ ] New public classes, fields, and methods are annotated with `@Restricted` or have `@since TODO` Javadocs, as appropriate.
- [ ] New deprecations are annotated with `@Deprecated(since = "TODO")` or `@Deprecated(forRemoval = true, since = "TODO")`, if applicable.
- [ ] New or substantially changed JavaScript is not defined inline and does not call `eval` to ease future introduction of Content Security Policy (CSP) directives (see [documentation](https://www.jenkins.io/doc/developer/security/csp/)).
- [ ] For dependency updates, there are links to external changelogs and, if possible, full differentials.
- [ ] For new APIs and extension points, there is a link to at least one consumer.

Desired reviewers

@mention

Before the changes are marked as ready-for-merge:

### Maintainer checklist
- [ ] There are at least two (2) approvals for the pull request and no outstanding requests for change.
- [ ] Conversations in the pull request are over, or it is explicit that a reviewer is not blocking the change.
- [ ] Changelog entries in the pull request title and/or **Proposed changelog entries** are accurate, human-readable, and in the imperative mood.
- [ ] Proper changelog labels are set so that the changelog can be generated automatically.
- [ ] If the change needs additional upgrade steps from users, the `upgrade-guide-needed` label is set and there is a **Proposed upgrade guidelines** section in the pull request title (see [example](https://github.com/jenkinsci/jenkins/pull/4387)).
- [ ] If it would make sense to backport the change to LTS, a Jira issue must exist, be a _Bug_ or _Improvement_, and be labeled as `lts-candidate` to be considered (see [query](https://issues.jenkins.io/issues/?filter=12146)).

@basil basil added the skip-changelog Should not be shown in the changelog label Sep 13, 2023
Path tmpPath = ref.get().getTemporaryPath();
assertTrue(Files.exists(tmpPath));
assertFalse(Files.exists(destPath));
MemoryAssert.assertGC(ref);
Copy link
Member Author

Choose a reason for hiding this comment

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

In a separate test in test/ rather than in core/src/test/ to be able to have access to MemoryAssert.

@NotMyFault NotMyFault requested a review from a team September 16, 2023 15:45
@NotMyFault NotMyFault requested a review from a team September 17, 2023 14:38
@timja
Copy link
Member

timja commented Sep 17, 2023

/label ready-for-merge


This PR is now ready for merge, after ~24 hours, we will merge it if there's no negative feedback.

Thanks!

@comment-ops-bot comment-ops-bot bot added the ready-for-merge The PR is ready to go, and it will be merged soon if there is no negative feedback label Sep 17, 2023
@NotMyFault NotMyFault removed the request for review from a team September 20, 2023 18:42
@NotMyFault NotMyFault merged commit febca34 into jenkinsci:master Sep 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-for-merge The PR is ready to go, and it will be merged soon if there is no negative feedback skip-changelog Should not be shown in the changelog

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants