Gary Gregory
2014-09-15 10:50:04 UTC
I don't about this... I feel we need to discuss this before we reinvent the bean validation JSR wheel and Hibernate Validator or some other implementation. Why are we forcing users to learn another framework instead of using a standard? This is almost -1 territory... I feel we need to clean up the builder pattern mess before we make another decision on plugins...
Gary
<div>-------- Original message --------</div><div>From: ***@apache.org </div><div>Date:09/14/2014 23:34 (GMT-05:00) </div><div>To: ***@logging.apache.org </div><div>Subject: [2/8] git commit: Add validation message to @RequiresNonNull. </div><div>
</div>Add validation message to @RequiresNonNull.
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/20e739a5
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/20e739a5
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/20e739a5
Branch: refs/heads/master
Commit: 20e739a5308023e4f5b03a49ea12f473193dcbea
Parents: 84e7fed
Author: Matt Sicker <***@apache.org>
Authored: Sun Sep 14 20:26:48 2014 -0500
Committer: Matt Sicker <***@apache.org>
Committed: Sun Sep 14 20:26:48 2014 -0500
----------------------------------------------------------------------
.../validation/constraints/RequiresNonNull.java | 5 +++++
.../validators/RequiresNonNullValidator.java | 14 +++++++++++++-
2 files changed, 18 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/20e739a5/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/validation/constraints/RequiresNonNull.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/validation/constraints/RequiresNonNull.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/validation/constraints/RequiresNonNull.java
index b3ef11d..7eb83e2 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/validation/constraints/RequiresNonNull.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/validation/constraints/RequiresNonNull.java
@@ -36,4 +36,9 @@ import org.apache.logging.log4j.core.config.plugins.validation.validators.Requir
@Target({ElementType.FIELD, ElementType.PARAMETER})
@Constraint(RequiresNonNullValidator.class)
public @interface RequiresNonNull {
+
+ /**
+ * The message to be logged if this constraint is violated. This should normally be overridden.
+ */
+ String message() default "The parameter is null";
}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/20e739a5/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/validation/validators/RequiresNonNullValidator.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/validation/validators/RequiresNonNullValidator.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/validation/validators/RequiresNonNullValidator.java
index 49c5806..9a39d4d 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/validation/validators/RequiresNonNullValidator.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/validation/validators/RequiresNonNullValidator.java
@@ -16,8 +16,10 @@
*/
package org.apache.logging.log4j.core.config.plugins.validation.validators;
+import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.core.config.plugins.validation.ConstraintValidator;
import org.apache.logging.log4j.core.config.plugins.validation.constraints.RequiresNonNull;
+import org.apache.logging.log4j.status.StatusLogger;
/**
* Validator implementation for {@link RequiresNonNull}.
@@ -25,12 +27,22 @@ import org.apache.logging.log4j.core.config.plugins.validation.constraints.Requi
* @since 2.1
*/
public class RequiresNonNullValidator implements ConstraintValidator<RequiresNonNull, Object> {
+
+ private static final Logger LOGGER = StatusLogger.getLogger();
+
+ private RequiresNonNull annotation;
+
@Override
public void initialize(final RequiresNonNull annotation) {
+ this.annotation = annotation;
}
@Override
public boolean isValid(final Object value) {
- return value != null;
+ if (value != null) {
+ return true;
+ }
+ LOGGER.error(annotation.message());
+ return false;
}
}
Gary
<div>-------- Original message --------</div><div>From: ***@apache.org </div><div>Date:09/14/2014 23:34 (GMT-05:00) </div><div>To: ***@logging.apache.org </div><div>Subject: [2/8] git commit: Add validation message to @RequiresNonNull. </div><div>
</div>Add validation message to @RequiresNonNull.
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/20e739a5
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/20e739a5
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/20e739a5
Branch: refs/heads/master
Commit: 20e739a5308023e4f5b03a49ea12f473193dcbea
Parents: 84e7fed
Author: Matt Sicker <***@apache.org>
Authored: Sun Sep 14 20:26:48 2014 -0500
Committer: Matt Sicker <***@apache.org>
Committed: Sun Sep 14 20:26:48 2014 -0500
----------------------------------------------------------------------
.../validation/constraints/RequiresNonNull.java | 5 +++++
.../validators/RequiresNonNullValidator.java | 14 +++++++++++++-
2 files changed, 18 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/20e739a5/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/validation/constraints/RequiresNonNull.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/validation/constraints/RequiresNonNull.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/validation/constraints/RequiresNonNull.java
index b3ef11d..7eb83e2 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/validation/constraints/RequiresNonNull.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/validation/constraints/RequiresNonNull.java
@@ -36,4 +36,9 @@ import org.apache.logging.log4j.core.config.plugins.validation.validators.Requir
@Target({ElementType.FIELD, ElementType.PARAMETER})
@Constraint(RequiresNonNullValidator.class)
public @interface RequiresNonNull {
+
+ /**
+ * The message to be logged if this constraint is violated. This should normally be overridden.
+ */
+ String message() default "The parameter is null";
}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/20e739a5/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/validation/validators/RequiresNonNullValidator.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/validation/validators/RequiresNonNullValidator.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/validation/validators/RequiresNonNullValidator.java
index 49c5806..9a39d4d 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/validation/validators/RequiresNonNullValidator.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/validation/validators/RequiresNonNullValidator.java
@@ -16,8 +16,10 @@
*/
package org.apache.logging.log4j.core.config.plugins.validation.validators;
+import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.core.config.plugins.validation.ConstraintValidator;
import org.apache.logging.log4j.core.config.plugins.validation.constraints.RequiresNonNull;
+import org.apache.logging.log4j.status.StatusLogger;
/**
* Validator implementation for {@link RequiresNonNull}.
@@ -25,12 +27,22 @@ import org.apache.logging.log4j.core.config.plugins.validation.constraints.Requi
* @since 2.1
*/
public class RequiresNonNullValidator implements ConstraintValidator<RequiresNonNull, Object> {
+
+ private static final Logger LOGGER = StatusLogger.getLogger();
+
+ private RequiresNonNull annotation;
+
@Override
public void initialize(final RequiresNonNull annotation) {
+ this.annotation = annotation;
}
@Override
public boolean isValid(final Object value) {
- return value != null;
+ if (value != null) {
+ return true;
+ }
+ LOGGER.error(annotation.message());
+ return false;
}
}