{"record":{"id":"da1e36742bce9038","repo":"google/gson","slug":"invalid-version-version","errorCode":null,"errorMessage":"Invalid version: ${version}","messagePattern":"Invalid version: (.+?)","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"gson/src/main/java/com/google/gson/GsonBuilder.java","lineNumber":207,"sourceCode":"  /**\n   * Configures Gson to enable versioning support. Versioning support works based on the annotation\n   * types {@link Since} and {@link Until}. It allows including or excluding fields and classes\n   * based on the specified version. See the documentation of these annotation types for more\n   * information.\n   *\n   * <p>By default versioning support is disabled and usage of {@code @Since} and {@code @Until} has\n   * no effect.\n   *\n   * @param version the version number to use.\n   * @return a reference to this {@code GsonBuilder} object to fulfill the \"Builder\" pattern\n   * @throws IllegalArgumentException if the version number is NaN or negative\n   * @see Since\n   * @see Until\n   */\n  @CanIgnoreReturnValue\n  public GsonBuilder setVersion(double version) {\n    if (Double.isNaN(version) || version < 0.0) {\n      throw new IllegalArgumentException(\"Invalid version: \" + version);\n    }\n    excluder = excluder.withVersion(version);\n    return this;\n  }\n\n  /**\n   * Configures Gson to excludes all class fields that have the specified modifiers. By default,\n   * Gson will exclude all fields marked {@code transient} or {@code static}. This method will\n   * override that behavior.\n   *\n   * <p>This is a convenience method which behaves as if an {@link ExclusionStrategy} which excludes\n   * these fields was {@linkplain #setExclusionStrategies(ExclusionStrategy...) registered with this\n   * builder}.\n   *\n   * @param modifiers the field modifiers. You must use the modifiers specified in the {@link\n   *     java.lang.reflect.Modifier} class. For example, {@link\n   *     java.lang.reflect.Modifier#TRANSIENT}, {@link java.lang.reflect.Modifier#STATIC}.\n   * @return a reference to this {@code GsonBuilder} object to fulfill the \"Builder\" pattern","sourceCodeStart":189,"sourceCodeEnd":225,"githubUrl":"https://github.com/google/gson/blob/310ac341f2f92a454b229bf21f70d2d18b2b6db7/gson/src/main/java/com/google/gson/GsonBuilder.java#L189-L225","documentation":"Thrown by GsonBuilder.setVersion(double) when the supplied version is NaN or negative. Versions drive field/class inclusion via @Since and @Until annotations, so a non-finite or negative number is meaningless and rejected with an IllegalArgumentException before being applied to the Excluder.","triggerScenarios":"Passing Double.NaN; a negative double (e.g. from a subtraction bug); computing the version from unparsed config that yields NaN; passing 0.0/0.0.","commonSituations":"Reading version from a properties file and parsing fails to NaN; arithmetic that can go negative; default/uninitialized double field passed through; test values like -1 to mean 'unset'.","solutions":["Pass a non-negative, finite double version (>= 0.0 and not NaN), e.g. setVersion(1.2).","Validate the value before calling: if (!Double.isNaN(v) && v >= 0.0) builder.setVersion(v).","Use 0.0 or omit setVersion to disable versioning rather than passing a sentinel.","Parse config with Double.parseDouble guarded by a try/catch to avoid NaN propagation."],"exampleFix":"// before\nbuilder.setVersion(parseDoubleOrNaN(config)); // NaN -> throws\n\n// after\ndouble v = parseDoubleOrNaN(config);\nif (!Double.isNaN(v) && v >= 0.0) builder.setVersion(v);","handlingStrategy":"validation","validationCode":"// Validate version before applying\nif (Double.isNaN(version) || version < 0.0) {\n  throw new IllegalArgumentException(\"version must be >= 0 and not NaN, got \" + version);\n}\nbuilder.setVersion(version);","typeGuard":null,"tryCatchPattern":"try { builder.setVersion(v); }\ncatch (IllegalArgumentException e) {\n  if (e.getMessage().startsWith(\"Invalid version\")) { /* default version or fail config */ }\n  else throw e;\n}","preventionTips":["Guard config parsing so NaN/negative never reach setVersion.","Use 0.0 or omit setVersion to disable versioning.","Unit-test the version config path."],"tags":["gson-builder","versioning","configuration","validation"],"backgroundTag":null,"analyzedSha":"310ac341f2f92a454b229bf21f70d2d18b2b6db7","analyzedAt":"2026-08-10T02:58:47.455Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}