{"record":{"id":"9bc724a41c3fe44c","repo":"google/guava","slug":"at-index-s","errorCode":null,"errorMessage":"at index %s","messagePattern":"at index (.+?)","errorType":"validation","errorClass":"NullPointerException","httpStatus":null,"severity":"error","filePath":"android/guava-testlib/src/com/google/common/testing/EqualsTester.java","lineNumber":117,"sourceCode":"   *\n   * <p>The {@code @Nullable} annotations on the {@code equalityGroup} parameter imply that the\n   * objects, and the array itself, can be null. That is for programmer convenience, when the\n   * objects come from factory methods that are themselves {@code @Nullable}. In reality neither the\n   * array nor its contents can be null, but it is not useful to force the use of {@code\n   * requireNonNull} or the like just to assert that.\n   *\n   * <p>{@code EqualsTester} will always check that every object it is given returns false from\n   * {@code equals(null)}, so it is neither useful nor allowed to include a null value in any\n   * equality group.\n   */\n  @CanIgnoreReturnValue\n  public EqualsTester addEqualityGroup(@Nullable Object @Nullable ... equalityGroup) {\n    checkNotNull(equalityGroup);\n    List<Object> list = new ArrayList<>(equalityGroup.length);\n    for (int i = 0; i < equalityGroup.length; i++) {\n      Object element = equalityGroup[i];\n      if (element == null) {\n        throw new NullPointerException(\"at index \" + i);\n      }\n      list.add(element);\n    }\n    equalityGroups.add(list);\n    return this;\n  }\n\n  /** Run tests on equals method, throwing a failure on an invalid test */\n  @CanIgnoreReturnValue\n  public EqualsTester testEquals() {\n    RelationshipTester<Object> delegate =\n        new RelationshipTester<>(\n            Equivalence.equals(), \"Object#equals\", \"Object#hashCode\", itemReporter);\n    for (List<Object> group : equalityGroups) {\n      delegate.addRelatedGroup(group);\n    }\n    for (int run = 0; run < REPETITIONS; run++) {\n      testItems();","sourceCodeStart":99,"sourceCodeEnd":135,"githubUrl":"https://github.com/google/guava/blob/94f39958baf7ad51ddf9c70e406ed6b188194daa/android/guava-testlib/src/com/google/common/testing/EqualsTester.java#L99-L135","documentation":"EqualsTester.addEqualityGroup(...) forbids null elements. EqualsTester always verifies on its own that every object returns false from equals(null), so letting the user also pass null would be redundant and ambiguous about which group it belongs to. A null in the varargs array triggers a NullPointerException naming the offending index.","triggerScenarios":"Calling new EqualsTester().addEqualityGroup(a, null, b) — i.e. passing a null reference anywhere in the equalityGroup varargs. The check runs on every element before the group is stored.","commonSituations":"Converting a List/Map that contains null values into an array passed to addEqualityGroup; misunderstanding the API and trying to test equals(null) yourself; arrays widened to Object[] that sneak in a null.","solutions":["Remove the null element from the group; EqualsTester already asserts equals(null) == false for every object.","If you meant to test a null-like case, substitute Optional.empty(), a sentinel object, or an empty collection — never null.","Filter nulls out before constructing the group when sourcing from a nullable collection."],"exampleFix":"// before\ntester.addEqualityGroup(a, null, b); // NullPointerException: at index 1\n\n// after\ntester.addEqualityGroup(a, b); // equals(null) checked automatically","handlingStrategy":"validation","validationCode":"// Strip nulls before forming a group; EqualsTester checks equals(null) itself.\nObject[] safe = Arrays.stream(maybeWithNulls)\n    .filter(Objects::nonNull)\n    .toArray();\nnew EqualsTester().addEqualityGroup(safe).testEquals();","typeGuard":"// If you build groups dynamically, guard each element.\nstatic boolean isGroupable(Object o) { return o != null; }","tryCatchPattern":null,"preventionTips":["Never pass null in addEqualityGroup(...); EqualsTester already tests equals(null) == false.","When sourcing a group from a collection, filter nulls first.","Represent 'absent' with Optional.empty() or a sentinel object, not null.","Treat the NullPointerException: at index N message as a data error in your test inputs."],"tags":["guava","testing","equals","null-pointer","validation"],"backgroundTag":null,"analyzedSha":"94f39958baf7ad51ddf9c70e406ed6b188194daa","analyzedAt":"2026-08-13T22:50:30.265Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}