@@ -81,6 +81,7 @@ public static class Builder {
8181 private Statement .Builder currentStatementBuilder ;
8282
8383 private Builder () {
84+ this .currentStatementBuilder = Statement .builder ();
8485 }
8586
8687 /**
@@ -113,7 +114,6 @@ public Builder statement(String sid) {
113114 * @return this Builder instance
114115 */
115116 public Builder effect (String effect ) {
116- validateCurrentStatement ();
117117 this .currentStatementBuilder .effect (effect );
118118 return this ;
119119 }
@@ -125,7 +125,6 @@ public Builder effect(String effect) {
125125 * @return this Builder instance
126126 */
127127 public Builder addPrincipal (String principal ) {
128- validateCurrentStatement ();
129128 this .currentStatementBuilder .addPrincipal (principal );
130129 return this ;
131130 }
@@ -137,7 +136,6 @@ public Builder addPrincipal(String principal) {
137136 * @return this Builder instance
138137 */
139138 public Builder addPrincipals (List <String > principals ) {
140- validateCurrentStatement ();
141139 this .currentStatementBuilder .addPrincipals (principals );
142140 return this ;
143141 }
@@ -149,7 +147,6 @@ public Builder addPrincipals(List<String> principals) {
149147 * @return this Builder instance
150148 */
151149 public Builder addAction (String action ) {
152- validateCurrentStatement ();
153150 this .currentStatementBuilder .addAction (action );
154151 return this ;
155152 }
@@ -161,7 +158,6 @@ public Builder addAction(String action) {
161158 * @return this Builder instance
162159 */
163160 public Builder addActions (List <String > actions ) {
164- validateCurrentStatement ();
165161 this .currentStatementBuilder .addActions (actions );
166162 return this ;
167163 }
@@ -173,7 +169,6 @@ public Builder addActions(List<String> actions) {
173169 * @return this Builder instance
174170 */
175171 public Builder addResource (String resource ) {
176- validateCurrentStatement ();
177172 this .currentStatementBuilder .addResource (resource );
178173 return this ;
179174 }
@@ -185,7 +180,6 @@ public Builder addResource(String resource) {
185180 * @return this Builder instance
186181 */
187182 public Builder addResources (List <String > resources ) {
188- validateCurrentStatement ();
189183 this .currentStatementBuilder .addResources (resources );
190184 return this ;
191185 }
@@ -199,7 +193,6 @@ public Builder addResources(List<String> resources) {
199193 * @return this Builder instance
200194 */
201195 public Builder addCondition (String operator , String key , Object value ) {
202- validateCurrentStatement ();
203196 this .currentStatementBuilder .addCondition (operator , key , value );
204197 return this ;
205198 }
@@ -245,16 +238,16 @@ public PolicyDocument build() {
245238 return new PolicyDocument (this );
246239 }
247240
248- private void validateCurrentStatement () {
249- if (currentStatementBuilder == null ) {
250- throw new InvalidArgumentException ("No statement is currently being built. Call statement(sid) first." );
251- }
252- }
253241
254242 private void finalizeCurrentStatement () {
255243 if (currentStatementBuilder != null ) {
256- statements .add (currentStatementBuilder .build ());
257- currentStatementBuilder = null ;
244+ // Only finalize statements that have the minimum required content
245+ if (currentStatementBuilder .hasMinimumContent ()) {
246+ Statement statement = currentStatementBuilder .build ();
247+ statements .add (statement );
248+ }
249+ // Always reinitialize for the next statement
250+ currentStatementBuilder = Statement .builder ();
258251 }
259252 }
260253 }
0 commit comments