Skip to content

Commit

Permalink
Revert the changes to avoid deprecation of finalize()
Browse files Browse the repository at this point in the history
  • Loading branch information
pradeepbn committed Oct 7, 2021
1 parent 22c3cfd commit 9285c10
Showing 1 changed file with 6 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import static com.scurrilous.circe.utils.NativeUtils.loadLibraryFromJar;
import static com.scurrilous.circe.utils.NativeUtils.libType;

import java.lang.ref.Cleaner;
import java.nio.ByteBuffer;
import com.scurrilous.circe.IncrementalIntHash;
import com.scurrilous.circe.impl.AbstractIncrementalIntHash;
Expand Down Expand Up @@ -55,23 +54,6 @@ public static boolean isSupported() {
config = 0;
}

// A cleaner similar to a finalizer(deprecated in java11)
private static final Cleaner cleaner = Cleaner.create();

static class State implements Runnable {
private final long config;
State(long config) {
// initialize State needed for cleaning action
this.config = config;
}

public void run() {
// cleanup action accessing State, executed at most once
if (this.config != 0)
freeConfig(this.config);
}
}

public Sse42Crc32C(int[] chunkWords) {
if (chunkWords.length == 0) {
config = 0;
Expand All @@ -80,7 +62,12 @@ public Sse42Crc32C(int[] chunkWords) {
if (config == 0)
throw new RuntimeException("CRC32C configuration allocation failed");
}
cleaner.register(config, new State(config));
}

@Override
protected void finalize() {
if (config != 0)
freeConfig(config);
}

@Override
Expand Down

0 comments on commit 9285c10

Please sign in to comment.