1
1
/*
2
- * Copyright (c) 2017, 2019 , Oracle Corporation and/or its affiliates. All rights reserved .
2
+ * Copyright (c) 2017, 2020 , Oracle Corporation and/or its affiliates.
3
3
* Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
4
4
*/
5
5
package oracle .weblogic .deploy .aliases ;
6
6
7
7
import java .io .File ;
8
8
import java .lang .reflect .Array ;
9
+ import java .lang .NumberFormatException ;
9
10
import java .util .ArrayList ;
10
11
import java .util .Arrays ;
11
12
import java .util .HashMap ;
@@ -168,7 +169,7 @@ public static Object convertToType(Class<?> targetType, Object value) throws Ali
168
169
* or the requested data type is not supported.
169
170
* @throws AliasException if classType is a primitive class type such as int, short, etc. or if a multi-valued
170
171
* type is detected where the delimiter is null and a delimiter is required to handle
171
- * the conversion.
172
+ * the conversion. Or if the numeric value cannot be converted to the numeric format.
172
173
*/
173
174
public static Object convertToType (Class <?> targetType , Object value , String delimiter ) throws AliasException {
174
175
final String METHOD = "convertToType" ;
@@ -194,38 +195,44 @@ public static Object convertToType(Class<?> targetType, Object value, String del
194
195
}
195
196
196
197
Object result ;
197
- if (targetType == String .class ) {
198
- result = strValue ;
199
- } else if (targetType == Boolean .class ) {
200
- result = convertToBoolean (strValue );
201
- } else if (targetType == Integer .class ) {
202
- result = Integer .valueOf (strValue );
203
- } else if (targetType == Short .class ) {
204
- result = Short .valueOf (strValue );
205
- } else if (targetType == Long .class ) {
206
- result = Long .valueOf (strValue );
207
- } else if (targetType == Float .class ) {
208
- result = Float .valueOf (strValue );
209
- } else if (targetType == Double .class ) {
210
- result = Double .valueOf (strValue );
211
- } else if (targetType == Character .class ) {
212
- result = convertToCharacter (strValue );
213
- } else if (targetType == char [].class ) {
214
- result = convertToCharArray (strValue );
215
- } else if (Object [].class .isAssignableFrom (targetType )) {
216
- result = convertToObjectArray (value , strValue , delimiter );
217
- } else if (List .class .isAssignableFrom (targetType )) {
218
- result = convertToList (value , strValue , delimiter );
219
- } else if (Properties .class .isAssignableFrom (targetType )) {
220
- result = convertToProperties (value , delimiter );
221
- } else if (PyOrderedDict .class .isAssignableFrom (targetType )) {
222
- result = convertToDictionary (value , delimiter , true );
223
- } else if (PyDictionary .class .isAssignableFrom (targetType )) {
224
- result = convertToDictionary (value , delimiter , false );
225
- } else if (Map .class .isAssignableFrom (targetType )) {
226
- result = convertToMap (value , strValue , delimiter );
227
- } else {
228
- AliasException ae = new AliasException ("WLSDPLY-08502" , strValue , targetType .getName ());
198
+ try {
199
+ if (targetType == String .class ) {
200
+ result = strValue ;
201
+ } else if (targetType == Boolean .class ) {
202
+ result = convertToBoolean (strValue );
203
+ } else if (targetType == Integer .class ) {
204
+ result = Integer .valueOf (strValue );
205
+ } else if (targetType == Short .class ) {
206
+ result = Short .valueOf (strValue );
207
+ } else if (targetType == Long .class ) {
208
+ result = Long .valueOf (strValue );
209
+ } else if (targetType == Float .class ) {
210
+ result = Float .valueOf (strValue );
211
+ } else if (targetType == Double .class ) {
212
+ result = Double .valueOf (strValue );
213
+ } else if (targetType == Character .class ) {
214
+ result = convertToCharacter (strValue );
215
+ } else if (targetType == char [].class ) {
216
+ result = convertToCharArray (strValue );
217
+ } else if (Object [].class .isAssignableFrom (targetType )) {
218
+ result = convertToObjectArray (value , strValue , delimiter );
219
+ } else if (List .class .isAssignableFrom (targetType )) {
220
+ result = convertToList (value , strValue , delimiter );
221
+ } else if (Properties .class .isAssignableFrom (targetType )) {
222
+ result = convertToProperties (value , delimiter );
223
+ } else if (PyOrderedDict .class .isAssignableFrom (targetType )) {
224
+ result = convertToDictionary (value , delimiter , true );
225
+ } else if (PyDictionary .class .isAssignableFrom (targetType )) {
226
+ result = convertToDictionary (value , delimiter , false );
227
+ } else if (Map .class .isAssignableFrom (targetType )) {
228
+ result = convertToMap (value , strValue , delimiter );
229
+ } else {
230
+ AliasException ae = new AliasException ("WLSDPLY-08502" , strValue , targetType .getName ());
231
+ LOGGER .throwing (CLASS , METHOD , ae );
232
+ throw ae ;
233
+ }
234
+ } catch (NumberFormatException nfe ) {
235
+ AliasException ae = new AliasException ("WLSDPLY-08508" , strValue , targetType .getSimpleName (), nfe );
229
236
LOGGER .throwing (CLASS , METHOD , ae );
230
237
throw ae ;
231
238
}
0 commit comments