Fix ISE when code ownership is assigned to 2 emails of the same account

If code ownership is assigned to the primary and secondary email of one
account at the same time, there was an ISE in CodeOwnerResolver when
trying to create the CodeOwner to annotations map [1] (because it cannot
have 2 entries with the same CodeOwner as key).

Rewrite this logic to avoid this issue and add tests to cover this case.

[1]
Caused by: java.lang.IllegalArgumentException: Multiple entries with same key: CodeOwner{accountId=100019}=[] and CodeOwner{accountId=100019}=[]
  at com.google.common.collect.ImmutableMap.conflictException(ImmutableMap.java:226)
  at com.google.common.collect.ImmutableMap.checkNoConflict(ImmutableMap.java:220)
  at com.google.common.collect.RegularImmutableMap.checkNoConflictInKeyBucket(RegularImmutableMap.java:146)
  at com.google.common.collect.RegularImmutableMap.fromEntryArray(RegularImmutableMap.java:109)
  at com.google.common.collect.ImmutableMap$Builder.build(ImmutableMap.java:405)
  at java.base/java.util.stream.ReferencePipeline.collect(Unknown Source)
  at com.google.gerrit.plugins.codeowners.backend.CodeOwnerResolver.resolve(CodeOwnerResolver.java:451)
  ...

Signed-off-by: Edwin Kempin <ekempin@google.com>
Change-Id: Ib159ebbd08f92d11945cc74c9774028f93d6722a
2 files changed
tree: 26f228e9a9d578a0dc4be919467c899d84add825
  1. java/
  2. javatests/
  3. proto/
  4. resources/
  5. test/
  6. ui/
  7. .eslintrc.json
  8. .gitignore
  9. .gitreview
  10. bower.json
  11. BUILD
  12. LICENSE
  13. package-lock.json
  14. package.json
  15. README.md
README.md

Gerrit Code Review code-owners plugin

This plugin provides support for defining code owners for files in a repository.

If the code-owners plugin is enabled, changes can only be submitted if all touched files are covered by approvals from code owners.

Also see resources/Documentation/about.md.

IMPORTANT: Before installing/enabling the plugin follow the instructions from the setup guide, see resources/Documentation/setup-guide.md.