samarthjain commented on code in PR #17847:
URL: https://github.com/apache/druid/pull/17847#discussion_r2067110210


##########
server/src/main/java/org/apache/druid/segment/realtime/appenderator/StreamAppenderator.java:
##########
@@ -354,40 +376,43 @@ public AppenderatorAddResult add(
 
     boolean isPersistRequired = false;
     boolean persist = false;
-    List<String> persistReasons = new ArrayList<>();
+    final String[] persistReasons = new String[NUMBER_OF_PERSIST_REASONS];

Review Comment:
   When you don't specify the default capacity, there are additional checks 
performed on the first add(). 
   
   ```
   public ArrayList(int initialCapacity) {
           if (initialCapacity > 0) {
               this.elementData = new Object[initialCapacity];
           } else if (initialCapacity == 0) {
               this.elementData = EMPTY_ELEMENTDATA;
           } else {
               throw new IllegalArgumentException("Illegal Capacity: "+
                                                  initialCapacity);
           }
    }
    
    public boolean add(E e) {
           ensureCapacityInternal(size + 1);  // Increments modCount!!
           elementData[size++] = e;
           return true;
   }
   ```
   Java array list uses arrays under the hood with additional checks for 
capacity. 
   
   The downside of using arrays is that future maintainers will have to resize 
the array when they want to add reasons. If they forget doing that and their 
tests don't exercise the path where new persist reasons are added, then things 
can break in production.  
   



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