fix: check if property is bound before setting value of ReadWriteComposedProperty

This commit is contained in:
Haowei Wen 2021-09-01 16:41:07 +08:00
parent 832c029db6
commit e428cc7117
No known key found for this signature in database
GPG Key ID: 5BC167F73EA558E4

View File

@ -1,6 +1,6 @@
/*
* Hello Minecraft! Launcher
* Copyright (C) 2020 huangyuhui <huanghongxun2008@126.com> and contributors
* Copyright (C) 2021 huangyuhui <huanghongxun2008@126.com> and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -44,7 +44,11 @@ public class ReadWriteComposedProperty<T> extends SimpleObjectProperty<T> {
this.readSource = readSource;
this.writeTarget = writeTarget;
this.listener = (observable, oldValue, newValue) -> set(newValue);
this.listener = (observable, oldValue, newValue) -> {
if (!isBound()) {
set(newValue);
}
};
readSource.addListener(new WeakChangeListener<>(listener));
set(readSource.getValue());
}