File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -58,8 +58,6 @@ public class ESAPI {
5858 private static SecurityConfiguration securityConfiguration = null ;
5959
6060 private static Validator validator = null ;
61-
62- private static ValidatorErrorList validatorErrorList = null ;
6361
6462 /**
6563 * prevent instantiation of this class
@@ -270,13 +268,4 @@ public static Validator validator() {
270268 public static void setValidator (Validator validator ) {
271269 ESAPI .validator = validator ;
272270 }
273-
274- /**
275- * @return the validatorErrorList
276- */
277- public static ValidatorErrorList validatorErrorList () {
278- if (ESAPI .validatorErrorList == null )
279- ESAPI .validatorErrorList = new DefaultValidatorErrorList ();
280- return ESAPI .validatorErrorList ;
281- }
282271}
Original file line number Diff line number Diff line change 4646 * @since June 1, 2007
4747 */
4848public interface Validator {
49+
50+ /**
51+ * Returns the ThreadLocal instance of the ValidatorErrorList which can be called
52+ * anywhere in the application without needing to pass the list around.
53+ * @return
54+ */
55+ public ValidatorErrorList getValidatorErrorList ();
4956
5057 /**
5158 * Returns true if input is valid according to the specified type. The type parameter must be the name
Original file line number Diff line number Diff line change @@ -64,5 +64,10 @@ public interface ValidatorErrorList {
6464 * @param ve
6565 */
6666 public void addError (String context , ValidationException ve );
67+
68+ /**
69+ * Removes all errors from error list.
70+ */
71+ public void clearErrors ();
6772}
6873
Original file line number Diff line number Diff line change @@ -71,6 +71,30 @@ public class DefaultValidator implements org.owasp.esapi.Validator {
7171 private static final int MAX_CREDIT_CARD_LENGTH = 19 ;
7272 private static final int MAX_PARAMETER_NAME_LENGTH = 100 ;
7373 private static final int MAX_PARAMETER_VALUE_LENGTH = 65535 ; //max length of MySQL "text" column type
74+
75+ /** list of errors collection class */
76+ private ThreadLocalValidatorErrorList validatorErrorList = new ThreadLocalValidatorErrorList ();
77+
78+ private class ThreadLocalValidatorErrorList extends InheritableThreadLocal {
79+
80+ public ValidatorErrorList getValidatorErrorList () {
81+ if ((ValidatorErrorList )super .get () == null ) {
82+ super .set (new DefaultValidatorErrorList ());
83+ }
84+ return (ValidatorErrorList )super .get ();
85+ }
86+
87+ public void setValidatorErrorList (ValidatorErrorList validatorErrorList ) {
88+ super .set (validatorErrorList );
89+ }
90+ };
91+
92+ /**
93+ * @return the validatorErrorList
94+ */
95+ public ValidatorErrorList getValidatorErrorList () {
96+ return (ValidatorErrorList )validatorErrorList .get ();
97+ }
7498
7599 public DefaultValidator () {
76100 }
Original file line number Diff line number Diff line change @@ -93,4 +93,8 @@ public boolean isEmpty() {
9393 if ((errorList == null ) || (errorList .size () == 0 )) return true ;
9494 return false ;
9595 }
96+
97+ public void clearErrors () {
98+ errorList .clear ();
99+ }
96100}
You can’t perform that action at this time.
0 commit comments