@@ -178,7 +178,13 @@ private static void setAddOnFeatures(String addOnName, Map<String, Object> addOn
178178
179179 for (String addOnFeatureName : addOnFeaturesMap .keySet ()) {
180180
181- Map <String , Object > addOnFeatureMap = (Map <String , Object >) addOnFeaturesMap .get (addOnFeatureName );
181+ Object featureObj = addOnFeaturesMap .get (addOnFeatureName );
182+ if (!(featureObj instanceof Map )) {
183+ throw new PricingParsingException ("The feature " + addOnFeatureName
184+ + " of the add-on " + addOnName + " is not a valid map. Maybe 'value' attribute is missing to set the value of the feature" );
185+ }
186+ @ SuppressWarnings ("unchecked" )
187+ Map <String , Object > addOnFeatureMap = (Map <String , Object >) featureObj ;
182188
183189 if (!globalFeaturesMap .containsKey (addOnFeatureName )) {
184190 throw new FeatureNotFoundException (
@@ -232,9 +238,23 @@ private static void setAddOnUsageLimits(String addOnName, Map<String, Object> ad
232238 Map <String , Object > addOnUsageLimitsMap = null ;
233239
234240 if (areExtensions ) {
235- addOnUsageLimitsMap = (Map <String , Object >) addOnMap .get ("usageLimitsExtensions" );
241+ Object usageLimitsExtensionsObj = addOnMap .get ("usageLimitsExtensions" );
242+ if (usageLimitsExtensionsObj instanceof Map <?, ?>) {
243+ addOnUsageLimitsMap = (Map <String , Object >) usageLimitsExtensionsObj ;
244+ } else if (usageLimitsExtensionsObj != null ) {
245+ throw new PricingParsingException ("The field \" usageLimitsExtensions\" should be a map. It is currently: "
246+ + usageLimitsExtensionsObj .getClass ().getSimpleName () + ". "
247+ + "Maybe you forgot to add the 'value' attribute to the usage limit in the add-on definition." );
248+ }
236249 } else {
237- addOnUsageLimitsMap = (Map <String , Object >) addOnMap .get ("usageLimits" );
250+ Object usageLimitsObj = addOnMap .get ("usageLimits" );
251+ if (usageLimitsObj instanceof Map <?, ?>) {
252+ addOnUsageLimitsMap = (Map <String , Object >) usageLimitsObj ;
253+ } else if (usageLimitsObj != null ) {
254+ throw new PricingParsingException ("The field \" usageLimits\" should be a map. It is currently: "
255+ + usageLimitsObj .getClass ().getSimpleName () + ". "
256+ + "Maybe you forgot to add the 'value' attribute to the usage limit in the add-on definition." );
257+ }
238258 }
239259 Map <String , UsageLimit > globalUsageLimitsMap = pricingManager .getUsageLimits ();
240260 Map <String , UsageLimit > addOnUsageLimits = new LinkedHashMap <>();
0 commit comments