diff --git a/api/all/src/jmh/java/io/opentelemetry/api/trace/SpanIdBenchmark.java b/api/all/src/jmh/java/io/opentelemetry/api/trace/SpanIdBenchmark.java index 975cb0c157..47dd55b2bd 100644 --- a/api/all/src/jmh/java/io/opentelemetry/api/trace/SpanIdBenchmark.java +++ b/api/all/src/jmh/java/io/opentelemetry/api/trace/SpanIdBenchmark.java @@ -22,7 +22,7 @@ import org.openjdk.jmh.annotations.Warmup; @Warmup(iterations = 5, time = 1) @Measurement(iterations = 15, time = 1) @OutputTimeUnit(TimeUnit.NANOSECONDS) -@Fork(1) +@Fork(3) @Threads(1) public class SpanIdBenchmark { diff --git a/api/all/src/main/java/io/opentelemetry/api/internal/OtelEncodingUtils.java b/api/all/src/main/java/io/opentelemetry/api/internal/OtelEncodingUtils.java index e4203d5228..3014ec28f9 100644 --- a/api/all/src/main/java/io/opentelemetry/api/internal/OtelEncodingUtils.java +++ b/api/all/src/main/java/io/opentelemetry/api/internal/OtelEncodingUtils.java @@ -14,7 +14,7 @@ public final class OtelEncodingUtils { static final int BYTE_BASE16 = 2; static final int LONG_BASE16 = BYTE_BASE16 * LONG_BYTES; private static final String ALPHABET = "0123456789abcdef"; - private static final int ASCII_CHARACTERS = 128; + private static final int NUM_ASCII_CHARACTERS = 128; private static final char[] ENCODING = buildEncodingArray(); private static final byte[] DECODING = buildDecodingArray(); @@ -28,7 +28,7 @@ public final class OtelEncodingUtils { } private static byte[] buildDecodingArray() { - byte[] decoding = new byte[ASCII_CHARACTERS]; + byte[] decoding = new byte[NUM_ASCII_CHARACTERS]; Arrays.fill(decoding, (byte) -1); for (int i = 0; i < ALPHABET.length(); i++) { char c = ALPHABET.charAt(i); @@ -110,10 +110,12 @@ public final class OtelEncodingUtils { * @return the resulting {@code byte} */ public static byte byteFromBase16(char first, char second) { - Utils.checkArgument( - first < ASCII_CHARACTERS && DECODING[first] != -1, () -> "invalid character " + first); - Utils.checkArgument( - second < ASCII_CHARACTERS && DECODING[second] != -1, () -> "invalid character " + second); + if (first >= NUM_ASCII_CHARACTERS || DECODING[first] == -1) { + throw new IllegalArgumentException("invalid character " + first); + } + if (second >= NUM_ASCII_CHARACTERS || DECODING[second] == -1) { + throw new IllegalArgumentException("invalid character " + second); + } int decoded = DECODING[first] << 4 | DECODING[second]; return (byte) decoded; } diff --git a/api/all/src/main/java/io/opentelemetry/api/internal/Utils.java b/api/all/src/main/java/io/opentelemetry/api/internal/Utils.java index 5fda975b43..2f6603e0da 100644 --- a/api/all/src/main/java/io/opentelemetry/api/internal/Utils.java +++ b/api/all/src/main/java/io/opentelemetry/api/internal/Utils.java @@ -5,7 +5,6 @@ package io.opentelemetry.api.internal; -import java.util.function.Supplier; import javax.annotation.concurrent.Immutable; /** General internal utility methods. */ @@ -26,17 +25,4 @@ public final class Utils { throw new IllegalArgumentException(errorMessage); } } - - /** - * Throws an {@link IllegalArgumentException} if the argument is false. This method is similar to - * {@code Preconditions.checkArgument(boolean, Object)} from Guava. - * - * @param isValid whether the argument check passed. - * @param errorMessage the supplier of the message to use for the exception. - */ - public static void checkArgument(boolean isValid, Supplier errorMessage) { - if (!isValid) { - throw new IllegalArgumentException(errorMessage.get()); - } - } }