@@ -543,7 +543,7 @@ public void testThrowableToAndFromXContent() throws IOException {
543543 assertNotNull (parsedException );
544544
545545 ElasticsearchException expected = exceptions .v2 ();
546- while ( expected != null ) {
546+ do {
547547 assertEquals (expected .getMessage (), parsedException .getMessage ());
548548 assertEquals (expected .getHeaders (), parsedException .getHeaders ());
549549 assertEquals (expected .getMetadata (), parsedException .getMetadata ());
@@ -555,7 +555,7 @@ public void testThrowableToAndFromXContent() throws IOException {
555555 if (expected == null ) {
556556 assertNull (parsedException );
557557 }
558- }
558+ } while ( expected != null );
559559 }
560560
561561 /**
@@ -633,10 +633,11 @@ private static Tuple<Throwable, ElasticsearchException> randomExceptions() {
633633 }
634634
635635 if (actual instanceof ElasticsearchException ) {
636+ ElasticsearchException actualException = (ElasticsearchException ) actual ;
636637 if (randomBoolean ()) {
637- Map <String , List <String >> randomHeaders = new HashMap <>();
638-
639638 int nbHeaders = randomIntBetween (1 , 5 );
639+ Map <String , List <String >> randomHeaders = new HashMap <>(nbHeaders );
640+
640641 for (int i = 0 ; i < nbHeaders ; i ++) {
641642 List <String > values = new ArrayList <>();
642643
@@ -648,15 +649,15 @@ private static Tuple<Throwable, ElasticsearchException> randomExceptions() {
648649 }
649650
650651 for (Map .Entry <String , List <String >> entry : randomHeaders .entrySet ()) {
651- (( ElasticsearchException ) actual ) .addHeader (entry .getKey (), entry .getValue ());
652+ actualException .addHeader (entry .getKey (), entry .getValue ());
652653 expected .addHeader (entry .getKey (), entry .getValue ());
653654 }
654655 }
655656
656657 if (randomBoolean ()) {
657- Map <String , List <String >> randomMetadata = new HashMap <>();
658-
659658 int nbMetadata = randomIntBetween (1 , 5 );
659+ Map <String , List <String >> randomMetadata = new HashMap <>(nbMetadata );
660+
660661 for (int i = 0 ; i < nbMetadata ; i ++) {
661662 List <String > values = new ArrayList <>();
662663
@@ -668,7 +669,7 @@ private static Tuple<Throwable, ElasticsearchException> randomExceptions() {
668669 }
669670
670671 for (Map .Entry <String , List <String >> entry : randomMetadata .entrySet ()) {
671- (( ElasticsearchException ) actual ) .addMetadata (entry .getKey (), entry .getValue ());
672+ actualException .addMetadata (entry .getKey (), entry .getValue ());
672673 expected .addMetadata (entry .getKey (), entry .getValue ());
673674 }
674675 }
@@ -679,13 +680,12 @@ private static Tuple<Throwable, ElasticsearchException> randomExceptions() {
679680 String resourceType = "type_" + i ;
680681 String [] resourceIds = null ;
681682 if (frequently ()) {
682- resourceIds = new String [randomIntBetween (0 , 3 )];
683+ resourceIds = new String [randomIntBetween (1 , 3 )];
683684 for (int j = 0 ; j < resourceIds .length ; j ++) {
684685 resourceIds [j ] = frequently () ? randomAsciiOfLength (5 ) : null ;
685686 }
686687 }
687-
688- ((ElasticsearchException ) actual ).setResources (resourceType , resourceIds );
688+ actualException .setResources (resourceType , resourceIds );
689689 expected .setResources (resourceType , resourceIds );
690690 }
691691 }
0 commit comments