2525
2626package sun .nio .fs ;
2727
28- import java .nio .file .attribute .* ;
29- import java .util .* ;
28+ import java .nio .file .attribute .FileAttributeView ;
29+ import java .nio . file . attribute . UserDefinedFileAttributeView ;
3030import java .io .IOException ;
31+ import java .util .Arrays ;
32+ import sun .security .action .GetPropertyAction ;
3133
3234/**
3335 * Bsd implementation of FileStore
@@ -111,9 +113,12 @@ public boolean supportsFileAttributeView(Class<? extends FileAttributeView> type
111113 return false ;
112114
113115 // typical macOS file system types that are known to support xattr
114- if ( entry ().fstype (). equals ( "apfs" )
115- || entry (). fstype (). equals ( "hfs" )) {
116+ String fstype = entry ().fstype ();
117+ if ( "hfs" . equals ( fstype ))
116118 return true ;
119+ if ("apfs" .equals (fstype )) {
120+ // fgetxattr broken on APFS prior to 10.14
121+ return isOsVersionGte (10 , 14 );
117122 }
118123
119124 // probe file system capabilities
@@ -129,4 +134,17 @@ public boolean supportsFileAttributeView(String name) {
129134 return supportsFileAttributeView (UserDefinedFileAttributeView .class );
130135 return super .supportsFileAttributeView (name );
131136 }
137+
138+ /**
139+ * Returns true if the OS major/minor version is greater than, or equal, to the
140+ * given major/minor version.
141+ */
142+ private static boolean isOsVersionGte (int requiredMajor , int requiredMinor ) {
143+ String osVersion = GetPropertyAction .privilegedGetProperty ("os.version" );
144+ String [] vers = Util .split (osVersion , '.' );
145+ int majorVersion = Integer .parseInt (vers [0 ]);
146+ int minorVersion = Integer .parseInt (vers [1 ]);
147+ return (majorVersion > requiredMajor )
148+ || (majorVersion == requiredMajor && minorVersion >= requiredMinor );
149+ }
132150}
0 commit comments