{"record":{"id":"779e5d223bb6111a","repo":"OpenFeign/feign","slug":"no-more-elements","errorCode":null,"errorMessage":"No More Elements","messagePattern":"No More Elements","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/feign/template/Template.java","lineNumber":328,"sourceCode":"            outside = true;\n          }\n        }\n      }\n      if (lastIndex < idx) {\n        /* grab the remaining chunk */\n        tokens.add(template.substring(lastIndex, idx));\n      }\n    }\n\n    public boolean hasNext() {\n      return this.tokens.size() > this.index;\n    }\n\n    public String next() {\n      if (hasNext()) {\n        return this.tokens.get(this.index++);\n      }\n      throw new IllegalStateException(\"No More Elements\");\n    }\n  }\n\n  public enum EncodingOptions {\n    REQUIRED(true),\n    NOT_REQUIRED(false);\n\n    private final boolean shouldEncode;\n\n    EncodingOptions(boolean shouldEncode) {\n      this.shouldEncode = shouldEncode;\n    }\n\n    public boolean isEncodingRequired() {\n      return this.shouldEncode;\n    }\n  }\n","sourceCodeStart":310,"sourceCodeEnd":346,"githubUrl":"https://github.com/OpenFeign/feign/blob/e2a1e27560a1e68840c34f031afca88b36096e30/core/src/main/java/feign/template/Template.java#L310-L346","documentation":"The TokenIterator's next() throws IllegalStateException(\"No More Elements\") when called after the token list is exhausted. Callers must check hasNext() before calling next(), per the Iterator contract this class mimics.","triggerScenarios":"Calling next() on the internal template token iterator more times than there are tokens, i.e. without a guarding hasNext() check.","commonSituations":"Custom code iterating Template internals; bugs in chunk()/iteration logic that miscount tokens.","solutions":["Guard every next() call with hasNext()","Verify loop bounds when iterating template tokens manually","Use the public Template API (expand) instead of iterating internal token iterators"],"exampleFix":"// before\nString token = iterator.next();\n// after\nString token = iterator.hasNext() ? iterator.next() : null;","handlingStrategy":"type-guard","validationCode":"if (iterator.hasNext()) { token = iterator.next(); }","typeGuard":"String safeNext(Iterator<String> it) { return it.hasNext() ? it.next() : null; }","tryCatchPattern":"try {\n  token = iterator.next();\n} catch (IllegalStateException e) {\n  // iterator exhausted; handle end of tokens\n}","preventionTips":["Always pair next() with hasNext()","Prefer for-each loops over manual iterator calls"],"tags":["iterator","illegal-state","uri-template"],"backgroundTag":"iterator-exhausted","analyzedSha":"e2a1e27560a1e68840c34f031afca88b36096e30","analyzedAt":"2026-09-10T12:37:37.238Z","contentChangedAt":"2026-09-10T12:37:37.238Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}