United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-7133476 (fs) Files.readAttributes throws NPE on MacOSX
JDK-7133476 : (fs) Files.readAttributes throws NPE on MacOSX

Details
Type:
Bug
Submit Date:
2012-01-26
Status:
Closed
Updated Date:
2012-03-27
Project Name:
JDK
Resolved Date:
2012-03-27
Component:
core-libs
OS:
os_x
Sub-Component:
java.nio
CPU:
x86
Priority:
P4
Resolution:
Fixed
Affected Versions:
7u4
Fixed Versions:
7u4 (b11)

Related Reports

Sub Tasks

Description
From http://java.net/jira/browse/MACOSX_PORT-133 --

java.nio.file.Files .readAttributes throws NPE on MacOS

Simple test case:
import java.nio.file.attribute.DosFileAttributes;
import java.nio.ByteBuffer;
import java.nio.channels.SeekableByteChannel;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import static java.nio.file.StandardOpenOption.*;

public class Test {
public static void main(String argv[]) {
Path path = Paths.get("temp.txt");
String data = "Hello world!";
SeekableByteChannel sbc = null;

try { ByteBuffer bb = ByteBuffer.wrap(data.getBytes()); sbc = Files.newByteChannel(path, CREATE, WRITE); sbc.write(bb); DosFileAttributes dfa = null; dfa = Files.readAttributes(path, DosFileAttributes.class); } catch (Exception e) { e.printStackTrace(); }
}

}

Test output:

Exception in thread "main" java.lang.NullPointerException
at sun.nio.fs.BsdFileSystemProvider.readAttributes(BsdFileSystemProvider.java:78)
at java.nio.file.Files.readAttributes(Files.java:1669)
at TestCopy01.test01(TestCopy01.java:85)
at TestCopy01.main(TestCopy01.java:37)

                                    

Comments
EVALUATION

See comments, most of sun.nio.fs.Bsd* should be removed,
                                     
2012-01-26
SUGGESTED FIX

There is no need for BsdFileSystemProvider to override readAttributes. In addition, most of sun.nio.fs.Bsd* can be removed - is is just not needed.


diff --git a/src/solaris/classes/sun/nio/fs/BsdFileStore.java b/src/solaris/classes/sun/nio/fs/BsdFileStore.java
--- a/src/solaris/classes/sun/nio/fs/BsdFileStore.java
+++ b/src/solaris/classes/sun/nio/fs/BsdFileStore.java
@@ -85,76 +85,4 @@
 
         throw new IOException("Mount point not found in fstab");
     }
-
-    // returns true if extended attributes enabled on file system where given
-    // file resides, returns false if disabled or unable to determine.
-    private boolean isExtendedAttributesEnabled(UnixPath path) {
-/*
-        try {
-            int fd = path.openForAttributeAccess(false);
-            try {
-                // fgetxattr returns size if called with size==0
-                BsdNativeDispatcher.fgetxattr(fd, "user.java".getBytes(), 0L, 0);
-                return true;
-            } catch (UnixException e) {
-                // attribute does not exist
-                if (e.errno() == UnixConstants.ENODATA)
-                    return true;
-            } finally {
-                UnixNativeDispatcher.close(fd);
-            }
-        } catch (IOException ignore) {
-            // nothing we can do
-        }
-*/
-        return false;
-    }
-
-    @Override
-    public boolean supportsFileAttributeView(Class<? extends FileAttributeView> type) {
-/*
-        // support DosFileAttributeView and UserDefinedAttributeView if extended
-        // attributes enabled
-        if (type == DosFileAttributeView.class ||
-            type == UserDefinedFileAttributeView.class)
-        {
-            // lookup fstypes.properties
-            FeatureStatus status = checkIfFeaturePresent("user_xattr");
-            if (status == FeatureStatus.PRESENT)
-                return true;
-            if (status == FeatureStatus.NOT_PRESENT)
-                return false;
-
-            // if file system is mounted with user_xattr option then assume
-            // extended attributes are enabled
-            if ((entry().hasOption("user_xattr")))
-                return true;
-
-            // user_xattr option not present but we special-case ext3/4 as we
-            // know that extended attributes are not enabled by default.
-            if (entry().fstype().equals("ext3") || entry().fstype().equals("ext4"))
-                return false;
-
-            // not ext3/4 so probe mount point
-            if (!xattrChecked) {
-                UnixPath dir = new UnixPath(file().getFileSystem(), entry().dir());
-                xattrEnabled = isExtendedAttributesEnabled(dir);
-                xattrChecked = true;
-            }
-            return xattrEnabled;
-        }
-*/
-        return super.supportsFileAttributeView(type);
-    }
-
-    @Override
-    public boolean supportsFileAttributeView(String name) {
-/*
-        if (name.equals("dos"))
-            return supportsFileAttributeView(DosFileAttributeView.class);
-        if (name.equals("user"))
-            return supportsFileAttributeView(UserDefinedFileAttributeView.class);
-*/
-        return super.supportsFileAttributeView(name);
-    }
 }
diff --git a/src/solaris/classes/sun/nio/fs/BsdFileSystemProvider.java b/src/solaris/classes/sun/nio/fs/BsdFileSystemProvider.java
--- a/src/solaris/classes/sun/nio/fs/BsdFileSystemProvider.java
+++ b/src/solaris/classes/sun/nio/fs/BsdFileSystemProvider.java
@@ -47,37 +47,4 @@
     BsdFileStore getFileStore(UnixPath path) throws IOException {
         return new BsdFileStore(path);
     }
-
-    @Override
-    @SuppressWarnings("unchecked")
-    public <V extends FileAttributeView> V getFileAttributeView(Path obj,
-                                                                Class<V> type,
-                                                                LinkOption... options)
-    {
-        return super.getFileAttributeView(obj, type, options);
-    }
-
-    @Override
-    public DynamicFileAttributeView getFileAttributeView(Path obj,
-                                                         String name,
-                                                         LinkOption... options)
-    {
-        return super.getFileAttributeView(obj, name, options);
-    }
-
-    @Override
-    @SuppressWarnings("unchecked")
-    public <A extends BasicFileAttributes> A readAttributes(Path file,
-                                                            Class<A> type,
-                                                            LinkOption... options)
-        throws IOException
-    {
-        if (type == DosFileAttributes.class) {
-            DosFileAttributeView view =
-                getFileAttributeView(file, DosFileAttributeView.class, options);
-            return (A) view.readAttributes();
-        } else {
-            return super.readAttributes(file, type, options);
-        }
-    }
 }
                                     
2012-01-26



Hardware and Software, Engineered to Work Together