Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace finalize() with Cleaner #139

Open
wants to merge 6 commits into
base: trunk
Choose a base branch
from

Conversation

rototor
Copy link

@rototor rototor commented Jan 15, 2022

Finalizers (method finalize()) are going to be deprecated for removal with JDK 18. See https://openjdk.java.net/jeps/421 for details.

The best way to replace the finalize() methods is by using the JDK 9 java.lang.ref.Cleaner. As PDFBox 3 targets JDK 8 this can not be used directly.

The attached patch implements a Cleaner using finalizers for JDK <= 8 and using java.lang.ref.Cleaner by reflection for JDK 9+.

The two remaining finalize() implementing classes are migrated to the new Cleaner.

I’m not really happy with the name and package org.apache.fontbox.util.PdfBoxInternalCleaner of the cleaner. Maybe you have an idea for a better place and name.

In theory this patch could be back ported to PDFBox 2, but I’m not sure if this is worth the risk.

@rototor
Copy link
Author

rototor commented Jan 15, 2022

See also the JIRA Ticket https://issues.apache.org/jira/browse/PDFBOX-5362

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant