• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

TAKETODAY / today-infrastructure / 18154768944

01 Oct 2025 07:26AM UTC coverage: 81.882% (-0.005%) from 81.887%
18154768944

push

github

web-flow
Merge pull request #290 from TAKETODAY/dev/jspecify

jspecify

59788 of 78013 branches covered (76.64%)

Branch coverage included in aggregate %.

141239 of 167496 relevant lines covered (84.32%)

3.6 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

78.95
today-context/src/main/java/infra/validation/DirectFieldBindingResult.java
1
/*
2
 * Copyright 2017 - 2025 the original author or authors.
3
 *
4
 * This program is free software: you can redistribute it and/or modify
5
 * it under the terms of the GNU General Public License as published by
6
 * the Free Software Foundation, either version 3 of the License, or
7
 * (at your option) any later version.
8
 *
9
 * This program is distributed in the hope that it will be useful,
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 * GNU General Public License for more details.
13
 *
14
 * You should have received a copy of the GNU General Public License
15
 * along with this program. If not, see [https://www.gnu.org/licenses/]
16
 */
17

18
package infra.validation;
19

20
import org.jspecify.annotations.Nullable;
21

22
import infra.beans.BeanWrapper;
23
import infra.beans.ConfigurablePropertyAccessor;
24

25
/**
26
 * Special implementation of the Errors and BindingResult interfaces,
27
 * supporting registration and evaluation of binding errors on value objects.
28
 * Performs direct field access instead of going through JavaBean getters.
29
 *
30
 * <p>this implementation is able to traverse nested fields.
31
 *
32
 * @author Juergen Hoeller
33
 * @author <a href="https://github.com/TAKETODAY">海子 Yang</a>
34
 * @see DataBinder#getBindingResult()
35
 * @see DataBinder#initDirectFieldAccess()
36
 * @see BeanPropertyBindingResult
37
 * @since 4.0
38
 */
39
@SuppressWarnings("serial")
40
public class DirectFieldBindingResult extends AbstractPropertyBindingResult {
41

42
  @Nullable
43
  private final Object target;
44

45
  private final boolean autoGrowNestedPaths;
46

47
  @Nullable
48
  private transient ConfigurablePropertyAccessor directFieldAccessor;
49

50
  /**
51
   * Create a new DirectFieldBindingResult instance.
52
   *
53
   * @param target the target object to bind onto
54
   * @param objectName the name of the target object
55
   */
56
  public DirectFieldBindingResult(@Nullable Object target, String objectName) {
57
    this(target, objectName, true);
×
58
  }
×
59

60
  /**
61
   * Create a new DirectFieldBindingResult instance.
62
   *
63
   * @param target the target object to bind onto
64
   * @param objectName the name of the target object
65
   * @param autoGrowNestedPaths whether to "auto-grow" a nested path that contains a null value
66
   */
67
  public DirectFieldBindingResult(@Nullable Object target, String objectName, boolean autoGrowNestedPaths) {
68
    super(objectName);
3✔
69
    this.target = target;
3✔
70
    this.autoGrowNestedPaths = autoGrowNestedPaths;
3✔
71
  }
1✔
72

73
  @Override
74
  @Nullable
75
  public final Object getTarget() {
76
    return this.target;
3✔
77
  }
78

79
  /**
80
   * Returns the DirectFieldAccessor that this instance uses.
81
   * Creates a new one if none existed before.
82
   *
83
   * @see #createDirectFieldAccessor()
84
   */
85
  @Override
86
  public final ConfigurablePropertyAccessor getPropertyAccessor() {
87
    if (this.directFieldAccessor == null) {
3✔
88
      this.directFieldAccessor = createDirectFieldAccessor();
4✔
89
      this.directFieldAccessor.setExtractOldValueForEditor(true);
4✔
90
      this.directFieldAccessor.setAutoGrowNestedPaths(this.autoGrowNestedPaths);
5✔
91
    }
92
    return this.directFieldAccessor;
3✔
93
  }
94

95
  /**
96
   * Create a new DirectFieldAccessor for the underlying target object.
97
   *
98
   * @see #getTarget()
99
   */
100
  protected ConfigurablePropertyAccessor createDirectFieldAccessor() {
101
    if (this.target == null) {
3!
102
      throw new IllegalStateException("Cannot access fields on null target instance '" + getObjectName() + "'");
×
103
    }
104
    return BeanWrapper.forDirectFieldAccess(this.target);
4✔
105
  }
106

107
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc