apache/skywalking · error · IllegalArgumentException
The length of buckets and values should be same.
Error message
The length of buckets and values should be same.
What it means
BucketedValues pairs every bucket boundary with exactly one value (values[i] is the amount in buckets[i]); all iteration in histogram functions indexes both arrays in lockstep. The constructor therefore rejects arrays of different lengths with 'The length of buckets and values should be same.'
Source
Thrown at oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/analysis/meter/function/BucketedValues.java:62
* The {@link Long#MIN_VALUE} could be the first bucket element to indicate there is no minimal value.
*/
private long[] buckets;
/**
* {@link #buckets} and {@link #values} arrays should have the same length. The element in the values, represents
* the amount in the same index bucket.
*/
private long[] values;
/**
* @param buckets Read {@link #buckets}
* @param values Read {@link #values}
*/
public BucketedValues(final long[] buckets, final long[] values) {
if (buckets == null || values == null || buckets.length == 0 || values.length == 0) {
throw new IllegalArgumentException("buckets and values can't be null.");
}
if (buckets.length != values.length) {
throw new IllegalArgumentException("The length of buckets and values should be same.");
}
this.buckets = buckets;
this.values = values;
}
/**
* @return true if the bucket is same.
*/
public boolean isCompatible(DataTable dataset) {
final List<String> sortedKeys = dataset.sortedKeys(new HeatMap.KeyComparator(true));
long[] existedBuckets = new long[sortedKeys.size()];
for (int i = 0; i < sortedKeys.size(); i++) {
String key = sortedKeys.get(i);
if (key.equals(Bucket.INFINITE_NEGATIVE)) {
existedBuckets[i] = Long.MIN_VALUE;
} else {
// remove the label name
if (key.contains(":")) {View on GitHub (pinned to 102af09b4a)
Solutions
- Make the producer derive both arrays from one source: values.length must equal buckets.length — typically buckets has one entry per bucket including the implicit infinity buckets
- When bucket config changes, regenerate/redeploy the emitting side so it sends values matching the new bucket count
- Add a boundary check in the sender (length equality) so the failure surfaces at the source, not in OAP
Example fix
// before
long[] buckets = {0, 10, 50, 100}; // 4 boundaries
long[] values = {12, 8, 3}; // 3 values -> throws
// after
long[] buckets = {0, 10, 50, 100};
long[] values = new long[buckets.length]; // always sized from buckets
// fill values[i] by bucketing each observation Defensive patterns
Strategy: validation
Validate before calling
if (buckets.length != values.length) {
throw new IllegalStateException("buckets=" + buckets.length + " values=" + values.length
+ " — bucket/value length mismatch at source for " + metricName);
} Type guard
boolean sameLength(long[] a, long[] b) { return a != null && b != null && a.length == b.length; } Prevention
- Size the values array from the buckets array (values = new long[buckets.length]) rather than counting observations
- Re-run producer tests after any change to bucket templates so length contracts stay locked
- Log both lengths whenever a mismatch is detected at the producer to catch off-by-one bucket boundaries early
When it happens
Trigger: A producer builds the bucket array from an explicit bucket list but the values array from observed counts, and a missing/extra bucket skews them; a MAL valueBuckets declaration with N boundaries is paired with N-1 or N+1 values; serialization/deserialization truncates one array.
Common situations: Off-by-one bugs computing buckets (boundary count vs bucket count); changing the buckets config in a MAL rule without regenerating the emitted values; custom agents packing histograms where the infinite-negative/positive sentinel buckets are mishandled.
Related errors
- buckets and values can't be null.
- Incompatible BucketedValues [{}] for current HistogramFuncti
- Illegal rank value {rank}, must be positive
- decorate() not supported for histogram metrics
- YAML parsed to null — empty or malformed rule file: {sourceN
AI-assisted analysis of apache/skywalking@102af09b4a (2026-08-14).
Data as JSON: /api/errors/4e98c165321462bb.
Report an issue: GitHub.