pwoody commented on a change in pull request #8194:
URL: https://github.com/apache/arrow/pull/8194#discussion_r489968112



##########
File path: 
java/memory/memory-core/src/test/java/org/apache/arrow/memory/util/TestLargeMemoryUtil.java
##########
@@ -0,0 +1,108 @@
+/*
+ * 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.arrow.memory.util;
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.net.URLClassLoader;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.jupiter.api.Assertions;
+
+public class TestLargeMemoryUtil {
+
+  /**
+   * Get a copy of the current class loader.
+   * @return the newly created class loader.
+   */
+  private ClassLoader copyClassLoader() {
+    ClassLoader curClassLoader = this.getClass().getClassLoader();
+    if (curClassLoader instanceof URLClassLoader) {
+      // for Java 1.8
+      return new URLClassLoader(((URLClassLoader) curClassLoader).getURLs(), 
null);
+    }
+
+    // for Java 1.9 and Java 11.
+    return null;
+  }
+
+  /**
+   * Use the checkedCastToInt method from the current classloader.
+   * @param classLoader the class loader from which to call the method.
+   * @return the return value of the method.
+   */
+  private int checkedCastToInt(ClassLoader classLoader, long value) throws 
Exception {
+    Class<?> clazz = 
classLoader.loadClass("org.apache.arrow.memory.util.LargeMemoryUtil");
+    Method method = clazz.getMethod("checkedCastToInt", long.class);
+    return (int) method.invoke(null, value);
+  }
+
+  private void checkExpectedOverflow(ClassLoader classLoader, long value) 
throws Exception {
+    try {
+      checkedCastToInt(classLoader, value);
+      Assert.fail();
+    } catch (InvocationTargetException e) {
+      Assertions.assertThrows(ArithmeticException.class, () -> {

Review comment:
       Could you clarify what you mean? Is it the static import or the fact 
that I need to catch the InvocationTargetException before rethrowing to get the 
actual exception?
   
   The latter is a side effect of having to jump through hoops to get the 
static variable set - if there is a better way then let me know.




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

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


Reply via email to