Commit eea5d154 authored by Phillip Webb's avatar Phillip Webb

Merge branch '2.1.x'

Closes gh-18219
parents c2023a8c 23174eb4
...@@ -162,7 +162,7 @@ public final class Bindable<T> { ...@@ -162,7 +162,7 @@ public final class Bindable<T> {
existingValue == null || this.type.isArray() || this.boxedType.resolve().isInstance(existingValue), existingValue == null || this.type.isArray() || this.boxedType.resolve().isInstance(existingValue),
() -> "ExistingValue must be an instance of " + this.type); () -> "ExistingValue must be an instance of " + this.type);
Supplier<T> value = (existingValue != null) ? () -> existingValue : null; Supplier<T> value = (existingValue != null) ? () -> existingValue : null;
return new Bindable<>(this.type, this.boxedType, value, NO_ANNOTATIONS); return new Bindable<>(this.type, this.boxedType, value, this.annotations);
} }
/** /**
...@@ -171,7 +171,7 @@ public final class Bindable<T> { ...@@ -171,7 +171,7 @@ public final class Bindable<T> {
* @return an updated {@link Bindable} * @return an updated {@link Bindable}
*/ */
public Bindable<T> withSuppliedValue(Supplier<T> suppliedValue) { public Bindable<T> withSuppliedValue(Supplier<T> suppliedValue) {
return new Bindable<>(this.type, this.boxedType, suppliedValue, NO_ANNOTATIONS); return new Bindable<>(this.type, this.boxedType, suppliedValue, this.annotations);
} }
/** /**
......
...@@ -160,6 +160,20 @@ class BindableTests { ...@@ -160,6 +160,20 @@ class BindableTests {
assertThat(bindable1).isEqualTo(bindable3); assertThat(bindable1).isEqualTo(bindable3);
} }
@Test // gh-18218
public void withExistingValueDoesNotForgetAnnotations() {
Annotation annotation = AnnotationUtils.synthesizeAnnotation(TestAnnotation.class);
Bindable<?> bindable = Bindable.of(String.class).withAnnotations(annotation).withExistingValue("");
assertThat(bindable.getAnnotations()).containsExactly(annotation);
}
@Test // gh-18218
public void withSuppliedValueValueDoesNotForgetAnnotations() {
Annotation annotation = AnnotationUtils.synthesizeAnnotation(TestAnnotation.class);
Bindable<?> bindable = Bindable.of(String.class).withAnnotations(annotation).withSuppliedValue(() -> "");
assertThat(bindable.getAnnotations()).containsExactly(annotation);
}
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
@interface TestAnnotation { @interface TestAnnotation {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment