[libbluray-devel] Fix Java 8 build break with getFileSystem()

Zach Rait git at videolan.org
Sun Mar 1 13:28:04 CET 2015


libbluray | branch: master | Zach Rait <zachrait at gmail.com> | Sun Mar  1 14:11:14 2015 +0200| [490af8f1d913d34d779b6c2ad4c5130d4f435882] | committer: hpi1

Fix Java 8 build break with getFileSystem()

> http://git.videolan.org/gitweb.cgi/libbluray.git/?a=commit;h=490af8f1d913d34d779b6c2ad4c5130d4f435882
---

 src/libbluray/bdj/java/java/io/BDFileSystem.java |   23 ++++++++++++++++++++--
 1 file changed, 21 insertions(+), 2 deletions(-)

diff --git a/src/libbluray/bdj/java/java/io/BDFileSystem.java b/src/libbluray/bdj/java/java/io/BDFileSystem.java
index 687a228..276d38c 100644
--- a/src/libbluray/bdj/java/java/io/BDFileSystem.java
+++ b/src/libbluray/bdj/java/java/io/BDFileSystem.java
@@ -44,6 +44,25 @@ public abstract class BDFileSystem extends FileSystem {
 
     protected final FileSystem fs;
 
+    private static FileSystem nativeFileSystem;
+
+    static {
+        /* Java 8: getFileSystem() no longer exists on java.io.FileSystem */
+        try {
+            nativeFileSystem = (FileSystem)Class.forName("java.io.DefaultFileSystem")
+                .getDeclaredMethod("getFileSystem", new Class[0])
+                .invoke(null, new Object[0]);
+        } catch (Exception e) {
+            try {
+                nativeFileSystem = (FileSystem)FileSystem.class
+                    .getDeclaredMethod("getFileSystem",new Class[0])
+                    .invoke(null, new Object[0]);
+            } catch (Exception t) {
+                System.err.print("Couldn't find native filesystem: " + t);
+            }
+        }
+    }
+
     public static void init(final Class c) {
         AccessController.doPrivileged(
             new PrivilegedAction() {
@@ -77,11 +96,11 @@ public abstract class BDFileSystem extends FileSystem {
     }
 
     public static String[] nativeList(File f) {
-        return getFileSystem().list(f);
+        return nativeFileSystem.list(f);
     }
 
     public static boolean nativeFileExists(String path) {
-        return getFileSystem().getBooleanAttributes(new File(path)) != 0;
+        return nativeFileSystem.getBooleanAttributes(new File(path)) != 0;
     }
 
     /*



More information about the libbluray-devel mailing list