@@ -81,8 +81,10 @@ public class GenericConversionService implements ConfigurableConversionService {
8181
8282 public void addConverter (Converter <?, ?> converter ) {
8383 GenericConverter .ConvertiblePair typeInfo = getRequiredTypeInfo (converter , Converter .class );
84- Assert .notNull (typeInfo , "Unable to the determine sourceType <S> and targetType " +
85- "<T> which your Converter<S, T> converts between; declare these generic types." );
84+ if (typeInfo == null ) {
85+ throw new IllegalArgumentException ("Unable to determine source type <S> and target type <T> for your " +
86+ "Converter [" + converter .getClass ().getName () + "]; does the class parameterize those types?" );
87+ }
8688 addConverter (new ConverterAdapter (converter , typeInfo ));
8789 }
8890
@@ -96,14 +98,13 @@ public void addConverter(GenericConverter converter) {
9698 invalidateCache ();
9799 }
98100
99- public void addConverterFactory (ConverterFactory <?, ?> converterFactory ) {
100- GenericConverter .ConvertiblePair typeInfo = getRequiredTypeInfo (converterFactory , ConverterFactory .class );
101+ public void addConverterFactory (ConverterFactory <?, ?> factory ) {
102+ GenericConverter .ConvertiblePair typeInfo = getRequiredTypeInfo (factory , ConverterFactory .class );
101103 if (typeInfo == null ) {
102- throw new IllegalArgumentException ("Unable to the determine sourceType <S> and " +
103- "targetRangeType R which your ConverterFactory<S, R> converts between; " +
104- "declare these generic types." );
104+ throw new IllegalArgumentException ("Unable to determine source type <S> and target type <T> for your " +
105+ "ConverterFactory [" + factory .getClass ().getName () + "]; does the class parameterize those types?" );
105106 }
106- addConverter (new ConverterFactoryAdapter (converterFactory , typeInfo ));
107+ addConverter (new ConverterFactoryAdapter (factory , typeInfo ));
107108 }
108109
109110 public void removeConvertible (Class <?> sourceType , Class <?> targetType ) {
@@ -129,17 +130,18 @@ public boolean canConvert(TypeDescriptor sourceType, TypeDescriptor targetType)
129130 }
130131
131132 /**
132- * Returns true if conversion between the sourceType and targetType can be bypassed.
133- * More precisely this method will return true if objects of sourceType can be
133+ * Return whether conversion between the sourceType and targetType can be bypassed.
134+ * <p> More precisely, this method will return true if objects of sourceType can be
134135 * converted to the targetType by returning the source object unchanged.
135- * @param sourceType context about the source type to convert from (may be null if source is null)
136+ * @param sourceType context about the source type to convert from
137+ * (may be {@code null} if source is {@code null})
136138 * @param targetType context about the target type to convert to (required)
137- * @return true if conversion can be bypassed
138- * @throws IllegalArgumentException if targetType is null
139+ * @return {@code true} if conversion can be bypassed; {@code false} otherwise
140+ * @throws IllegalArgumentException if targetType is {@code null}
139141 * @since 3.2
140142 */
141143 public boolean canBypassConvert (TypeDescriptor sourceType , TypeDescriptor targetType ) {
142- Assert .notNull (targetType , "The targetType to convert to cannot be null" );
144+ Assert .notNull (targetType , "targetType to convert to cannot be null" );
143145 if (sourceType == null ) {
144146 return true ;
145147 }
@@ -149,18 +151,18 @@ public boolean canBypassConvert(TypeDescriptor sourceType, TypeDescriptor target
149151
150152 @ SuppressWarnings ("unchecked" )
151153 public <T > T convert (Object source , Class <T > targetType ) {
152- Assert .notNull (targetType ,"The targetType to convert to cannot be null" );
154+ Assert .notNull (targetType , " targetType to convert to cannot be null" );
153155 return (T ) convert (source , TypeDescriptor .forObject (source ), TypeDescriptor .valueOf (targetType ));
154156 }
155157
156158 public Object convert (Object source , TypeDescriptor sourceType , TypeDescriptor targetType ) {
157- Assert .notNull (targetType ,"The targetType to convert to cannot be null" );
159+ Assert .notNull (targetType , " targetType to convert to cannot be null" );
158160 if (sourceType == null ) {
159- Assert .isTrue (source == null , "The source must be [null] if sourceType == [null]" );
160- return handleResult (sourceType , targetType , convertNullSource (sourceType , targetType ));
161+ Assert .isTrue (source == null , "source must be [null] if sourceType == [null]" );
162+ return handleResult (null , targetType , convertNullSource (null , targetType ));
161163 }
162164 if (source != null && !sourceType .getObjectType ().isInstance (source )) {
163- throw new IllegalArgumentException ("The source to convert from must be an instance of " +
165+ throw new IllegalArgumentException ("source to convert from must be an instance of " +
164166 sourceType + "; instead it was a " + source .getClass ().getName ());
165167 }
166168 GenericConverter converter = getConverter (sourceType , targetType );
@@ -198,7 +200,7 @@ public String toString() {
198200
199201 /**
200202 * Template method to convert a null source.
201- * <p>Default implementation returns {@code null}.
203+ * <p>The default implementation returns {@code null}.
202204 * Subclasses may override to return custom null objects for specific target types.
203205 * @param sourceType the sourceType to convert from
204206 * @param targetType the targetType to convert to
@@ -213,11 +215,10 @@ protected Object convertNullSource(TypeDescriptor sourceType, TypeDescriptor tar
213215 * First queries this ConversionService's converter cache.
214216 * On a cache miss, then performs an exhaustive search for a matching converter.
215217 * If no converter matches, returns the default converter.
216- * Subclasses may override.
217218 * @param sourceType the source type to convert from
218219 * @param targetType the target type to convert to
219- * @return the generic converter that will perform the conversion, or {@code null} if
220- * no suitable converter was found
220+ * @return the generic converter that will perform the conversion,
221+ * or {@code null} if no suitable converter was found
221222 * @see #getDefaultConverter(TypeDescriptor, TypeDescriptor)
222223 */
223224 protected GenericConverter getConverter (TypeDescriptor sourceType , TypeDescriptor targetType ) {
@@ -243,9 +244,8 @@ protected GenericConverter getConverter(TypeDescriptor sourceType, TypeDescripto
243244
244245 /**
245246 * Return the default converter if no converter is found for the given sourceType/targetType pair.
246- * Returns a NO_OP Converter if the sourceType is assignable to the targetType.
247+ * <p> Returns a NO_OP Converter if the sourceType is assignable to the targetType.
247248 * Returns {@code null} otherwise, indicating no suitable converter could be found.
248- * Subclasses may override.
249249 * @param sourceType the source type to convert from
250250 * @param targetType the target type to convert to
251251 * @return the default generic converter that will perform the conversion
0 commit comments