{"record":{"id":"0e78bb3b72be50e4","repo":"eclipse-vertx/vert.x","slug":"invalid-tag-index-index","errorCode":null,"errorMessage":"Invalid tag index ${index}","messagePattern":"Invalid tag index (.+?)","errorType":"exception","errorClass":"IndexOutOfBoundsException","httpStatus":null,"severity":"warning","filePath":"vertx-core/src/main/java/io/vertx/core/spi/tracing/TagExtractor.java","lineNumber":50,"sourceCode":"  /**\n   * Returns the number of tags {@code obj} exposes.\n   *\n   * @param obj the object to evaluate\n   * @return the number of tags\n   */\n  default int len(T obj) {\n    return 0;\n  }\n\n  /**\n   * Returns the name of the tag extracted from {@code obj}at the specified {@code index}.\n   *\n   * @param obj the object to extract the tag name from\n   * @param index the index of the tag\n   * @return the tag name\n   */\n  default String name(T obj, int index) {\n    throw new IndexOutOfBoundsException(\"Invalid tag index \" + index);\n  }\n\n  /**\n   * Returns the value of the tag extracted from {@code obj} at the specified {@code index}.\n   *\n   * @param obj the object to extract the tag name from\n   * @param index the index of the tag\n   * @return the tag value\n   */\n  default String value(T obj, int index) {\n    throw new IndexOutOfBoundsException(\"Invalid tag index \" + index);\n  }\n\n  /**\n   * Extract all the tags from {@code obj} into a {@code Map<String, String>}.\n   *\n   * @param obj the object to extract the tags from\n   * @return the map of all tags extracted from the object","sourceCodeStart":32,"sourceCodeEnd":68,"githubUrl":"https://github.com/eclipse-vertx/vert.x/blob/fb308bd8c3f12c79f4ae89bef67fadf6c80d036e/vertx-core/src/main/java/io/vertx/core/spi/tracing/TagExtractor.java#L32-L68","documentation":"TagExtractor.name(T,int) is a default interface method that throws IndexOutOfBoundsException when a tag name is requested at an index the extractor does not support. Concrete extractors override it to return tag names for valid indices; the default is a stub signaling out-of-range access. It is reached when iterating code (extractTo, addTags, addressOf) asks for more tags than the extractor provides.","triggerScenarios":"Calling name(obj, index) with an index >= the number of tags the extractor supports, typically from extractTo/addTags/addressOf when their loop bounds disagree with the overridden name()/size() implementation, or calling the default extractor directly with a non-zero index.","commonSituations":"Writing a custom TagExtractor that overrides size() but not name()/value() consistently; iteration logic using a wrong tag count; calling the base TagExtractor interface without an overriding implementation.","solutions":["Override name(T obj, int index) in your TagExtractor to return a valid tag name for every index in [0, size()) and keep it consistent with size().","Fix the caller's loop bound so it never asks for index >= size().","Use one of the provided TagExtractor factories (e.g. TagExtractor.empty() or fromMap-style helpers) instead of the bare default methods."],"exampleFix":"// before\nTagExtractor<Req> ex = new TagExtractor<>() { public int size(Req r){return 1;} };\nex.name(req, 0); // IndexOutOfBoundsException\n// after\nTagExtractor<Req> ex = new TagExtractor<>() {\n  public int size(Req r){return 1;}\n  public String name(Req r, int i){ return \"req.name\"; }\n};","handlingStrategy":"type-guard","validationCode":"for (int i = 0; i < extractor.size(obj); i++) { String n = extractor.name(obj, i); }","typeGuard":"String safeName(TagExtractor<T> ex, T obj, int i) { return (i >= 0 && i < ex.size(obj)) ? ex.name(obj, i) : null; }","tryCatchPattern":"try { return extractor.name(obj, index); } catch (IndexOutOfBoundsException e) { return null; }","preventionTips":["Always implement name(), value(), and size() together in custom TagExtractors","Derive loop bounds from extractor.size(obj), not hardcoded counts","Add a test iterating all indices of your extractor"],"tags":["tracing","tags","index-out-of-bounds"],"backgroundTag":"index-out-of-range","analyzedSha":"fb308bd8c3f12c79f4ae89bef67fadf6c80d036e","analyzedAt":"2026-09-06T11:37:12.241Z","contentChangedAt":"2026-09-06T11:37:12.241Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}