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 10:50:12 UTC

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

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


##########
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

Review Comment:
   There is no `@param` tag for `message`.



##########
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:
   `String.valueOf(String)` is not required. Note that String.valueOf(null) will return null and that is handled fine by the IllegalArgumentException constructor. So just pass through the String message argument (which can be null).
   



##########
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

Review Comment:
   `an exception with the specified message`
   
   Note: This change makes the code example on line 143 invalid. Please update the javadoc in the preceding method to remove:
   ```Validate.isTrue(myObject.isOk(), "The object is not okay");</pre>```
   



##########
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>

Review Comment:
   This is not required.



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