From ad6ba4046afa7aa6415392cb0f3234c3bdc59f4c Mon Sep 17 00:00:00 2001 From: Yury Yarashevich Date: Thu, 12 Sep 2024 15:16:46 +0200 Subject: [PATCH] Remove usage of java assert. --- .../java/io/micrometer/core/instrument/Tags.java | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/micrometer-core/src/main/java/io/micrometer/core/instrument/Tags.java b/micrometer-core/src/main/java/io/micrometer/core/instrument/Tags.java index 868c6377f0..c789346b28 100644 --- a/micrometer-core/src/main/java/io/micrometer/core/instrument/Tags.java +++ b/micrometer-core/src/main/java/io/micrometer/core/instrument/Tags.java @@ -54,17 +54,25 @@ public final class Tags implements Iterable { * @param length the number of valid tags in the {@code sortedSet} */ private Tags(Tag[] sortedSet, int length) { - assert isSortedSet(sortedSet, length) : "bug on caller side: construction invariant violated"; this.sortedSet = sortedSet; this.length = length; } - private static boolean isSortedSet(Tag[] sortedSet, int length) { - if (length > sortedSet.length) { + /** + * Checks if the first {@code length} elements of the {@code tags} array + * form an ordered set of tags. + * + * @param tags an array of tags. + * @param length the number of items to check. + * @return {@code true} if the first {@code length} items of {@code tags} + * form an ordered set; otherwise {@code false}. + */ + private static boolean isSortedSet(Tag[] tags, int length) { + if (length > tags.length) { return false; } for (int i = 0; i < length - 1; i++) { - int cmp = sortedSet[i].compareTo(sortedSet[i + 1]); + int cmp = tags[i].compareTo(tags[i + 1]); if (cmp >= 0) { return false; }