[wpilibj] Remove finalizers (#4158)

They were deprecated for removal in Java 18 because they're error-prone.
Prefer AutoCloseable and Cleaner instead.

https://openjdk.java.net/jeps/421
https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/lang/ref/Cleaner.html
This commit is contained in:
Tyler Veness
2022-04-24 07:21:08 -07:00
committed by GitHub
parent b3aee28388
commit 3919250da2
4 changed files with 3 additions and 23 deletions

View File

@@ -30,12 +30,6 @@ public class Notifier implements AutoCloseable {
// is until we call the handler.
private double m_periodSeconds;
@Override
@SuppressWarnings("NoFinalizer")
protected void finalize() {
close();
}
@Override
public void close() {
int handle = m_notifier.getAndSet(0);

View File

@@ -94,8 +94,7 @@ public class TimedRobot extends IterativeRobotBase {
}
@Override
@SuppressWarnings("NoFinalizer")
protected void finalize() {
public void close() {
NotifierJNI.stopNotifier(m_notifier);
NotifierJNI.cleanNotifier(m_notifier);
}

View File

@@ -93,16 +93,4 @@ public class CallbackStore implements AutoCloseable {
}
m_cancelType = -1;
}
@SuppressWarnings({"NoFinalizer", "deprecation"})
@Override
protected void finalize() throws Throwable {
try {
if (m_cancelType >= 0) {
close(); // close open files
}
} finally {
super.finalize();
}
}
}

View File

@@ -20,14 +20,13 @@ import java.util.function.Function;
import java.util.function.Supplier;
public class SendableBuilderImpl implements NTSendableBuilder {
private static class Property {
private static class Property implements AutoCloseable {
Property(NetworkTable table, String key) {
m_entry = table.getEntry(key);
}
@Override
@SuppressWarnings("NoFinalizer")
protected synchronized void finalize() {
public void close() {
stopListener();
}