@@ -617,55 +617,64 @@ private static void mapPropertiesToOption(Builder builder, Properties properties
617
617
// loop on properties,
618
618
// - check DefaultOption to check that property value correspond to type (and range)
619
619
// - set values
620
- for (final Object keyObj : properties .keySet ()) {
621
- String realKey = OptionAliases .OPTIONS_ALIASES .get (keyObj );
622
- if (realKey == null ) realKey = keyObj .toString ();
623
- final Object propertyValue = properties .get (keyObj );
624
-
625
- if (propertyValue != null && realKey != null ) {
626
- try {
627
- final Field field = Builder .class .getDeclaredField (realKey );
628
- field .setAccessible (true );
629
- if (field .getGenericType ().equals (String .class )
630
- && !propertyValue .toString ().isEmpty ()) {
631
- field .set (builder , propertyValue );
632
- } else if (field .getGenericType ().equals (Boolean .class )) {
633
- switch (propertyValue .toString ().toLowerCase ()) {
634
- case "" :
635
- case "1" :
636
- case "true" :
637
- field .set (builder , Boolean .TRUE );
638
- break ;
639
-
640
- case "0" :
641
- case "false" :
642
- field .set (builder , Boolean .FALSE );
643
- break ;
644
-
645
- default :
620
+ Properties remainingProperties = new Properties ();
621
+ properties .forEach ((key , val ) -> remainingProperties .put (key , val ));
622
+
623
+ for (Field field : Builder .class .getDeclaredFields ()) {
624
+ if (remainingProperties .isEmpty ()) break ;
625
+ for (final Object keyObj : remainingProperties .keySet ()) {
626
+ String realKey =
627
+ OptionAliases .OPTIONS_ALIASES .get (keyObj .toString ().toLowerCase (Locale .ROOT ));
628
+ if (realKey == null ) realKey = keyObj .toString ();
629
+ final Object propertyValue = remainingProperties .get (keyObj );
630
+
631
+ if (propertyValue != null && realKey != null ) {
632
+ if (realKey .toLowerCase (Locale .ROOT ).equals (field .getName ().toLowerCase (Locale .ROOT ))) {
633
+ field .setAccessible (true );
634
+ remainingProperties .remove (keyObj );
635
+
636
+ if (field .getGenericType ().equals (String .class )
637
+ && !propertyValue .toString ().isEmpty ()) {
638
+ field .set (builder , propertyValue );
639
+ } else if (field .getGenericType ().equals (Boolean .class )) {
640
+ switch (propertyValue .toString ().toLowerCase ()) {
641
+ case "" :
642
+ case "1" :
643
+ case "true" :
644
+ field .set (builder , Boolean .TRUE );
645
+ break ;
646
+
647
+ case "0" :
648
+ case "false" :
649
+ field .set (builder , Boolean .FALSE );
650
+ break ;
651
+
652
+ default :
653
+ throw new IllegalArgumentException (
654
+ String .format (
655
+ "Optional parameter %s must be boolean (true/false or 0/1) was '%s'" ,
656
+ keyObj , propertyValue ));
657
+ }
658
+ } else if (field .getGenericType ().equals (Integer .class )) {
659
+ try {
660
+ final Integer value = Integer .parseInt (propertyValue .toString ());
661
+ field .set (builder , value );
662
+ } catch (NumberFormatException n ) {
646
663
throw new IllegalArgumentException (
647
664
String .format (
648
- "Optional parameter %s must be boolean (true/false or 0/1) was '%s'" ,
665
+ "Optional parameter %s must be Integer, was '%s'" ,
649
666
keyObj , propertyValue ));
650
- }
651
- } else if (field .getGenericType ().equals (Integer .class )) {
652
- try {
653
- final Integer value = Integer .parseInt (propertyValue .toString ());
654
- field .set (builder , value );
655
- } catch (NumberFormatException n ) {
656
- throw new IllegalArgumentException (
657
- String .format (
658
- "Optional parameter %s must be Integer, was '%s'" , keyObj , propertyValue ));
667
+ }
659
668
}
660
669
}
661
- } catch (NoSuchFieldException nfe ) {
662
- // keep unknown option:
663
- // those might be used in authentication or identity plugin
664
- nonMappedOptions .put (keyObj , propertyValue );
665
670
}
666
671
}
667
672
}
668
673
674
+ // keep unknown option:
675
+ // those might be used in authentication or identity plugin
676
+ remainingProperties .forEach ((key , val ) -> nonMappedOptions .put (key , val ));
677
+
669
678
// for compatibility with 2.x
670
679
if (isSet ("useSsl" , nonMappedOptions ) || isSet ("useSSL" , nonMappedOptions )) {
671
680
Properties deprecatedDesc = new Properties ();
0 commit comments