Skip to content

Commit

Permalink
8196586: Remove use of deprecated finalize methods from javafx proper…
Browse files Browse the repository at this point in the history
…ty objects

Reviewed-by: nlisker, arapte
  • Loading branch information
kevinrushforth committed Feb 27, 2020
1 parent ef2f9ce commit 9cd6f79
Show file tree
Hide file tree
Showing 7 changed files with 215 additions and 166 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -163,17 +163,6 @@ private static <T extends Number> BidirectionalBinding bindNumber(Property<T> pr
return binding;
}

public static <T extends Number> void unbindNumber(Property<T> property1, Property<Number> property2) {
checkParameters(property1, property2);
final BidirectionalBinding binding = new UntypedGenericBidirectionalBinding(property1, property2);
if (property1 instanceof ObservableValue) {
((ObservableValue) property1).removeListener(binding);
}
if (property2 instanceof Observable) {
((ObservableValue) property2).removeListener(binding);
}
}

private final int cachedHashCode;

private BidirectionalBinding(Object property1, Object property2) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,6 @@
import javafx.beans.value.WritableBooleanValue;
import com.sun.javafx.binding.Logging;

import java.security.AccessControlContext;
import java.security.AccessController;
import java.security.PrivilegedAction;

/**
* This class provides a full implementation of a {@link Property} wrapping a
* {@code boolean} value.
Expand Down Expand Up @@ -141,7 +137,6 @@ public static BooleanProperty booleanProperty(final Property<Boolean> property)
throw new NullPointerException("Property cannot be null");
}
return property instanceof BooleanProperty ? (BooleanProperty)property : new BooleanPropertyBase() {
private final AccessControlContext acc = AccessController.getContext();
{
BidirectionalBinding.bind(this, property);
}
Expand All @@ -155,18 +150,6 @@ public Object getBean() {
public String getName() {
return property.getName();
}

@Override
protected void finalize() throws Throwable {
try {
AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
BidirectionalBinding.unbind(property, this);
return null;
}, acc);
} finally {
super.finalize();
}
}
};
}

Expand All @@ -182,7 +165,6 @@ protected void finalize() throws Throwable {
@Override
public ObjectProperty<Boolean> asObject() {
return new ObjectPropertyBase<Boolean> () {
private final AccessControlContext acc = AccessController.getContext();
{
BidirectionalBinding.bind(this, BooleanProperty.this);
}
Expand All @@ -196,19 +178,6 @@ public Object getBean() {
public String getName() {
return BooleanProperty.this.getName();
}

@Override
protected void finalize() throws Throwable {
try {
AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
BidirectionalBinding.unbind(this, BooleanProperty.this);
return null;
}, acc);
} finally {
super.finalize();
}
}

};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,6 @@
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableDoubleValue;

import java.security.AccessControlContext;
import java.security.AccessController;
import java.security.PrivilegedAction;

/**
* This class defines a {@link Property} wrapping a {@code double} value.
* <p>
Expand Down Expand Up @@ -156,7 +152,6 @@ public static DoubleProperty doubleProperty(final Property<Double> property) {
throw new NullPointerException("Property cannot be null");
}
return new DoublePropertyBase() {
private final AccessControlContext acc = AccessController.getContext();
{
BidirectionalBinding.bindNumber(this, property);
}
Expand All @@ -170,18 +165,6 @@ public Object getBean() {
public String getName() {
return property.getName();
}

@Override
protected void finalize() throws Throwable {
try {
AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
BidirectionalBinding.unbindNumber(property, this);
return null;
}, acc);
} finally {
super.finalize();
}
}
};
}

Expand All @@ -207,7 +190,6 @@ protected void finalize() throws Throwable {
@Override
public ObjectProperty<Double> asObject() {
return new ObjectPropertyBase<Double> () {
private final AccessControlContext acc = AccessController.getContext();
{
BidirectionalBinding.bindNumber(this, DoubleProperty.this);
}
Expand All @@ -221,19 +203,6 @@ public Object getBean() {
public String getName() {
return DoubleProperty.this.getName();
}

@Override
protected void finalize() throws Throwable {
try {
AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
BidirectionalBinding.unbindNumber(this, DoubleProperty.this);
return null;
}, acc);
} finally {
super.finalize();
}
}

};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,6 @@
import javafx.beans.value.WritableFloatValue;
import com.sun.javafx.binding.Logging;

import java.security.AccessControlContext;
import java.security.AccessController;
import java.security.PrivilegedAction;

/**
* This class defines a {@link Property} wrapping a {@code float} value.
* <p>
Expand Down Expand Up @@ -151,7 +147,6 @@ public static FloatProperty floatProperty(final Property<Float> property) {
throw new NullPointerException("Property cannot be null");
}
return new FloatPropertyBase() {
private final AccessControlContext acc = AccessController.getContext();
{
BidirectionalBinding.bindNumber(this, property);
}
Expand All @@ -165,18 +160,6 @@ public Object getBean() {
public String getName() {
return property.getName();
}

@Override
protected void finalize() throws Throwable {
try {
AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
BidirectionalBinding.unbindNumber(property, this);
return null;
}, acc);
} finally {
super.finalize();
}
}
};
}

Expand All @@ -202,7 +185,6 @@ protected void finalize() throws Throwable {
@Override
public ObjectProperty<Float> asObject() {
return new ObjectPropertyBase<Float> () {
private final AccessControlContext acc = AccessController.getContext();
{
BidirectionalBinding.bindNumber(this, FloatProperty.this);
}
Expand All @@ -216,19 +198,6 @@ public Object getBean() {
public String getName() {
return FloatProperty.this.getName();
}

@Override
protected void finalize() throws Throwable {
try {
AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
BidirectionalBinding.unbindNumber(this, FloatProperty.this);
return null;
}, acc);
} finally {
super.finalize();
}
}

};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,6 @@
import javafx.beans.value.WritableIntegerValue;
import com.sun.javafx.binding.Logging;

import java.security.AccessControlContext;
import java.security.AccessController;
import java.security.PrivilegedAction;

/**
* This class defines a {@link Property} wrapping an {@code int} value.
* <p>
Expand Down Expand Up @@ -151,7 +147,6 @@ public static IntegerProperty integerProperty(final Property<Integer> property)
throw new NullPointerException("Property cannot be null");
}
return new IntegerPropertyBase() {
private final AccessControlContext acc = AccessController.getContext();
{
BidirectionalBinding.bindNumber(this, property);
}
Expand All @@ -165,18 +160,6 @@ public Object getBean() {
public String getName() {
return property.getName();
}

@Override
protected void finalize() throws Throwable {
try {
AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
BidirectionalBinding.unbindNumber(property, this);
return null;
}, acc);
} finally {
super.finalize();
}
}
};
}

Expand All @@ -202,7 +185,6 @@ protected void finalize() throws Throwable {
@Override
public ObjectProperty<Integer> asObject() {
return new ObjectPropertyBase<Integer> () {
private final AccessControlContext acc = AccessController.getContext();
{
BidirectionalBinding.bindNumber(this, IntegerProperty.this);
}
Expand All @@ -216,19 +198,6 @@ public Object getBean() {
public String getName() {
return IntegerProperty.this.getName();
}

@Override
protected void finalize() throws Throwable {
try {
AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
BidirectionalBinding.unbindNumber(this, IntegerProperty.this);
return null;
}, acc);
} finally {
super.finalize();
}
}

};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,6 @@
import javafx.beans.value.WritableLongValue;
import com.sun.javafx.binding.Logging;

import java.security.AccessControlContext;
import java.security.AccessController;
import java.security.PrivilegedAction;

/**
* This class defines a {@link Property} wrapping a {@code long} value.
* <p>
Expand Down Expand Up @@ -149,7 +145,6 @@ public static LongProperty longProperty(final Property<Long> property) {
throw new NullPointerException("Property cannot be null");
}
return new LongPropertyBase() {
private final AccessControlContext acc = AccessController.getContext();
{
BidirectionalBinding.bindNumber(this, property);
}
Expand All @@ -163,18 +158,6 @@ public Object getBean() {
public String getName() {
return property.getName();
}

@Override
protected void finalize() throws Throwable {
try {
AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
BidirectionalBinding.unbindNumber(property, this);
return null;
}, acc);
} finally {
super.finalize();
}
}
};
}

Expand All @@ -200,7 +183,6 @@ protected void finalize() throws Throwable {
@Override
public ObjectProperty<Long> asObject() {
return new ObjectPropertyBase<Long> () {
private final AccessControlContext acc = AccessController.getContext();
{
BidirectionalBinding.bindNumber(this, LongProperty.this);
}
Expand All @@ -214,19 +196,6 @@ public Object getBean() {
public String getName() {
return LongProperty.this.getName();
}

@Override
protected void finalize() throws Throwable {
try {
AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
BidirectionalBinding.unbindNumber(this, LongProperty.this);
return null;
}, acc);
} finally {
super.finalize();
}
}

};
}
}
Loading

0 comments on commit 9cd6f79

Please sign in to comment.