{"record":{"id":"82e7350f8156d625","repo":"google/guava","slug":"cannot-generate-distinct-value-for-parameter-s-of","errorCode":null,"errorMessage":"Cannot generate distinct value for parameter %s of %s","messagePattern":"Cannot generate distinct value for parameter (.+?) of (.+?)","errorType":"exception","errorClass":"ParameterHasNoDistinctValueException","httpStatus":null,"severity":"error","filePath":"android/guava-testlib/src/com/google/common/testing/ClassSanityTester.java","lineNumber":613,"sourceCode":"    EqualsTester tester =\n        new EqualsTester(\n            /* itemReporter= */ item -> {\n              List<Object> factoryArgs = argGroups.get(item.groupNumber).get(item.itemNumber);\n              return factory.getName()\n                  + \"(\"\n                  + Joiner.on(\", \").useForNull(\"null\").join(factoryArgs)\n                  + \")\";\n            });\n    tester.addEqualityGroup(instance, createInstance(factory, equalArgs));\n    for (int i = 0; i < params.size(); i++) {\n      List<Object> newArgs = new ArrayList<>(args);\n      Object newArg = argGenerators.get(i).generateFresh(params.get(i).getType());\n\n      if (newArg == null || Objects.equals(args.get(i), newArg)) {\n        if (params.get(i).getType().getRawType().isEnum()) {\n          continue; // Nothing better we can do if it's single-value enum\n        }\n        throw new ParameterHasNoDistinctValueException(params.get(i));\n      }\n      newArgs.set(i, newArg);\n      tester.addEqualityGroup(createInstance(factory, newArgs));\n      argGroups.add(ImmutableList.of(newArgs));\n    }\n    tester.testEquals();\n  }\n\n  /**\n   * Returns dummy factory arguments that are equal to {@code args} but may be different instances,\n   * to be used to construct a second instance of the same equality group.\n   */\n  @SuppressWarnings(\"ReferenceEquality\") // checking for the case of equal but non-identical objects\n  private List<Object> generateEqualFactoryArguments(\n      Invokable<?, ?> factory, List<Parameter> params, List<Object> args)\n      throws ParameterNotInstantiableException,\n          FactoryMethodReturnsNullException,\n          InvocationTargetException,","sourceCodeStart":595,"sourceCodeEnd":631,"githubUrl":"https://github.com/google/guava/blob/94f39958baf7ad51ddf9c70e406ed6b188194daa/android/guava-testlib/src/com/google/common/testing/ClassSanityTester.java#L595-L631","documentation":"Thrown as ParameterHasNoDistinctValueException during ClassSanityTester's equals test when it cannot produce a second, distinct non-null value for a constructor/factory parameter. To verify equals, the tester needs at least two distinguishable argument values per parameter; if the only candidate equals the first (and it is not a single-value enum), the equals test cannot be constructed.","triggerScenarios":"Calling testEquals()/testAll() on a class whose constructor parameter has a type for which FreshValueGenerator cannot synthesize a fresh distinct value (e.g. an opaque interface/type with no registered sample instances and no concrete default).","commonSituations":"A value class whose constructor takes an interface type with no registered defaults; third-party types not covered by setDefault; a parameter whose only sample value collides with the first.","solutions":["Register sample/fresh distinct instances for the parameter type via ClassSanityTester.setDefault(Class, instance...) / setDistinctValues(Class, a, b).","Provide a FreshValueGenerator sample for the type so the tester can mint a distinct value.","If the parameter is genuinely single-valued or not relevant to equality, annotate it or exclude the class/field from the equals test."],"exampleFix":"// before\nsanityTester.testEquals(MyWrapper.class); // ctor takes Clock -> no distinct value\n\n// after\nsanityTester.setDistinctValues(Clock.class,\n    Clock.systemUTC(), Clock.system(\"UTC\"));\nsanityTester.testEquals(MyWrapper.class);","handlingStrategy":"validation","validationCode":"sanityTester.setDistinctValues(MyInterface.class, instanceA, instanceB);\nsanityTester.testEquals(MyType.class);","typeGuard":null,"tryCatchPattern":"try { sanityTester.testEquals(MyType.class); }\ncatch (ClassSanityTester.ParameterHasNoDistinctValueException e) {\n  // read e.getMessage() to find the parameter, register a distinct value, retry\n}","preventionTips":["Register distinct sample values (setDefault / setDistinctValues) for every interface/abstract parameter type before testEquals().","Keep a central registry of sample instances for collaborators used in value types."],"tags":["guava-testlib","equals-hashcode","reflection","class-sanity"],"backgroundTag":null,"analyzedSha":"94f39958baf7ad51ddf9c70e406ed6b188194daa","analyzedAt":"2026-08-13T22:50:30.265Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}