Move the try/catch just around the 'validator.validate()' call. Otherwise the construction of the error message will fail with NPE because 'validator' my be null
Project: http://git-wip-us.apache.org/repos/asf/wicket/repo Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/59b3e318 Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/59b3e318 Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/59b3e318 Branch: refs/heads/master Commit: 59b3e318762733adea00cfe3b31c5dd25e4d2147 Parents: 9575f0d Author: Martin Tzvetanov Grigorov <[email protected]> Authored: Thu Mar 6 10:07:21 2014 +0200 Committer: Martin Tzvetanov Grigorov <[email protected]> Committed: Thu Mar 6 10:07:21 2014 +0200 ---------------------------------------------------------------------- .../wicket/markup/html/form/FormComponent.java | 42 ++++++++++---------- 1 file changed, 21 insertions(+), 21 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/wicket/blob/59b3e318/wicket-core/src/main/java/org/apache/wicket/markup/html/form/FormComponent.java ---------------------------------------------------------------------- diff --git a/wicket-core/src/main/java/org/apache/wicket/markup/html/form/FormComponent.java b/wicket-core/src/main/java/org/apache/wicket/markup/html/form/FormComponent.java index 2b2ae49..660cf53 100644 --- a/wicket-core/src/main/java/org/apache/wicket/markup/html/form/FormComponent.java +++ b/wicket-core/src/main/java/org/apache/wicket/markup/html/form/FormComponent.java @@ -1503,38 +1503,38 @@ public abstract class FormComponent<T> extends LabeledWebMarkupContainer impleme IValidator<T> validator = null; - try + for (Behavior behavior : getBehaviors()) { - for (Behavior behavior : getBehaviors()) + validator = null; + if (behavior instanceof ValidatorAdapter) { - validator = null; - if (behavior instanceof ValidatorAdapter) - { - validator = ((ValidatorAdapter<T>)behavior).getValidator(); - } - else if (behavior instanceof IValidator) - { - validator = (IValidator<T>)behavior; - } - if (validator != null) + validator = ((ValidatorAdapter<T>)behavior).getValidator(); + } + else if (behavior instanceof IValidator) + { + validator = (IValidator<T>)behavior; + } + if (validator != null) + { + if (isNull == false || validator instanceof INullAcceptingValidator<?>) { - if (isNull == false || validator instanceof INullAcceptingValidator<?>) + try { validator.validate(validatable); } - if (!isValid()) + catch (Exception e) { - break; + throw new WicketRuntimeException("Exception '" + e.getMessage() + + "' occurred during validation " + validator.getClass().getName() + + " on component " + getPath(), e); } } + if (!isValid()) + { + break; + } } } - catch (Exception e) - { - throw new WicketRuntimeException("Exception '" + e.getMessage() + - "' occurred during validation " + validator.getClass().getName() + - " on component " + getPath(), e); - } } /**
