You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by GitBox <gi...@apache.org> on 2022/09/21 11:36:36 UTC

[GitHub] [commons-lang] stawirej commented on a diff in pull request #953: Handle error messages with special characters.

stawirej commented on code in PR #953:
URL: https://github.com/apache/commons-lang/pull/953#discussion_r976395832


##########
src/main/java/org/apache/commons/lang3/Validate.java:
##########
@@ -156,6 +156,30 @@ public static void isTrue(final boolean expression, final String message, final
         }
     }
 
+    /**
+     * Validate that the argument condition is {@code true}; otherwise
+     * throwing an exception. This method is useful when validating according
+     * to an arbitrary boolean expression, such as validating a
+     * primitive number or using your own custom validation expression.
+     *
+     * <pre>
+     * Validate.isTrue(i &gt; 0, "The value must be greater than 0");
+     * Validate.isTrue(myObject.isOk(), "The object is not okay");</pre>
+     *
+     * <p>The exception message will be converted to a string using String.valueOf(Object).</p>
+     *
+     * @param expression  the boolean expression to check
+     * @throws IllegalArgumentException if expression is {@code false}
+     * @see #isTrue(boolean, String, long)
+     * @see #isTrue(boolean, String, double)
+     * @see #isTrue(boolean, String, Object...)
+     */
+    public static void isTrue(final boolean expression, final String message) {
+        if (!expression) {
+            throw new IllegalArgumentException(String.valueOf(message));

Review Comment:
   Done.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org