Copilot commented on code in PR #10710:
URL: https://github.com/apache/ozone/pull/10710#discussion_r3557312242


##########
hadoop-ozone/httpfsgateway/src/main/java/org/apache/ozone/lib/service/instrumentation/InstrumentationService.java:
##########
@@ -362,23 +338,13 @@ void sample() {
           ((full) ? values.length : ((last == 0) ? 1 : last));
     }
 
-    @SuppressWarnings("unchecked")
-    private JSONObject getJSON() {
-      JSONObject json = new JSONObject();
+    @JsonValue
+    Map<String, Object> getJSON() {
+      Map<String, Object> json = new LinkedHashMap<>();
       json.put("sampler", getRate());
       json.put("size", (full) ? values.length : last);
       return json;
     }

Review Comment:
   Sampler#getJSON can throw a NullPointerException if the sampler is 
serialized before init() runs (sum/values are null until initialized, but the 
instance is inserted into the samplers map first). Add an uninitialized-state 
guard so snapshot serialization cannot fail due to this race.



##########
hadoop-ozone/httpfsgateway/src/main/java/org/apache/ozone/lib/service/instrumentation/InstrumentationService.java:
##########
@@ -308,23 +294,13 @@ static class VariableHolder<E> implements JSONAware, 
JSONStreamAware {
       this.var = var;
     }
 
-    @SuppressWarnings("unchecked")
-    private JSONObject getJSON() {
-      JSONObject json = new JSONObject();
+    @JsonValue
+    Map<String, Object> getJSON() {
+      Map<String, Object> json = new LinkedHashMap<>();
       json.put("value", var.getValue());
       return json;
     }

Review Comment:
   VariableHolder#getJSON can throw a NullPointerException if the holder is 
serialized before addVariable assigns var (there is a publish-before-initialize 
window similar to Timer). Returning a null value avoids failing the entire 
snapshot serialization under concurrent load.



##########
hadoop-ozone/httpfsgateway/src/main/java/org/apache/ozone/lib/service/instrumentation/InstrumentationService.java:
##########
@@ -251,27 +247,17 @@ void addCron(Cron cron) {
       }
     }
 
-    @SuppressWarnings("unchecked")
-    private JSONObject getJSON() {
+    @JsonValue
+    Map<String, Object> getJSON() {
       long[] values = getValues();
-      JSONObject json = new JSONObject();
+      Map<String, Object> json = new LinkedHashMap<>();
       json.put("lastTotal", values[0]);

Review Comment:
   Timer#getJSON currently calls getValues(), which can throw 
(ArrayIndexOutOfBoundsException and/or divide-by-zero) if the Timer is visible 
in the timers map before the first cron is added (last == -1). That 
publish-before-initialize window can happen between getToAdd() inserting a new 
Timer and addCron() updating it, and would break getSnapshot() serialization 
under concurrent load. Add an empty-state guard in getJSON so serialization 
cannot fail.



##########
hadoop-ozone/httpfsgateway/src/main/java/org/apache/ozone/fs/http/server/FSOperations.java:
##########
@@ -374,17 +373,16 @@ private static Map<String, Object> 
quotaUsageToMap(QuotaUsage quotaUsage) {
    *
    * @return the JSON representation of the key-value pair.
    */
-  @SuppressWarnings("unchecked")
-  private static JSONObject toJSON(String name, Object value) {
-    JSONObject json = new JSONObject();
+  private static Map<String, Object> toJSON(String name, Object value) {

Review Comment:
   The toJSON() Javadoc still references json-simple's "JsonAware" and contains 
a duplicated "with". After switching these helpers to Map-based Jackson 
serialization, this comment is now inaccurate/misleading and should be updated.



-- 
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]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to