Fix setting default values for Pattern options
Options in bazel can have default values assigned to them, which are validated
against allowed values. We have a bug where restricting the possible values of
a Pattern will break the default value. It happens because we create
Pattern objects, which use the default (by reference) implementation of equals.
This violates the contract used by bazel converters that options created from
the same representation will return true if compared using corresponding equals
method.
Create a wrapper around Pattern which implements proper equals (compliant with
the contract). Also, specify the contract in Converter to explicitly state the
assumptions and add tests covering the RegexPatternConverter and the
problematic scenario from the bug.
RELNOTES: none.
PiperOrigin-RevId: 241764234
diff --git a/src/main/java/com/google/devtools/common/options/Converter.java b/src/main/java/com/google/devtools/common/options/Converter.java
index 9b3c13b..f3e6ddd 100644
--- a/src/main/java/com/google/devtools/common/options/Converter.java
+++ b/src/main/java/com/google/devtools/common/options/Converter.java
@@ -20,7 +20,8 @@
public interface Converter<T> {
/**
- * Convert a string into type T.
+ * Convert a string into type T. Please note that we assume that converting the same string (if
+ * successful) will produce objects which are equal ({@link Object#equals)}).
*/
T convert(String input) throws OptionsParsingException;