{"record":{"id":"414d1be5809548c0","repo":"ben-manes/caffeine","slug":"invalid-option","errorCode":null,"errorMessage":"Invalid option ","messagePattern":"Invalid option ","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"caffeine/src/main/java/com/github/benmanes/caffeine/cache/CaffeineSpec.java","lineNumber":204,"sourceCode":"        valueStrength(key, value, Strength.WEAK);\n        return;\n      case \"softValues\":\n        valueStrength(key, value, Strength.SOFT);\n        return;\n      case \"expireAfterAccess\":\n        expireAfterAccess(key, value);\n        return;\n      case \"expireAfterWrite\":\n        expireAfterWrite(key, value);\n        return;\n      case \"refreshAfterWrite\":\n        refreshAfterWrite(key, value);\n        return;\n      case \"recordStats\":\n        recordStats(value);\n        return;\n      default:\n        throw new IllegalArgumentException(\"Invalid option \" + option);\n    }\n  }\n\n  /** Configures the initial capacity. */\n  void initialCapacity(String key, @Nullable String value) {\n    requireArgument(initialCapacity == null,\n        \"initial capacity was already set to %,d\", initialCapacity);\n    initialCapacity = parseInt(key, value);\n  }\n\n  /** Configures the maximum size. */\n  void maximumSize(String key, @Nullable String value) {\n    requireArgument(maximumSize == null,\n        \"maximum size was already set to %,d\", maximumSize);\n    requireArgument(maximumWeight == null,\n        \"maximum weight was already set to %,d\", maximumWeight);\n    maximumSize = parseLong(key, value);\n  }","sourceCodeStart":186,"sourceCodeEnd":222,"githubUrl":"https://github.com/ben-manes/caffeine/blob/9da6581ee366aa63c51e0dc96692d02f9c29ccff/caffeine/src/main/java/com/github/benmanes/caffeine/cache/CaffeineSpec.java#L186-L222","documentation":"CaffeineSpec.parse dispatches each key=value pair of the spec string to a fixed set of options (initialCapacity, maximumSize, expireAfterAccess, etc.); any key that matches none of the switch cases throws IllegalArgumentException(\"Invalid option \" + option). It indicates a typo'd or unsupported option name in the CaffeineSpec configuration string.","triggerScenarios":"Calling Caffeine.from(spec) / CaffeineSpec.parse with a key not in the supported set, e.g. \"maximumWeightSize=100\", \"expireAfterRead=30s\", \"maximumsize=100\" (wrong case), or trailing separators producing an empty key.","commonSituations":"Migrating config from another cache library (Guava/Ehcache) and reusing old option names; typos in externally supplied spec strings (properties files, env vars); copy-pasting spec syntax from a newer/older Caffeine version with different option names.","solutions":["Check the exception message: it names the exact invalid option string","Correct the key against the supported set: initialCapacity, maximumSize, maximumWeight, expireAfterAccess, expireAfterWrite, refreshAfterWrite, recordStats, strength keys (weakKeys/weakValues/softValues), and expiry variants","If specs come from user input/config files, validate keys against CaffeineSpec.supportedOptions before calling parse"],"exampleFix":"// before\nCache<K, V> cache = Caffeine.from(\"maximumsize=100,expireAfterWrite=10m\")\n    .build(); // IllegalArgumentException: Invalid option maximumsize=100\n\n// after\nCache<K, V> cache = Caffeine.from(\"maximumSize=100,expireAfterWrite=10m\")\n    .build();","handlingStrategy":"validation","validationCode":"// Validate spec keys before parsing:\nSet<String> supported = Set.of(\"initialCapacity\", \"maximumSize\", \"maximumWeight\",\n    \"expireAfterAccess\", \"expireAfterWrite\", \"refreshAfterWrite\", \"recordStats\",\n    \"weakKeys\", \"weakValues\", \"softValues\", \"strongKeys\", \"strongValues\", \"expireAfterAccessCustom\", \"expireAfterWriteCustom\");\nfor (String entry : spec.split(\",\")) {\n  String key = entry.split(\"=\", 2)[0].strip();\n  if (!supported.contains(key)) {\n    throw new ConfigException(\"Unknown Caffeine option: \" + key);\n  }\n}\nCache<K, V> cache = Caffeine.from(spec).build();","typeGuard":null,"tryCatchPattern":"try {\n  return Caffeine.from(spec);\n} catch (IllegalArgumentException e) {\n  if (e.getMessage() != null && e.getMessage().startsWith(\"Invalid option\")) {\n    throw new ConfigurationException(\"Bad Caffeine spec option: \" + e.getMessage(), e);\n  }\n  throw e;\n}","preventionTips":["Define spec strings as constants or config classes instead of free-form user text","Validate specs at application startup so typos fail boot, not later","Copy option names verbatim from the Caffeine wiki/README when writing configs"],"tags":["caffeine","configuration","caffeine-spec","invalid-option","parse"],"backgroundTag":null,"analyzedSha":"9da6581ee366aa63c51e0dc96692d02f9c29ccff","analyzedAt":"2026-08-14T14:45:28.147Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}