Description
When we create/update a policy by addion validity period to it, then it fails with the below error.
java.lang.UnsupportedOperationException: null at java.util.AbstractMap.put(AbstractMap.java:209) at org.apache.ranger.service.RangerPolicyServiceBase.mapViewToEntityBean(RangerPolicyServiceBase.java:217) at org.apache.ranger.service.RangerPolicyService.mapViewToEntityBean(RangerPolicyService.java:37) at org.apache.ranger.service.RangerPolicyService.mapViewToEntityBean(RangerPolicyService.java:27) at org.apache.ranger.service.RangerBaseModelService.populateEntityBeanForUpdate(RangerBaseModelService.java:192) at org.apache.ranger.service.RangerBaseModelService.preUpdate(RangerBaseModelService.java:270) at org.apache.ranger.service.RangerBaseModelService.update(RangerBaseModelService.java:252) at org.apache.ranger.biz.ServiceDBStore.updatePolicy(ServiceDBStore.java:2300) at org.apache.ranger.rest.ServiceREST.updatePolicy(ServiceREST.java:1854) at org.apache.ranger.rest.ServiceREST$$FastClassBySpringCGLIB$$92dab672.invoke(<generated>) at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218)
The root cause of this issue is because we have defined options object of RangerPolicy as immutable using nullSafeMap (default as NullSafeSupplierV2) which uses Collections.emptyMap to initialise options if its null or empty.
But when validity period is being added to a policy then this options map is being modified in RangerPolicyServiceBase -> mapViewToEntityBean() as below.
Map<String, Object> options = vObj.getOptions(); if (options == null) { options = new HashMap<>(); } if (StringUtils.isNotBlank(validitySchedules)) { options.put(OPTION_POLICY_VALIDITY_SCHEDULES, validitySchedules); } else { options.remove(OPTION_POLICY_VALIDITY_SCHEDULES); }
To fix this we would need to intitialise options object in RangerPolicy with a modifiable map by using getUpdatableMap of RangerBaseModelObject.
Attachments
Issue Links
- is caused by
-
RANGER-4787 reduce plugin memory footprint by avoiding creation of unnecessary collections
- Resolved