apache / netbeans

Apache NetBeans
https://netbeans.apache.org/
Apache License 2.0
2.67k stars 855 forks source link

remove finalizer usage #5440

Open mbien opened 1 year ago

mbien commented 1 year ago

the finalization mechanism is deprecated for removal. NetBeans is still using it occasionally.

Usage must be replaced with alternatives like for example the Java 9 Cleaner API where needed.

JEP: https://openjdk.org/jeps/421

there is a command line flag which simplifies testing during the transition period:

Finalization remains enabled by default in JDK 18. 
  A new command-line option --finalization=disabled disables finalization. 
  A JVM launched with --finalization=disabled will not run any finalizers — not even those declared within the JDK itself.
matthiasblaesing commented 1 year ago

And another query with jackpot (using the "finalize() declared" hint):

contrib/websvc.wsitconf/src/org/netbeans/modules/websvc/wsitconf/design/SecurityConfiguration.java:233
contrib/websvc.wsitconf/src/org/netbeans/modules/websvc/wsitconf/design/MtomConfiguration.java:184
contrib/websvc.wsitconf/src/org/netbeans/modules/websvc/wsitconf/design/RMConfiguration.java:194
harness/jellytools.platform/src/org/netbeans/jellytools/MainWindowOperator.java:513
ide/versioning.util/src/org/netbeans/modules/turbo/Turbo.java:136
ide/o.apache.xml.resolver/build/external-patch/sources/org/apache/xml/resolver/readers/TextCatalogReader.java:184
ide/xml.retriever/src/org/netbeans/modules/xml/retriever/catalog/impl/CatalogFileWrapperDOMImpl.java:642
ide/db.dataview/src/org/netbeans/modules/db/dataview/util/FileBackedBlob.java:238
ide/db.dataview/src/org/netbeans/modules/db/dataview/util/FileBackedClob.java:263
ide/editor.lib/src/org/netbeans/editor/MarkBlock.java:555
ide/editor.lib/src/org/netbeans/editor/LeafElement.java:66
ide/editor/src/org/netbeans/modules/editor/NbEditorUI.java:820
ide/subversion/src/org/netbeans/modules/subversion/client/SvnClientInvocationHandler.java:478
ide/lib.terminalemulator/src/org/netbeans/lib/terminalemulator/MyFontMetrics.java:149
ide/spi.debugger.ui/src/org/netbeans/modules/debugger/ui/eval/CodeEvaluatorUI.java:391
java/performance.java/test/qa-functional/data/SystemProperties/src/org/myorg/systemproperties/OnePropNode.java:105
java/xml.jaxb/src/org/netbeans/modules/xml/jaxb/ui/JAXBWizardIterator.java:87
java/refactoring.java/test/qa-functional/data/projects/RefactoringTest/src/inspectAndTransform/Class_A_E.java:8
java/refactoring.java/test/qa-functional/data/projects/RefactoringTest/src/inspectAndTransform/Class_A_B.java:5
java/refactoring.java/test/qa-functional/data/projects/RefactoringTest/src/inspectAndTransform/Class_A_A.java:5
java/debugger.jpda.ui/src/org/netbeans/modules/debugger/jpda/ui/actions/CheckDeadlocksAction.java:149
profiler/lib.profiler/src/org/netbeans/lib/profiler/heap/NumberList.java:93
profiler/lib.profiler/src/org/netbeans/lib/profiler/heap/AbstractLongMap.java:81
platform/openide.nodes/src/org/openide/util/actions/CookieAction.java:295
platform/openide.nodes/src/org/openide/util/actions/CookieAction.java:401
platform/openide.nodes/src/org/openide/nodes/FilterNode.java:1448
platform/openide.nodes/src/org/openide/nodes/EntrySupportLazy.java:908
platform/openide.nodes/test/unit/src/org/openide/nodes/ChildrenKeysTest.java:915
platform/openide.explorer/src/org/openide/explorer/propertysheet/SheetTable.java:237
platform/o.n.bootstrap/src/org/netbeans/JarClassLoader.java:867
platform/o.n.bootstrap/src/org/netbeans/ModuleManager.java:645
platform/openide.util/test/unit/src/org/openide/util/ReadWriteAccessTest.java:1045
platform/openide.filesystems/src/org/openide/filesystems/MIMESupport.java:660
platform/openide.filesystems/src/org/openide/filesystems/FileLock.java:112
platform/openide.filesystems/src/org/openide/filesystems/JarFileSystem.java:649
platform/openide.filesystems/src/org/openide/filesystems/DefaultAttributes.java:805
platform/openide.filesystems/test/unit/src/org/openide/filesystems/FileObjectTestHid.java:2877
platform/o.n.core/src/org/netbeans/core/NbStatusDisplayer.java:170
platform/openide.awt/src/org/openide/awt/StatusDisplayer.java:130
platform/openide.util.lookup/src/org/openide/util/lookup/ProxyLookup.java:427
platform/openide.util.ui/src/org/openide/util/actions/CallbackSystemAction.java:719
platform/openide.util.ui/src/org/openide/util/SharedClassObject.java:199
platform/openide.util.ui/test/unit/src/org/openide/util/MutexTest.java:1069
neilcsmith-net commented 1 year ago

Usage must be replaced with alternatives like for example the Java 9 Cleaner API where needed.

We also already have a somewhat similar utilities API which might be of use for this? - https://bits.netbeans.org/17/javadoc/org-openide-util/org/openide/util/BaseUtilities.html#activeReferenceQueue--

jtulach commented 1 year ago

Yes, go on and replace finalize with (active) ReferenceQueue. There is no point in sticking with finalize - queues are more friendly to GC and provide similar experience.

neilcsmith-net commented 1 year ago

We should consider what is happening in #5878 should we decide to introduce more usage of active reference queue over cleaner API.

mbien commented 1 year ago

IMO: JDK APIs should be always preferred over self written/third party implementations.

neilcsmith-net commented 1 year ago

@mbien agreed, and we're free to use Cleaner now. I assume we're going to punt this forward to at least NB20 though?

mbien commented 1 year ago

@neilcsmith-net we could probably remove the milestone entirely. But having a milestone makes it probably also less likely that we forget about it.

neilcsmith-net commented 1 year ago

@mbien true, and the ultimate milestone is this being removed from the next JDK, which I haven't seen scheduled so far.