Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ For example:
}
----

NOTE: It is also possible to configure `disallowedFields`, but that's fragile, and
due to be https://github.com/spring-projects/spring-framework/issues/36802[deprecated] in Spring Framework 7.1.
NOTE: It is also possible to configure `disallowedFields`, but that's fragile and
https://github.com/spring-projects/spring-framework/issues/36802[deprecated as of Spring Framework 7.1].
It is easy to overlook fields or introduce additional fields over time that should also be excluded.

By default, `DataBinder` applies both constructor and setter binding.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,6 @@ public boolean isIgnoreInvalidFields() {
* account.
* <p>More sophisticated matching can be implemented by overriding the
* {@link #isAllowed} method.
* <p>Alternatively, specify a list of <i>disallowed</i> field patterns.
* <p>Used for binding to fields with {@link #bind(PropertyValues)}, and not
* applicable to constructor binding via {@link #construct},
* which uses only the values it needs.
Expand Down Expand Up @@ -551,7 +550,9 @@ public void setAllowedFields(String @Nullable ... allowedFields) {
* @param disallowedFields array of disallowed field patterns
* @see #setAllowedFields
* @see #isAllowed(String)
* @deprecated as of 7.1, in favor of {@link #setAllowedFields}.
*/
@Deprecated(since = "7.1", forRemoval = true)
public void setDisallowedFields(String @Nullable ... disallowedFields) {
if (disallowedFields == null) {
this.disallowedFields = null;
Expand All @@ -569,7 +570,9 @@ public void setDisallowedFields(String @Nullable ... disallowedFields) {
* Return the field patterns that should <i>not</i> be allowed for binding.
* @return array of disallowed field patterns
* @see #setDisallowedFields(String...)
* @deprecated as of 7.1, in favor of {@link #getAllowedFields()}.
*/
@Deprecated(since = "7.1", forRemoval = true)
public String @Nullable [] getDisallowedFields() {
return this.disallowedFields;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -715,6 +715,7 @@ void bindingWithAllowedFields() throws BindException {
}

@Test
@SuppressWarnings("removal")
void bindingWithDisallowedFields() throws BindException {
TestBean rod = new TestBean();
DataBinder binder = new DataBinder(rod);
Expand All @@ -734,6 +735,7 @@ void bindingWithDisallowedFields() throws BindException {
}

@Test
@SuppressWarnings("removal")
void bindingWithAllowedAndDisallowedFields() throws BindException {
TestBean rod = new TestBean();
DataBinder binder = new DataBinder(rod);
Expand All @@ -752,6 +754,7 @@ void bindingWithAllowedAndDisallowedFields() throws BindException {
}

@Test
@SuppressWarnings("removal")
void bindingWithOverlappingAllowedAndDisallowedFields() throws BindException {
TestBean rod = new TestBean();
DataBinder binder = new DataBinder(rod);
Expand Down Expand Up @@ -797,6 +800,7 @@ void bindingWithAllowedFieldsUsingAsterisks() throws BindException {
}

@Test
@SuppressWarnings("removal")
void bindingWithAllowedAndDisallowedMapFields() throws BindException {
TestBean rod = new TestBean();
DataBinder binder = new DataBinder(rod);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,7 @@ void shouldNotTriggerBindingWhenFieldIsNotAllowed() {
}

@Test
@SuppressWarnings("removal")
void shouldNotTriggerBindingWhenFieldIsDisallowed() {
TestBean tb = new TestBean();

Expand Down Expand Up @@ -363,6 +364,7 @@ void shouldNotTriggerBindingWhenFieldIsNotAllowedWithEmptyArrayIndex() {

@ParameterizedTest
@ValueSource(strings = { "stringArray*", "stringArray[]" })
@SuppressWarnings("removal")
void shouldNotTriggerBindingWhenFieldIsDisallowedWithEmptyArrayIndex(String disallowedField) {
TestBean tb = new TestBean();

Expand Down Expand Up @@ -398,6 +400,7 @@ void shouldNotTriggerAutoGrowWhenFieldIsNotAllowed() {

@ParameterizedTest
@ValueSource(strings = { "someMap*", "someMap[*]", "someMap[key1]" })
@SuppressWarnings("removal")
void shouldNotTriggerAutoGrowWhenFieldIsDisallowed(String disallowedField) {
TestBean tb = new TestBean();
tb.setSomeMap(null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class InitBinderDataBinderFactoryTests {


@Test
@SuppressWarnings("removal")
void createBinder() throws Exception {
WebDataBinderFactory factory = createFactory("initBinder", WebDataBinder.class);
WebDataBinder dataBinder = factory.createBinder(this.webRequest, null, null);
Expand All @@ -76,6 +77,7 @@ void createBinderWithGlobalInitialization() throws Exception {
}

@Test
@SuppressWarnings("removal")
void createBinderWithAttrName() throws Exception {
WebDataBinderFactory factory = createFactory("initBinderWithAttributeName", WebDataBinder.class);
WebDataBinder dataBinder = factory.createBinder(this.webRequest, null, "foo");
Expand All @@ -85,6 +87,7 @@ void createBinderWithAttrName() throws Exception {
}

@Test
@SuppressWarnings("removal")
void createBinderWithAttrNameNoMatch() throws Exception {
WebDataBinderFactory factory = createFactory("initBinderWithAttributeName", WebDataBinder.class);
WebDataBinder dataBinder = factory.createBinder(this.webRequest, null, "invalidName");
Expand All @@ -93,6 +96,7 @@ void createBinderWithAttrNameNoMatch() throws Exception {
}

@Test
@SuppressWarnings("removal")
void createBinderNullAttrName() throws Exception {
WebDataBinderFactory factory = createFactory("initBinderWithAttributeName", WebDataBinder.class);
WebDataBinder dataBinder = factory.createBinder(this.webRequest, null, null);
Expand All @@ -108,6 +112,7 @@ void returnValueNotExpected() throws Exception {
}

@Test
@SuppressWarnings("removal")
void createBinderTypeConversion() throws Exception {
this.webRequest.getNativeRequest(MockHttpServletRequest.class).setParameter("requestParam", "22");
this.argumentResolvers.addResolver(new RequestParamMethodArgumentResolver(null, false));
Expand Down Expand Up @@ -138,11 +143,13 @@ private WebDataBinderFactory createFactory(String methodName, Class<?>... parame
private static class InitBinderHandler {

@InitBinder
@SuppressWarnings("removal")
public void initBinder(WebDataBinder dataBinder) {
dataBinder.setDisallowedFields("id");
}

@InitBinder(value="foo")
@SuppressWarnings("removal")
public void initBinderWithAttributeName(WebDataBinder dataBinder) {
dataBinder.setDisallowedFields("id");
}
Expand All @@ -153,6 +160,7 @@ public String initBinderReturnValue(WebDataBinder dataBinder) {
}

@InitBinder
@SuppressWarnings("removal")
public void initBinderTypeConversion(WebDataBinder dataBinder, @RequestParam int requestParam) {
dataBinder.setDisallowedFields("requestParam-" + requestParam);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ class InitBinderBindingContextTests {


@Test
@SuppressWarnings("removal")
void createBinder() throws Exception {
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/"));
BindingContext context = createBindingContext("initBinder", WebDataBinder.class);
Expand All @@ -84,6 +85,7 @@ void createBinderWithGlobalInitialization() throws Exception {
}

@Test
@SuppressWarnings("removal")
void createBinderWithAttrName() throws Exception {
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/"));
BindingContext context = createBindingContext("initBinderWithAttributeName", WebDataBinder.class);
Expand All @@ -94,6 +96,7 @@ void createBinderWithAttrName() throws Exception {
}

@Test
@SuppressWarnings("removal")
void createBinderWithAttrNameNoMatch() throws Exception {
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/"));
BindingContext context = createBindingContext("initBinderWithAttributeName", WebDataBinder.class);
Expand All @@ -103,6 +106,7 @@ void createBinderWithAttrNameNoMatch() throws Exception {
}

@Test
@SuppressWarnings("removal")
void createBinderNullAttrName() throws Exception {
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/"));
BindingContext context = createBindingContext("initBinderWithAttributeName", WebDataBinder.class);
Expand All @@ -119,6 +123,7 @@ void returnValueNotExpected() throws Exception {
}

@Test
@SuppressWarnings("removal")
void createBinderTypeConversion() throws Exception {
MockServerHttpRequest request = MockServerHttpRequest.get("/path?requestParam=22").build();
MockServerWebExchange exchange = MockServerWebExchange.from(request);
Expand Down Expand Up @@ -260,11 +265,13 @@ private BindingContext createBindingContext(String methodName, Class<?>... param
private static class InitBinderHandler {

@InitBinder
@SuppressWarnings("removal")
public void initBinder(WebDataBinder dataBinder) {
dataBinder.setDisallowedFields("id");
}

@InitBinder(value="foo")
@SuppressWarnings("removal")
public void initBinderWithAttributeName(WebDataBinder dataBinder) {
dataBinder.setDisallowedFields("id");
}
Expand All @@ -275,6 +282,7 @@ public String initBinderReturnValue(WebDataBinder dataBinder) {
}

@InitBinder
@SuppressWarnings("removal")
public void initBinderTypeConversion(WebDataBinder dataBinder, @RequestParam int requestParam) {
dataBinder.setDisallowedFields("requestParam-" + requestParam);
}
Expand Down