Skip to content

Commit 3faf6bd

Browse files
committed
fixed (rare) NPE in class ParagraphText when GC frees object between two WeakReference.get() invocations
1 parent 74efc78 commit 3faf6bd

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

richtextfx/src/main/java/org/fxmisc/richtext/ParagraphText.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -459,10 +459,11 @@ public SelectionRangeChangeListener(ParagraphText<PS, SEG, S> paragraphText) {
459459

460460
@Override
461461
public void changed(ObservableValue<? extends IndexRange> observable, IndexRange oldValue, IndexRange newValue) {
462-
if (null == ref.get()) {
462+
ParagraphText<PS, SEG, S> paragraphText = ref.get();
463+
if (null == paragraphText) {
463464
observable.removeListener(this);
464465
} else {
465-
ref.get().requestLayout();
466+
paragraphText.requestLayout();
466467
}
467468
}
468469
}
@@ -476,10 +477,11 @@ public CaretPositionChangeListener(ParagraphText<PS, SEG, S> paragraphText) {
476477

477478
@Override
478479
public void changed(ObservableValue<? extends Integer> observable, Integer oldValue, Integer newValue) {
479-
if (null == ref.get()) {
480+
ParagraphText<PS, SEG, S> paragraphText = ref.get();
481+
if (null == paragraphText) {
480482
observable.removeListener(this);
481483
} else {
482-
ref.get().requestLayout();
484+
paragraphText.requestLayout();
483485
}
484486
}
485487
}

0 commit comments

Comments
 (0)