This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-io.git


The following commit(s) were added to refs/heads/master by this push:
     new 2f1e354  [IO-510] Add and adapt ReadAheadInputStream and 
BufferedFileChannelInputStream from Apache Spark.
2f1e354 is described below

commit 2f1e3544a8f85de762f9750235f70b90e41445da
Author: Gary Gregory <gardgreg...@gmail.com>
AuthorDate: Thu Oct 29 20:37:02 2020 -0400

    [IO-510] Add and adapt ReadAheadInputStream and
    BufferedFileChannelInputStream from Apache Spark.
    
    Compiles on Java 8 and 11.
---
 .../commons/io/input/BufferedFileChannelInputStream.java    | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git 
a/src/main/java/org/apache/commons/io/input/BufferedFileChannelInputStream.java 
b/src/main/java/org/apache/commons/io/input/BufferedFileChannelInputStream.java
index c0c013c..8825a51 100644
--- 
a/src/main/java/org/apache/commons/io/input/BufferedFileChannelInputStream.java
+++ 
b/src/main/java/org/apache/commons/io/input/BufferedFileChannelInputStream.java
@@ -130,10 +130,11 @@ public final class BufferedFileChannelInputStream extends 
InputStream {
         if ("1.8".equals(specVer)) {
             // On Java 8, but also compiles on Java 11.
             try {
-              final Class<?> cls = Class.forName("sun.misc.Cleaner");
-              final Object cleaner = buffer.cleaner();
+              final Class<?> clsCleaner = Class.forName("sun.misc.Cleaner");
+              final Method cleanerMethod = 
DirectBuffer.class.getMethod("cleaner");
+              final Object cleaner = cleanerMethod.invoke(buffer);
               if (cleaner != null) {
-                  final Method cleanMethod = cls.getMethod("clean");
+                  final Method cleanMethod = clsCleaner.getMethod("clean");
                   cleanMethod.invoke(cleaner);
               }
             } catch (ReflectiveOperationException e) {
@@ -142,9 +143,9 @@ public final class BufferedFileChannelInputStream extends 
InputStream {
         } else {
             // On Java 9 and up, but compiles on Java 8.
             try {
-                final Class<?> cls = Class.forName("sun.misc.Unsafe");
-                final Method cleanerMethod = cls.getMethod("invokeCleaner", 
ByteBuffer.class);
-                final Field unsafeField = cls.getDeclaredField("theUnsafe");
+                final Class<?> clsUnsafe = Class.forName("sun.misc.Unsafe");
+                final Method cleanerMethod = 
clsUnsafe.getMethod("invokeCleaner", ByteBuffer.class);
+                final Field unsafeField = 
clsUnsafe.getDeclaredField("theUnsafe");
                 unsafeField.setAccessible(true);
                 cleanerMethod.invoke(unsafeField.get(null), buffer);
             } catch (ReflectiveOperationException e) {

Reply via email to