feat: 修复注解链的bug

This commit is contained in:
wangyu 2024-11-28 19:50:49 +08:00
parent 39fe3ace5d
commit 73891dca70

View File

@ -65,7 +65,7 @@ public class EmptyAnnotationChain<A extends Annotation, T> extends BasicAnnotati
*/ */
@Override @Override
public BeanPropertyAnnotationChain<A, T> then(Consumer<T> consumer) { public BeanPropertyAnnotationChain<A, T> then(Consumer<T> consumer) {
parent.last(false); markParent();
return this; return this;
} }
@ -77,7 +77,7 @@ public class EmptyAnnotationChain<A extends Annotation, T> extends BasicAnnotati
*/ */
@Override @Override
public BeanPropertyAnnotationChain<A, T> exists(Runnable handler) { public BeanPropertyAnnotationChain<A, T> exists(Runnable handler) {
parent.last(false); markParent();
return this; return this;
} }
@ -135,4 +135,15 @@ public class EmptyAnnotationChain<A extends Annotation, T> extends BasicAnnotati
protected BeanPropertyAnnotations cache() { protected BeanPropertyAnnotations cache() {
return parent; return parent;
} }
/**
* 需要判定之前的值当我们进入空链且调用了then
* 代表在没值的时候下次尝试用or时仍可获取值and总是成立
*/
private void markParent() {
// 当且仅当链上没有值才尝试置为false供后续使用
if (null == parent.value()) {
parent.last(false);
}
}
} }