@@ -229,24 +229,33 @@ public BootstrapMetadata bootstrapMetadata() {
229229 return bootstrapMetadata ;
230230 }
231231
232- public void run () throws Exception {
233- if (nodeId < 0 ) {
234- throw new RuntimeException ("You must specify a valid non-negative node ID." );
235- }
232+ /**
233+ * Validates the correctness of the given cluster id. A valid cluster id is a base64, urlencoded, no padding
234+ * representation of a {@link Uuid}. These checks do not validate the absence of <code>-</code> character as
235+ * {@link Uuid#randomUuid()} avoids them only for convenience reasons.
236+ */
237+ private void validateClusterId (String clusterId ) {
236238 if (clusterId == null ) {
237239 throw new FormatterException ("You must specify the cluster id." );
238240 }
241+ if (clusterId .contains ("=" )) {
242+ throw new FormatterException ("The specified cluster id, " + clusterId + " is invalid: contains padding" );
243+ }
239244 try {
240- if (clusterId .contains ("=" )) {
241- throw new FormatterException ("The specified cluster id, " + clusterId + " contains padding and is invalid" );
242- }
243245 Uuid uuid = Uuid .fromString (clusterId );
244246 if (Uuid .RESERVED .contains (uuid )) {
245247 throw new FormatterException ("The specified cluster id, " + clusterId + " is reserved" );
246248 }
247249 } catch (IllegalArgumentException e ) {
248250 throw new FormatterException ("The specified cluster id, " + clusterId + " is invalid" , e );
249251 }
252+ }
253+
254+ public void run () throws Exception {
255+ if (nodeId < 0 ) {
256+ throw new RuntimeException ("You must specify a valid non-negative node ID." );
257+ }
258+ validateClusterId (clusterId );
250259 if (directories .isEmpty ()) {
251260 throw new FormatterException ("You must specify at least one directory to format" );
252261 }
0 commit comments