Copilot commented on code in PR #799:
URL: https://github.com/apache/ranger/pull/799#discussion_r2681144821


##########
security-admin/src/main/java/org/apache/ranger/db/XXGlobalStateDao.java:
##########
@@ -167,20 +167,20 @@ private void createGlobalStateForAppDataVersion(String 
stateName) {
 
         appDataVersion.put(APP_DATA_ENTRY_VERSION, Long.toString(1L));
 
-        globalState.setAppData(new Gson().toJson(appDataVersion));
+        globalState.setAppData(JsonUtils.mapToJson(appDataVersion));
 
         create(globalState);
     }
 
     private void updateGlobalStateForAppDataVersion(XXGlobalState globalState, 
String stateName) {
-        Map<String, String> appDataVersionJson = new 
Gson().fromJson(globalState.getAppData(), Map.class);
+        Map<String, String> appDataVersionJson = 
JsonUtils.jsonToMapStringString(globalState.getAppData());
 
         if (MapUtils.isNotEmpty(appDataVersionJson)) {
-            Long appDataVersion = 
Long.valueOf(appDataVersionJson.get(APP_DATA_ENTRY_VERSION)) + 1L;
+            long appDataVersion = 
Long.parseLong(appDataVersionJson.get(APP_DATA_ENTRY_VERSION)) + 1L;

Review Comment:
   Missing null check for the map value before parsing. If 
`APP_DATA_ENTRY_VERSION` key is missing or its value is null, 
`Long.parseLong()` will throw a `NullPointerException`. Consider adding 
validation or using `MapUtils.getString()` with a default value.
   ```suggestion
               String appDataVersionStr = 
MapUtils.getString(appDataVersionJson, APP_DATA_ENTRY_VERSION, "0");
               long appDataVersion = Long.parseLong(appDataVersionStr) + 1L;
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to