You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2022/05/20 16:50:48 UTC

[GitHub] [arrow] davisusanibar commented on a diff in pull request #13200: ARROW-16537: [Java] Patch dataset module testing failure with JSE11+

davisusanibar commented on code in PR #13200:
URL: https://github.com/apache/arrow/pull/13200#discussion_r878351528


##########
java/dataset/src/main/java/org/apache/arrow/dataset/jni/DirectReservationListener.java:
##########
@@ -87,11 +87,47 @@ public void unreserve(long size) {
   public long getCurrentDirectMemReservation() {
     try {
       final Class<?> classBits = Class.forName("java.nio.Bits");
-      final Field f = classBits.getDeclaredField("reservedMemory");
+      final Field f = this.getDeclaredFieldBaseOnJDKVersion(classBits, "reservedMemory");
       f.setAccessible(true);
       return ((AtomicLong) f.get(null)).get();
     } catch (Exception e) {
       throw new RuntimeException(e);
     }
   }
+
+  /**
+   * To evaluate method on a class base on JDK version.
+   * @param classBits Object associated with the class with the given string name
+   * @param name Method needed to evaluate
+   * @return
+   */
+  private Method getDeclaredMethodBaseOnJDKVersion(Class<?> classBits, String name) {
+    try {
+      return classBits.getDeclaredMethod(name, long.class, int.class);
+    } catch (NoSuchMethodException e) {
+      try {
+        return classBits.getDeclaredMethod(name, long.class, long.class);
+      } catch (NoSuchMethodException ex) {
+        throw new AssertionError(ex);
+      }
+    }
+  }
+
+  /**
+   * To evaluate field on a class base on JDK version.
+   * @param classBits Object associated with the class with the given string name
+   * @param name Field needed to evaluate
+   * @return
+   */
+  private Field getDeclaredFieldBaseOnJDKVersion(Class<?> classBits, String name) {

Review Comment:
   Deleted



##########
java/dataset/src/main/java/org/apache/arrow/dataset/jni/DirectReservationListener.java:
##########
@@ -87,11 +87,40 @@ public void unreserve(long size) {
   public long getCurrentDirectMemReservation() {
     try {
       final Class<?> classBits = Class.forName("java.nio.Bits");
-      final Field f = classBits.getDeclaredField("reservedMemory");
+      final Field f;
+      Field fBaseOnJDKVersion;

Review Comment:
   Changed



-- 
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: github-unsubscribe@arrow.apache.org

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