[libbluray-devel] [PATCH] Fix Java 8 build break with getFileSystem()
Zach Rait
zachrait at gmail.com
Sat Feb 28 09:54:44 CET 2015
Got it, thanks.
diff --git a/src/libbluray/bdj/java/java/io/BDFileSystem.java
b/src/libbluray/bdj/java/java/io/BDFileSystem.java
index 687a228..7dcbeaf 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 (ReflectiveOperationException e) {
+ try {
+ nativeFileSystem = (FileSystem)FileSystem.class
+ .getDeclaredMethod("getFileSystem",new Class[0])
+ .invoke(null, new Object[0]);
+ } catch (ReflectiveOperationException 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;
}
/*
--
On Thu, Feb 26, 2015 at 11:21 PM, Petri Hintukainen <
phintuka at users.sourceforge.net> wrote:
> 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
>
>
>
>
> _______________________________________________
> libbluray-devel mailing list
> libbluray-devel at videolan.org
> https://mailman.videolan.org/listinfo/libbluray-devel
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.videolan.org/pipermail/libbluray-devel/attachments/20150228/dffa76d2/attachment.html>
More information about the libbluray-devel
mailing list