• 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

82.35
today-context/src/main/java/infra/validation/BindingResultUtils.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 java.util.Map;
23

24
import infra.lang.Assert;
25

26
/**
27
 * Convenience methods for looking up BindingResults in a model Map.
28
 *
29
 * @author Juergen Hoeller
30
 * @see BindingResult#MODEL_KEY_PREFIX
31
 * @since 4.0
32
 */
33
public abstract class BindingResultUtils {
×
34

35
  /**
36
   * Find the BindingResult for the given name in the given model.
37
   *
38
   * @param model the model to search
39
   * @param name the name of the target object to find a BindingResult for
40
   * @return the BindingResult, or {@code null} if none found
41
   * @throws IllegalStateException if the attribute found is not of type BindingResult
42
   */
43
  @Nullable
44
  public static BindingResult getBindingResult(Map<?, ?> model, String name) {
45
    Assert.notNull(model, "Model map is required");
3✔
46
    Assert.notNull(name, "Name is required");
3✔
47
    Object attr = model.get(BindingResult.MODEL_KEY_PREFIX + name);
6✔
48
    if (attr != null && !(attr instanceof BindingResult)) {
5!
49
      throw new IllegalStateException("BindingResult attribute is not of type BindingResult: " + attr);
×
50
    }
51
    return (BindingResult) attr;
3✔
52
  }
53

54
  /**
55
   * Find a required BindingResult for the given name in the given model.
56
   *
57
   * @param model the model to search
58
   * @param name the name of the target object to find a BindingResult for
59
   * @return the BindingResult (never {@code null})
60
   * @throws IllegalStateException if no BindingResult found
61
   */
62
  public static BindingResult getRequiredBindingResult(Map<?, ?> model, String name) {
63
    BindingResult bindingResult = getBindingResult(model, name);
4✔
64
    if (bindingResult == null) {
2✔
65
      throw new IllegalStateException("No BindingResult attribute found for name '" + name +
6✔
66
              "'- have you exposed the correct model?");
67
    }
68
    return bindingResult;
2✔
69
  }
70

71
}
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