@@ -58,6 +58,9 @@ public abstract static class Builder<R, B extends Builder<R, B>> {
5858 private String etag ;
5959 private Integer version ;
6060
61+ /**
62+ * Constructor for IAM Policy builder.
63+ */
6164 protected Builder () {}
6265
6366 /**
@@ -73,6 +76,8 @@ public final B bindings(Map<R, Set<Identity>> bindings) {
7376
7477 /**
7578 * Adds a binding to the policy.
79+ *
80+ * @throws IllegalArgumentException if the policy already contains a binding with the same role
7681 */
7782 public final B addBinding (R role , Set <Identity > identities ) {
7883 checkArgument (!bindings .containsKey (role ),
@@ -83,6 +88,8 @@ public final B addBinding(R role, Set<Identity> identities) {
8388
8489 /**
8590 * Adds a binding to the policy.
91+ *
92+ * @throws IllegalArgumentException if the policy already contains a binding with the same role
8693 */
8794 public final B addBinding (R role , Identity first , Identity ... others ) {
8895 checkArgument (!bindings .containsKey (role ),
@@ -104,8 +111,12 @@ public final B removeBinding(R role) {
104111
105112 /**
106113 * Adds one or more identities to an existing binding.
114+ *
115+ * @throws IllegalArgumentException if the policy doesn't contain a binding with the specified
116+ * role
107117 */
108118 public final B addIdentity (R role , Identity first , Identity ... others ) {
119+ checkArgument (bindings .containsKey (role ), "The policy doesn't contain the specified role." );
109120 Set <Identity > identities = bindings .get (role );
110121 identities .add (first );
111122 identities .addAll (Arrays .asList (others ));
@@ -114,8 +125,12 @@ public final B addIdentity(R role, Identity first, Identity... others) {
114125
115126 /**
116127 * Removes one or more identities from an existing binding.
128+ *
129+ * @throws IllegalArgumentException if the policy doesn't contain a binding with the specified
130+ * role
117131 */
118132 public final B removeIdentity (R role , Identity first , Identity ... others ) {
133+ checkArgument (bindings .containsKey (role ), "The policy doesn't contain the specified role." );
119134 bindings .get (role ).remove (first );
120135 bindings .get (role ).removeAll (Arrays .asList (others ));
121136 return self ();
0 commit comments