[fix] relax @CompileTimeConstant requirement on SafeArg key #119
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation
In 1.8.0 we started requiring
SafeArg.of(key, value)
to have a compile time constant key. The intention was to prevent people wrapping unknown key-value pairs as SafeArgs, which would make it harder to CR and spot potential data leaks.Since merging this, we've had a lot of complaints - particularly because it is impossible to suppress the
CompileTimeStatic
check. This has caused problems for anyone who was dynamically constructing args, leading them to choose one of the following approaches:As far as we can tell, this annotation hasn't actually motivated people to replace dynamic usages with non-dynamic usages.
Proposal
Google's error-prone maintainers carefully weigh the cost-benefit of introducing a new check vs the false positives and friction it causes. In this case, I think the friction outweighs the potential upside.
I'd propose turning this into a regular error-prone check, as part of baseline. This would ensure that at the time new code is being written, people will get a warning if they dynamically construct SafeArgs and have to either rethink their approach or justify their suppression of this check.