[libbluray-devel] [PATCH] Fix Java 8 build break with getFileSystem()
Petri Hintukainen
phintuka at users.sourceforge.net
Fri Feb 27 08:21:50 CET 2015
On ti, 2015-02-24 at 23:09 -0800, Zach Rait wrote:
> I'm not sure how to propose a patch as I don't see any recent examples, but I've included
> what I'd like to push below. Please let me know what the best way to contribute to this
> project is—I didn't see any guidelines at http://www.videolan.org/developers/libbluray.html,
> but I may have missed something obvious.
Posting patches to this list is fine.
>
> [PATCH] Fix Java 8 build break with getFileSystem()
>
>
>
> Unfortunately java.io.FileSystem.getFileSystem() was removed in Java 8,
> so the addition of calls to it in 7fc6531ea0 broke compilation under Java 8
> ---
> src/libbluray/bdj/java/java/io/BDFileSystem.java | 21 ++++++++++++++++++---
> 1 file changed, 18 insertions(+), 3 deletions(-)
>
>
> diff --git a/src/libbluray/bdj/java/java/io/BDFileSystem.java b/src/libbluray/bdj/java/java/io/BDFileSystem.java
> index 9800022..a6892a5 100644
> --- a/src/libbluray/bdj/java/java/io/BDFileSystem.java
> +++ b/src/libbluray/bdj/java/java/io/BDFileSystem.java
> @@ -42,6 +42,8 @@ public abstract class BDFileSystem extends FileSystem {
>
>
> protected final FileSystem fs;
>
>
> + private static FileSystem nativeFileSystem;
> +
> public static void init(Class c) {
> Field filesystem;
> try {
> @@ -62,18 +64,31 @@ public abstract class BDFileSystem extends FileSystem {
> } catch (Throwable t) {
> System.err.print("Hooking FileSystem class failed: " + t);
> }
> + /* Java 8: getFileSystem() no longer exists on java.io.FileSystem */
> + try {
> + Class.forName("java.io.DefaultFileSystem");
> + nativeFileSystem = DefaultFileSystem.getFileSystem();
This will not compile with older Java (DefaultFileSystem does not
exist). You need to use reflection also here.
> + } catch (ClassNotFoundException e) {
> + try {
> + nativeFileSystem = (FileSystem)FileSystem.class
> + .getDeclaredMethod("getFileSystem",new Class[0])
> + .invoke(FileSystem.class, new Object[0]);
> + } catch (Throwable t) {
> + System.err.print("Couldn't find native filesystem: " + t);
> + }
> + }
> }
>
Following functions are called before any Xlet is loaded (and init()
called). nativeFileSystem field should be initialized in static {}
block.
> 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;
> }
>
>
> public static boolean nativeDelete(File f) {
> - return getFileSystem().delete(f);
> + return nativeFileSystem.delete(f);
> }
>
> /*
> --
> _______________________________________________
> libbluray-devel mailing list
> libbluray-devel at videolan.org
> https://mailman.videolan.org/listinfo/libbluray-devel
More information about the libbluray-devel
mailing list