Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/main/java/org/apache/commons/lang3/BooleanUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ public class BooleanUtils {
* @throws IllegalArgumentException if {@code array} is empty.
* @since 3.0.1
*/
public static boolean and(final boolean... array) {

public static boolean and(boolean[] array) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should keep this as final.
We will not be allowed to modify the reference and work with another array by mistake.
Otherwise we will be busy debugging why our changes are not persisted/reflected after the method call.

ObjectUtils.requireNonEmpty(array, "array");
for (final boolean element : array) {
if (!element) {
Expand Down
10 changes: 10 additions & 0 deletions src/test/java/org/apache/commons/lang3/BooleanUtilsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,16 @@ void testAnd_object_emptyInput() {
assertIllegalArgumentException(() -> BooleanUtils.and(new Boolean[] {}));
}

@Test
void testAnd_object_varargs_wrapper() {
assertEquals(false, BooleanUtils.and(Boolean.FALSE, Boolean.TRUE));
}

@Test
void testAnd_object_varargs_primitive() {
assertEquals(false, BooleanUtils.and(false, true));
}

@Test
void testAnd_object_nullElementInput() {
assertEquals(Boolean.FALSE, BooleanUtils.and(new Boolean[] {null}));
Expand Down