@@ -185,8 +185,7 @@ public static Object to(final Class<?> cls, final Object value, final DefaultCon
185185 if (Duration .class .equals (cls )) {
186186 return toDuration (value );
187187 }
188-
189- throw new ConversionException ("The value '" + value + "' (" + value .getClass () + ") can't be converted to a " + cls .getName () + " object" );
188+ throw new ConversionException ("The value '%s' (%s) can't be converted to a %s object" , value , value .getClass (), cls .getName ());
190189 }
191190
192191 /**
@@ -234,11 +233,11 @@ public static Boolean toBoolean(final Object value) throws ConversionException {
234233 return (Boolean ) value ;
235234 }
236235 if (!(value instanceof String )) {
237- throw new ConversionException ("The value " + value + " can't be converted to a Boolean object" );
236+ throw new ConversionException ("The value %s can't be converted to a Boolean object" , value );
238237 }
239238 final Boolean b = BooleanUtils .toBooleanObject ((String ) value );
240239 if (b == null ) {
241- throw new ConversionException ("The value " + value + " can't be converted to a Boolean object" );
240+ throw new ConversionException ("The value %s can't be converted to a Boolean object" , value );
242241 }
243242 return b ;
244243 }
@@ -276,14 +275,14 @@ public static Calendar toCalendar(final Object value, final String format) throw
276275 return calendar ;
277276 }
278277 if (!(value instanceof String )) {
279- throw new ConversionException ("The value " + value + " can't be converted to a Calendar" );
278+ throw new ConversionException ("The value %s can't be converted to a Calendar" , value );
280279 }
281280 try {
282281 final Calendar calendar = Calendar .getInstance ();
283282 calendar .setTime (new SimpleDateFormat (format ).parse ((String ) value ));
284283 return calendar ;
285284 } catch (final ParseException e ) {
286- throw new ConversionException ("The value " + value + " can't be converted to a Calendar" , e );
285+ throw new ConversionException (e , "The value %s can't be converted to a Calendar" , value );
287286 }
288287 }
289288
@@ -300,7 +299,7 @@ public static Character toCharacter(final Object value) throws ConversionExcepti
300299 if (strValue .length () == 1 ) {
301300 return Character .valueOf (strValue .charAt (0 ));
302301 }
303- throw new ConversionException (String . format ( "The value '%s' cannot be converted to a Character object!" , strValue ) );
302+ throw new ConversionException ("The value '%s' cannot be converted to a Character object!" , strValue );
304303 }
305304
306305 /**
@@ -322,7 +321,7 @@ public static Color toColor(final Object value) throws ConversionException {
322321 return (Color ) value ;
323322 }
324323 if (!(value instanceof String ) || StringUtils .isBlank ((String ) value )) {
325- throw new ConversionException ("The value " + value + " can't be converted to a Color" );
324+ throw new ConversionException ("The value %s can't be converted to a Color" , value );
326325 }
327326 String color = ((String ) value ).trim ();
328327
@@ -331,7 +330,7 @@ public static Color toColor(final Object value) throws ConversionException {
331330 // check the size of the string
332331 final int minlength = components .length * 2 ;
333332 if (color .length () < minlength ) {
334- throw new ConversionException ("The value " + value + " can't be converted to a Color" );
333+ throw new ConversionException ("The value %s can't be converted to a Color" , value );
335334 }
336335
337336 // remove the leading #
@@ -355,7 +354,7 @@ public static Color toColor(final Object value) throws ConversionException {
355354
356355 return new Color (components [0 ], components [1 ], components [2 ], alpha );
357356 } catch (final Exception e ) {
358- throw new ConversionException ("The value " + value + " can't be converted to a Color" , e );
357+ throw new ConversionException (e , "The value %s can't be converted to a Color" , value );
359358 }
360359 }
361360
@@ -375,12 +374,12 @@ public static Date toDate(final Object value, final String format) throws Conver
375374 return ((Calendar ) value ).getTime ();
376375 }
377376 if (!(value instanceof String )) {
378- throw new ConversionException ("The value " + value + " can't be converted to a Date" );
377+ throw new ConversionException ("The value %s can't be converted to a Date" , value );
379378 }
380379 try {
381380 return new SimpleDateFormat (format ).parse ((String ) value );
382381 } catch (final ParseException e ) {
383- throw new ConversionException ("The value " + value + " can't be converted to a Date" , e );
382+ throw new ConversionException (e , "The value %s can't be converted to a Date" , value );
384383 }
385384 }
386385
@@ -415,10 +414,10 @@ public static Duration toDuration(final Object value) throws ConversionException
415414 try {
416415 return Duration .parse ((CharSequence ) value );
417416 } catch (final DateTimeParseException e ) {
418- throw new ConversionException ("Could not convert " + value + " to Duration" , e );
417+ throw new ConversionException (e , "Could not convert %s to Duration" , value );
419418 }
420419 }
421- throw new ConversionException ("The value " + value + " can't be converted to a Duration" );
420+ throw new ConversionException ("The value %s can't be converted to a Duration" , value );
422421 }
423422
424423 /**
@@ -438,17 +437,17 @@ static <E extends Enum<E>> E toEnum(final Object value, final Class<E> cls) thro
438437 try {
439438 return Enum .valueOf (cls , (String ) value );
440439 } catch (final Exception e ) {
441- throw new ConversionException ("The value " + value + " can't be converted to a " + cls .getName ());
440+ throw new ConversionException (e , "The value %s can't be converted to a %s" , value , cls .getName ());
442441 }
443442 }
444443 if (!(value instanceof Number )) {
445- throw new ConversionException ("The value " + value + " can't be converted to a " + cls .getName ());
444+ throw new ConversionException ("The value %s can't be converted to a " , value , cls .getName ());
446445 }
447446 try {
448447 final E [] enumConstants = cls .getEnumConstants ();
449448 return enumConstants [((Number ) value ).intValue ()];
450449 } catch (final Exception e ) {
451- throw new ConversionException ("The value " + value + " can't be converted to a " + cls .getName ());
450+ throw new ConversionException (e , "The value %s can't be converted to a " , value , cls .getName ());
452451 }
453452 }
454453
@@ -470,7 +469,7 @@ public static File toFile(final Object value) throws ConversionException {
470469 if (value instanceof String ) {
471470 return new File ((String ) value );
472471 }
473- throw new ConversionException ("The value " + value + " can't be converted to a File" );
472+ throw new ConversionException ("The value %s can't be converted to a File" , value );
474473 }
475474
476475 /**
@@ -501,12 +500,12 @@ static InetAddress toInetAddress(final Object value) throws ConversionException
501500 return (InetAddress ) value ;
502501 }
503502 if (!(value instanceof String )) {
504- throw new ConversionException ("The value " + value + " can't be converted to a InetAddress" );
503+ throw new ConversionException ("The value %s can't be converted to a InetAddress" , value );
505504 }
506505 try {
507506 return InetAddress .getByName ((String ) value );
508507 } catch (final UnknownHostException e ) {
509- throw new ConversionException ("The value " + value + " can't be converted to a InetAddress" , e );
508+ throw new ConversionException (e , "The value %s can't be converted to a InetAddress" , value );
510509 }
511510 }
512511
@@ -540,13 +539,13 @@ static Object toInternetAddress(final Object value, final String targetClassName
540539 return value ;
541540 }
542541 if (!(value instanceof String )) {
543- throw new ConversionException ("The value " + value + " can't be converted to an InternetAddress" );
542+ throw new ConversionException ("The value %s can't be converted to an InternetAddress" , value );
544543 }
545544 try {
546545 final Constructor <?> ctor = Class .forName (targetClassName ).getConstructor (String .class );
547546 return ctor .newInstance (value );
548547 } catch (final Exception e ) {
549- throw new ConversionException ("The value " + value + " can't be converted to an InternetAddress" , e );
548+ throw new ConversionException (e , "The value %s can't be converted to an InternetAddress" , value );
550549 }
551550 }
552551
@@ -562,7 +561,7 @@ public static Locale toLocale(final Object value) throws ConversionException {
562561 return (Locale ) value ;
563562 }
564563 if (!(value instanceof String )) {
565- throw new ConversionException ("The value " + value + " can't be converted to a Locale" );
564+ throw new ConversionException ("The value %s can't be converted to a Locale" , value );
566565 }
567566 final String [] elements = ((String ) value ).split ("_" );
568567 final int size = elements .length ;
@@ -574,7 +573,7 @@ public static Locale toLocale(final Object value) throws ConversionException {
574573
575574 return new Locale (language , country , variant );
576575 }
577- throw new ConversionException ("The value " + value + " can't be converted to a Locale" );
576+ throw new ConversionException ("The value %s can't be converted to a Locale" , value );
578577 }
579578
580579 /**
@@ -610,27 +609,25 @@ static Number toNumber(final Object value, final Class<?> targetClass) throws Co
610609 if (Strings .CS .startsWithAny (str , HEX_PREFIX )) {
611610 try {
612611 return new BigInteger (str .substring (HEX_PREFIX .length ()), HEX_RADIX );
613- } catch (final NumberFormatException nex ) {
614- throw new ConversionException ("Could not convert " + str + " to " + targetClass . getName () + " ! Invalid hex number." , nex );
612+ } catch (final NumberFormatException e ) {
613+ throw new ConversionException (e , "Could not convert %s to %s ! Invalid hex number." , str , targetClass . getName () );
615614 }
616615 }
617-
618616 if (Strings .CS .startsWithAny (str , BIN_PREFIX )) {
619617 try {
620618 return new BigInteger (str .substring (BIN_PREFIX .length ()), BIN_RADIX );
621- } catch (final NumberFormatException nex ) {
622- throw new ConversionException ("Could not convert " + str + " to " + targetClass . getName () + " ! Invalid binary number." , nex );
619+ } catch (final NumberFormatException e ) {
620+ throw new ConversionException (e , "Could not convert %s to %s ! Invalid binary number." , str , targetClass . getName () );
623621 }
624622 }
625-
626623 try {
627624 final Constructor <?> constr = targetClass .getConstructor (CONSTR_ARGS );
628625 return (Number ) constr .newInstance (str );
629- } catch (final InvocationTargetException itex ) {
630- throw new ConversionException ("Could not convert " + str + " to " + targetClass .getName (), itex . getTargetException ());
631- } catch (final Exception ex ) {
626+ } catch (final InvocationTargetException e ) {
627+ throw new ConversionException (e . getTargetException (), "Could not convert %s to %s" , str , targetClass .getName ());
628+ } catch (final Exception e ) {
632629 // Treat all possible exceptions the same way
633- throw new ConversionException ("Conversion error when trying to convert " + str + " to " + targetClass .getName (), ex );
630+ throw new ConversionException (e , "Conversion error when trying to convert %s to %s" , str , targetClass .getName ());
634631 }
635632 }
636633
@@ -652,7 +649,7 @@ public static Path toPath(final Object value) throws ConversionException {
652649 if (value instanceof String ) {
653650 return Paths .get ((String ) value );
654651 }
655- throw new ConversionException ("The value " + value + " can't be converted to a Path" );
652+ throw new ConversionException ("The value %s can't be converted to a Path" , value );
656653 }
657654
658655 /**
@@ -667,12 +664,12 @@ public static Pattern toPattern(final Object value) throws ConversionException {
667664 return (Pattern ) value ;
668665 }
669666 if (!(value instanceof String )) {
670- throw new ConversionException ("The value " + value + " can't be converted to a Pattern" );
667+ throw new ConversionException ("The value %s can't be converted to a Pattern" , value );
671668 }
672669 try {
673670 return Pattern .compile ((String ) value );
674671 } catch (final PatternSyntaxException e ) {
675- throw new ConversionException ("The value " + value + " can't be converted to a Pattern" , e );
672+ throw new ConversionException (e , "The value %s can't be converted to a Pattern" , value );
676673 }
677674 }
678675
@@ -703,12 +700,12 @@ public static URI toURI(final Object value) throws ConversionException {
703700 return (URI ) value ;
704701 }
705702 if (!(value instanceof String )) {
706- throw new ConversionException ("The value " + value + " can't be converted to an URI" );
703+ throw new ConversionException ("The value %s can't be converted to an URI" , value );
707704 }
708705 try {
709706 return new URI ((String ) value );
710707 } catch (final URISyntaxException e ) {
711- throw new ConversionException ("The value " + value + " can't be converted to an URI" , e );
708+ throw new ConversionException (e , "The value %s can't be converted to an URI" , value );
712709 }
713710 }
714711
@@ -724,12 +721,12 @@ public static URL toURL(final Object value) throws ConversionException {
724721 return (URL ) value ;
725722 }
726723 if (!(value instanceof String )) {
727- throw new ConversionException ("The value " + value + " can't be converted to an URL" );
724+ throw new ConversionException ("The value %s can't be converted to an URL" , value );
728725 }
729726 try {
730727 return new URL ((String ) value );
731728 } catch (final MalformedURLException e ) {
732- throw new ConversionException ("The value " + value + " can't be converted to an URL" , e );
729+ throw new ConversionException (e , "The value %s can't be converted to an URL" , value );
733730 }
734731 }
735732
0 commit comments