11/*
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.
33 * Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
44 */
55package oracle .weblogic .deploy .aliases ;
66
77import java .io .File ;
88import java .lang .reflect .Array ;
9+ import java .lang .NumberFormatException ;
910import java .util .ArrayList ;
1011import java .util .Arrays ;
1112import java .util .HashMap ;
@@ -168,7 +169,7 @@ public static Object convertToType(Class<?> targetType, Object value) throws Ali
168169 * or the requested data type is not supported.
169170 * @throws AliasException if classType is a primitive class type such as int, short, etc. or if a multi-valued
170171 * 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.
172173 */
173174 public static Object convertToType (Class <?> targetType , Object value , String delimiter ) throws AliasException {
174175 final String METHOD = "convertToType" ;
@@ -194,38 +195,44 @@ public static Object convertToType(Class<?> targetType, Object value, String del
194195 }
195196
196197 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 );
229236 LOGGER .throwing (CLASS , METHOD , ae );
230237 throw ae ;
231238 }
0 commit comments