pinpoint-apm/pinpoint · error · IllegalArgumentException

negative maxWidth:+maxWidth

Error message

negative maxWidth:+maxWidth

What it means

StringUtils.abbreviate truncates a string to maxWidth, appending an abbreviation marker. A negative maxWidth is rejected with IllegalArgumentException since there is no meaningful negative truncation length. Null strings are handled gracefully, but the width must be >= 0.

Solutions

  1. Clamp width before calling: Math.max(0, maxWidth)
  2. Fix the width computation to never go below zero
  3. Use a sensible positive default when the computed width is invalid

Example fix

// before
String s = StringUtils.abbreviate(str, maxWidth); // maxWidth = -3
// after
String s = StringUtils.abbreviate(str, Math.max(0, maxWidth));
Defensive patterns

Strategy: validation

Validate before calling

if (maxWidth < 0) throw new IllegalArgumentException("maxWidth must be >= 0");
String s = StringUtils.abbreviate(str, maxWidth);

Try / catch

try {
    display = StringUtils.abbreviate(str, maxWidth);
} catch (IllegalArgumentException e) {
    logger.warn("abbreviate width invalid: {}", e.getMessage());
    display = str;
}

Prevention

When it happens

Trigger: Calling abbreviate(str, maxWidth) with maxWidth < 0 — e.g. a negative computed display width or a subtracted length going negative.

Common situations: Computing available width as terminalWidth - someOffset where offset exceeded width; passing a config value that defaulted to -1 as 'unlimited'.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


AI-assisted analysis of pinpoint-apm/pinpoint@744c3d3075 (2026-09-07). Data as JSON: /api/errors/19ac3a56545c3d67. Report an issue: GitHub.

Appendix: source

Thrown at commons/src/main/java/com/navercorp/pinpoint/common/util/StringUtils.java:154

        return str != null && str.startsWith(prefix);
    }

    public static boolean contains(String str, String prefix) {
        return str != null && str.contains(prefix);
    }


    public static String abbreviate(final String str) {
        return abbreviate(str, DEFAULT_ABBREVIATE_MAX_WIDTH);
    }


    public static String abbreviate(final String str, final int maxWidth) {
        if (str == null) {
            return NULL_STRING;
        }
        if (maxWidth < 0) {
            throw new IllegalArgumentException("negative maxWidth:" + maxWidth);
        }
        if (str.length() > maxWidth) {
            final int endIndex = abbreviateEndIndex(str, maxWidth);
            StringBuilder buffer = new StringBuilder(abbreviateBufferSize(endIndex, str.length()));
            buffer.append(str, 0, endIndex);
            appendAbbreviateMessage(buffer, str.length());
            return buffer.toString();
        } else {
            return str;
        }
    }

    /**
     * An unpaired high surrogate left by cutting a surrogate pair in half
     * is not encodable to UTF-8 (e.g. protobuf throws UnpairedSurrogateException),
     * so drop the high surrogate instead of splitting the pair.
     */
    static int abbreviateEndIndex(final String str, final int maxWidth) {

View on GitHub (pinned to 744c3d3075)