{"record":{"id":"19ac3a56545c3d67","repo":"pinpoint-apm/pinpoint","slug":"negative-maxwidth-maxwidth","errorCode":null,"errorMessage":"negative maxWidth:+maxWidth","messagePattern":"negative maxWidth:\\+maxWidth","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"commons/src/main/java/com/navercorp/pinpoint/common/util/StringUtils.java","lineNumber":154,"sourceCode":"        return str != null && str.startsWith(prefix);\n    }\n\n    public static boolean contains(String str, String prefix) {\n        return str != null && str.contains(prefix);\n    }\n\n\n    public static String abbreviate(final String str) {\n        return abbreviate(str, DEFAULT_ABBREVIATE_MAX_WIDTH);\n    }\n\n\n    public static String abbreviate(final String str, final int maxWidth) {\n        if (str == null) {\n            return NULL_STRING;\n        }\n        if (maxWidth < 0) {\n            throw new IllegalArgumentException(\"negative maxWidth:\" + maxWidth);\n        }\n        if (str.length() > maxWidth) {\n            final int endIndex = abbreviateEndIndex(str, maxWidth);\n            StringBuilder buffer = new StringBuilder(abbreviateBufferSize(endIndex, str.length()));\n            buffer.append(str, 0, endIndex);\n            appendAbbreviateMessage(buffer, str.length());\n            return buffer.toString();\n        } else {\n            return str;\n        }\n    }\n\n    /**\n     * An unpaired high surrogate left by cutting a surrogate pair in half\n     * is not encodable to UTF-8 (e.g. protobuf throws UnpairedSurrogateException),\n     * so drop the high surrogate instead of splitting the pair.\n     */\n    static int abbreviateEndIndex(final String str, final int maxWidth) {","sourceCodeStart":136,"sourceCodeEnd":172,"githubUrl":"https://github.com/pinpoint-apm/pinpoint/blob/744c3d3075e595656abb1ae331ad2c0e4c9eb996/commons/src/main/java/com/navercorp/pinpoint/common/util/StringUtils.java#L136-L172","documentation":"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.","triggerScenarios":"Calling abbreviate(str, maxWidth) with maxWidth < 0 — e.g. a negative computed display width or a subtracted length going negative.","commonSituations":"Computing available width as terminalWidth - someOffset where offset exceeded width; passing a config value that defaulted to -1 as 'unlimited'.","solutions":["Clamp width before calling: Math.max(0, maxWidth)","Fix the width computation to never go below zero","Use a sensible positive default when the computed width is invalid"],"exampleFix":"// before\nString s = StringUtils.abbreviate(str, maxWidth); // maxWidth = -3\n// after\nString s = StringUtils.abbreviate(str, Math.max(0, maxWidth));","handlingStrategy":"validation","validationCode":"if (maxWidth < 0) throw new IllegalArgumentException(\"maxWidth must be >= 0\");\nString s = StringUtils.abbreviate(str, maxWidth);","typeGuard":null,"tryCatchPattern":"try {\n    display = StringUtils.abbreviate(str, maxWidth);\n} catch (IllegalArgumentException e) {\n    logger.warn(\"abbreviate width invalid: {}\", e.getMessage());\n    display = str;\n}","preventionTips":["Clamp computed widths with Math.max(0, width)","Do not use -1 to mean unlimited — the method rejects it","Test display-width math for edge cases (width 0, offsets > width)"],"tags":["string","argument-check","pinpoint-commons"],"backgroundTag":"invalid-argument-value","analyzedSha":"744c3d3075e595656abb1ae331ad2c0e4c9eb996","analyzedAt":"2026-09-07T18:48:45.289Z","contentChangedAt":"2026-09-07T18:48:45.289Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}