You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hudi.apache.org by GitBox <gi...@apache.org> on 2022/09/22 15:40:46 UTC

[GitHub] [hudi] alexeykudinkin commented on a diff in pull request #6657: [HUDI-4687] Avoid setAccessible which breaks strong encapsulation

alexeykudinkin commented on code in PR #6657:
URL: https://github.com/apache/hudi/pull/6657#discussion_r971328667


##########
hudi-common/src/main/java/org/apache/hudi/common/util/ObjectSizeCalculator.java:
##########
@@ -127,23 +129,29 @@ public synchronized long calculateObjectSize(Object obj) {
         }
         obj = pending.removeFirst();
       }
+    } catch (IllegalAccessException | SecurityException e) {

Review Comment:
   Let's add a comment elaborating on fallback (basically what you've put up in a description here)



##########
hudi-common/src/main/java/org/apache/hudi/common/util/ObjectSizeCalculator.java:
##########
@@ -232,7 +240,7 @@ private class ClassSizeInfo {
     private final long fieldsSize;
     private final Field[] referenceFields;
 
-    public ClassSizeInfo(Class<?> clazz) {
+    public ClassSizeInfo(Class<?> clazz, int referenceSize, int superclassFieldPadding, int objectHeaderSize, int objectPadding) {

Review Comment:
   Where are these new fields used? I see them passed t/h, but don't see them being actually used anywhere



##########
hudi-common/src/test/java/org/apache/hudi/common/util/TestObjectSizeCalculator.java:
##########
@@ -0,0 +1,95 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.hudi.common.util;
+
+import org.apache.hudi.common.model.HoodieRecord;
+
+import org.apache.avro.Schema;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.List;
+
+public class TestObjectSizeCalculator {
+
+  @Test
+  public void testGetObjectSize() {
+    EmptyClass emptyClass = new EmptyClass();
+    StringClass stringClass = new StringClass();
+    PayloadClass payloadClass = new PayloadClass();
+    String emptyString = "";
+    String string = "hello";
+    String[] stringArray = {emptyString, string, " world"};
+    String[] anotherStringArray = new String[100];
+    List<String> stringList = new ArrayList<>();
+    StringBuilder stringBuilder = new StringBuilder(100);
+    int maxIntPrimitive = Integer.MAX_VALUE;
+    int minIntPrimitive = Integer.MIN_VALUE;
+    Integer maxInteger = Integer.MAX_VALUE;
+    Integer minInteger = Integer.MIN_VALUE;
+    long zeroLong = 0L;
+    double zeroDouble = 0.0;
+    boolean booleanField = true;
+    Object object = new Object();
+
+    Assertions.assertDoesNotThrow(() -> {
+      printObjectSize(emptyString);

Review Comment:
   Let's actually assert objects' sizes instead



-- 
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: commits-unsubscribe@hudi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org