7050570: (fs) FileSysteProvider fails to initializes if run with file.encoding set to Cp037
Reviewed-by: sherman, ulfzibis
This commit is contained in:
parent
62105105d7
commit
467adb4a7c
@ -27,6 +27,9 @@ package sun.nio.fs;
|
|||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.nio.file.*;
|
import java.nio.file.*;
|
||||||
|
import java.nio.charset.Charset;
|
||||||
|
import java.security.*;
|
||||||
|
import sun.security.action.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Utility methods
|
* Utility methods
|
||||||
@ -35,6 +38,33 @@ import java.nio.file.*;
|
|||||||
class Util {
|
class Util {
|
||||||
private Util() { }
|
private Util() { }
|
||||||
|
|
||||||
|
private static final Charset jnuEncoding = Charset.forName(
|
||||||
|
AccessController.doPrivileged(new GetPropertyAction("sun.jnu.encoding")));
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns {@code Charset} corresponding to the sun.jnu.encoding property
|
||||||
|
*/
|
||||||
|
static Charset jnuEncoding() {
|
||||||
|
return jnuEncoding;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Encodes the given String into a sequence of bytes using the {@code Charset}
|
||||||
|
* specified by the sun.jnu.encoding property.
|
||||||
|
*/
|
||||||
|
static byte[] toBytes(String s) {
|
||||||
|
return s.getBytes(jnuEncoding);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs a new String by decoding the specified array of bytes using the
|
||||||
|
* {@code Charset} specified by the sun.jnu.encoding property.
|
||||||
|
*/
|
||||||
|
static String toString(byte[] bytes) {
|
||||||
|
return new String(bytes, jnuEncoding);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Splits a string around the given character. The array returned by this
|
* Splits a string around the given character. The array returned by this
|
||||||
* method contains each substring that is terminated by the character. Use
|
* method contains each substring that is terminated by the character. Use
|
||||||
|
@ -70,12 +70,12 @@ public class GnomeFileTypeDetector
|
|||||||
// GIO may access file so need permission check
|
// GIO may access file so need permission check
|
||||||
path.checkRead();
|
path.checkRead();
|
||||||
byte[] type = probeUsingGio(buffer.address());
|
byte[] type = probeUsingGio(buffer.address());
|
||||||
return (type == null) ? null : new String(type);
|
return (type == null) ? null : Util.toString(type);
|
||||||
} else {
|
} else {
|
||||||
byte[] type = probeUsingGnomeVfs(buffer.address());
|
byte[] type = probeUsingGnomeVfs(buffer.address());
|
||||||
if (type == null)
|
if (type == null)
|
||||||
return null;
|
return null;
|
||||||
String s = new String(type);
|
String s = Util.toString(type);
|
||||||
return s.equals(GNOME_VFS_MIME_TYPE_UNKNOWN) ? null : s;
|
return s.equals(GNOME_VFS_MIME_TYPE_UNKNOWN) ? null : s;
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
|
@ -51,7 +51,7 @@ class LinuxDosFileAttributeView
|
|||||||
private static final String HIDDEN_NAME = "hidden";
|
private static final String HIDDEN_NAME = "hidden";
|
||||||
|
|
||||||
private static final String DOS_XATTR_NAME = "user.DOSATTRIB";
|
private static final String DOS_XATTR_NAME = "user.DOSATTRIB";
|
||||||
private static final byte[] DOS_XATTR_NAME_AS_BYTES = DOS_XATTR_NAME.getBytes();
|
private static final byte[] DOS_XATTR_NAME_AS_BYTES = Util.toBytes(DOS_XATTR_NAME);
|
||||||
|
|
||||||
private static final int DOS_XATTR_READONLY = 0x01;
|
private static final int DOS_XATTR_READONLY = 0x01;
|
||||||
private static final int DOS_XATTR_HIDDEN = 0x02;
|
private static final int DOS_XATTR_HIDDEN = 0x02;
|
||||||
@ -225,7 +225,7 @@ class LinuxDosFileAttributeView
|
|||||||
byte[] buf = new byte[len];
|
byte[] buf = new byte[len];
|
||||||
unsafe.copyMemory(null, buffer.address(), buf,
|
unsafe.copyMemory(null, buffer.address(), buf,
|
||||||
Unsafe.ARRAY_BYTE_BASE_OFFSET, len);
|
Unsafe.ARRAY_BYTE_BASE_OFFSET, len);
|
||||||
String value = new String(buf); // platform encoding
|
String value = Util.toString(buf);
|
||||||
|
|
||||||
// should be something like 0x20
|
// should be something like 0x20
|
||||||
if (value.length() >= 3 && value.startsWith("0x")) {
|
if (value.length() >= 3 && value.startsWith("0x")) {
|
||||||
@ -263,7 +263,7 @@ class LinuxDosFileAttributeView
|
|||||||
newValue &= ~flag;
|
newValue &= ~flag;
|
||||||
}
|
}
|
||||||
if (newValue != oldValue) {
|
if (newValue != oldValue) {
|
||||||
byte[] value = ("0x" + Integer.toHexString(newValue)).getBytes();
|
byte[] value = Util.toBytes("0x" + Integer.toHexString(newValue));
|
||||||
NativeBuffer buffer = NativeBuffers.asNativeBuffer(value);
|
NativeBuffer buffer = NativeBuffers.asNativeBuffer(value);
|
||||||
try {
|
try {
|
||||||
LinuxNativeDispatcher.fsetxattr(fd, DOS_XATTR_NAME_AS_BYTES,
|
LinuxNativeDispatcher.fsetxattr(fd, DOS_XATTR_NAME_AS_BYTES,
|
||||||
|
@ -98,7 +98,8 @@ class LinuxFileStore
|
|||||||
int fd = path.openForAttributeAccess(false);
|
int fd = path.openForAttributeAccess(false);
|
||||||
try {
|
try {
|
||||||
// fgetxattr returns size if called with size==0
|
// fgetxattr returns size if called with size==0
|
||||||
LinuxNativeDispatcher.fgetxattr(fd, "user.java".getBytes(), 0L, 0);
|
byte[] name = Util.toBytes("user.java");
|
||||||
|
LinuxNativeDispatcher.fgetxattr(fd, name, 0L, 0);
|
||||||
return true;
|
return true;
|
||||||
} catch (UnixException e) {
|
} catch (UnixException e) {
|
||||||
// attribute does not exist
|
// attribute does not exist
|
||||||
|
@ -78,7 +78,7 @@ class LinuxFileSystem extends UnixFileSystem {
|
|||||||
Iterable<UnixMountEntry> getMountEntries(String fstab) {
|
Iterable<UnixMountEntry> getMountEntries(String fstab) {
|
||||||
ArrayList<UnixMountEntry> entries = new ArrayList<>();
|
ArrayList<UnixMountEntry> entries = new ArrayList<>();
|
||||||
try {
|
try {
|
||||||
long fp = setmntent(fstab.getBytes(), "r".getBytes());
|
long fp = setmntent(Util.toBytes(fstab), Util.toBytes("r"));
|
||||||
try {
|
try {
|
||||||
for (;;) {
|
for (;;) {
|
||||||
UnixMountEntry entry = new UnixMountEntry();
|
UnixMountEntry entry = new UnixMountEntry();
|
||||||
|
@ -53,7 +53,7 @@ class LinuxUserDefinedFileAttributeView
|
|||||||
if (name == null)
|
if (name == null)
|
||||||
throw new NullPointerException("'name' is null");
|
throw new NullPointerException("'name' is null");
|
||||||
name = USER_NAMESPACE + name;
|
name = USER_NAMESPACE + name;
|
||||||
byte[] bytes = name.getBytes();
|
byte[] bytes = Util.toBytes(name);
|
||||||
if (bytes.length > XATTR_NAME_MAX) {
|
if (bytes.length > XATTR_NAME_MAX) {
|
||||||
throw new FileSystemException(file.getPathForExceptionMessage(),
|
throw new FileSystemException(file.getPathForExceptionMessage(),
|
||||||
null, "'" + name + "' is too big");
|
null, "'" + name + "' is too big");
|
||||||
@ -72,7 +72,7 @@ class LinuxUserDefinedFileAttributeView
|
|||||||
byte[] value = new byte[len];
|
byte[] value = new byte[len];
|
||||||
unsafe.copyMemory(null, address+start, value,
|
unsafe.copyMemory(null, address+start, value,
|
||||||
Unsafe.ARRAY_BYTE_BASE_OFFSET, len);
|
Unsafe.ARRAY_BYTE_BASE_OFFSET, len);
|
||||||
String s = new String(value);
|
String s = Util.toString(value);
|
||||||
if (s.startsWith(USER_NAMESPACE)) {
|
if (s.startsWith(USER_NAMESPACE)) {
|
||||||
s = s.substring(USER_NAMESPACE.length());
|
s = s.substring(USER_NAMESPACE.length());
|
||||||
list.add(s);
|
list.add(s);
|
||||||
|
@ -42,16 +42,15 @@ import static sun.nio.fs.SolarisConstants.*;
|
|||||||
class SolarisUserDefinedFileAttributeView
|
class SolarisUserDefinedFileAttributeView
|
||||||
extends AbstractUserDefinedFileAttributeView
|
extends AbstractUserDefinedFileAttributeView
|
||||||
{
|
{
|
||||||
|
private static final byte[] HERE = { '.' };
|
||||||
|
|
||||||
private byte[] nameAsBytes(UnixPath file, String name) throws IOException {
|
private byte[] nameAsBytes(UnixPath file, String name) throws IOException {
|
||||||
byte[] bytes = name.getBytes();
|
byte[] bytes = Util.toBytes(name);
|
||||||
// "", "." and ".." not allowed
|
// "", "." and ".." not allowed
|
||||||
if (bytes.length == 0 || bytes[0] == '.') {
|
if ((bytes.length == 0 || bytes[0] == '.') &&
|
||||||
if (bytes.length <= 1 ||
|
((bytes.length <= 1 || (bytes.length == 2 && bytes[1] == '.')) {
|
||||||
(bytes.length == 2 && bytes[1] == '.'))
|
throw new FileSystemException(file.getPathForExceptionMessage(),
|
||||||
{
|
null, "'" + name + "' is not a valid name");
|
||||||
throw new FileSystemException(file.getPathForExceptionMessage(),
|
|
||||||
null, "'" + name + "' is not a valid name");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return bytes;
|
return bytes;
|
||||||
}
|
}
|
||||||
@ -73,7 +72,7 @@ class SolarisUserDefinedFileAttributeView
|
|||||||
try {
|
try {
|
||||||
try {
|
try {
|
||||||
// open extended attribute directory
|
// open extended attribute directory
|
||||||
int dfd = openat(fd, ".".getBytes(), (O_RDONLY|O_XATTR), 0);
|
int dfd = openat(fd, HERE, (O_RDONLY|O_XATTR), 0);
|
||||||
long dp;
|
long dp;
|
||||||
try {
|
try {
|
||||||
dp = fdopendir(dfd);
|
dp = fdopendir(dfd);
|
||||||
@ -87,7 +86,7 @@ class SolarisUserDefinedFileAttributeView
|
|||||||
try {
|
try {
|
||||||
byte[] name;
|
byte[] name;
|
||||||
while ((name = readdir(dp)) != null) {
|
while ((name = readdir(dp)) != null) {
|
||||||
String s = new String(name);
|
String s = Util.toString(name);
|
||||||
if (!s.equals(".") && !s.equals(".."))
|
if (!s.equals(".") && !s.equals(".."))
|
||||||
list.add(s);
|
list.add(s);
|
||||||
}
|
}
|
||||||
@ -217,7 +216,7 @@ class SolarisUserDefinedFileAttributeView
|
|||||||
|
|
||||||
int fd = file.openForAttributeAccess(followLinks);
|
int fd = file.openForAttributeAccess(followLinks);
|
||||||
try {
|
try {
|
||||||
int dfd = openat(fd, ".".getBytes(), (O_RDONLY|O_XATTR), 0);
|
int dfd = openat(fd, HERE, (O_RDONLY|O_XATTR), 0);
|
||||||
try {
|
try {
|
||||||
unlinkat(dfd, nameAsBytes(file,name), 0);
|
unlinkat(dfd, nameAsBytes(file,name), 0);
|
||||||
} finally {
|
} finally {
|
||||||
@ -243,7 +242,7 @@ class SolarisUserDefinedFileAttributeView
|
|||||||
static void copyExtendedAttributes(int ofd, int nfd) {
|
static void copyExtendedAttributes(int ofd, int nfd) {
|
||||||
try {
|
try {
|
||||||
// open extended attribute directory
|
// open extended attribute directory
|
||||||
int dfd = openat(ofd, ".".getBytes(), (O_RDONLY|O_XATTR), 0);
|
int dfd = openat(ofd, HERE, (O_RDONLY|O_XATTR), 0);
|
||||||
long dp = 0L;
|
long dp = 0L;
|
||||||
try {
|
try {
|
||||||
dp = fdopendir(dfd);
|
dp = fdopendir(dfd);
|
||||||
|
@ -61,7 +61,7 @@ class UnixException extends Exception {
|
|||||||
if (msg != null) {
|
if (msg != null) {
|
||||||
return msg;
|
return msg;
|
||||||
} else {
|
} else {
|
||||||
return new String(UnixNativeDispatcher.strerror(errno()));
|
return Util.toString(UnixNativeDispatcher.strerror(errno()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -196,7 +196,7 @@ abstract class UnixFileStore
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
StringBuilder sb = new StringBuilder(new String(entry.dir()));
|
StringBuilder sb = new StringBuilder(Util.toString(entry.dir()));
|
||||||
sb.append(" (");
|
sb.append(" (");
|
||||||
sb.append(entry.name());
|
sb.append(entry.name());
|
||||||
sb.append(")");
|
sb.append(")");
|
||||||
|
@ -49,7 +49,7 @@ abstract class UnixFileSystem
|
|||||||
// package-private
|
// package-private
|
||||||
UnixFileSystem(UnixFileSystemProvider provider, String dir) {
|
UnixFileSystem(UnixFileSystemProvider provider, String dir) {
|
||||||
this.provider = provider;
|
this.provider = provider;
|
||||||
this.defaultDirectory = UnixPath.normalizeAndCheck(dir).getBytes();
|
this.defaultDirectory = Util.toBytes(UnixPath.normalizeAndCheck(dir));
|
||||||
if (this.defaultDirectory[0] != '/') {
|
if (this.defaultDirectory[0] != '/') {
|
||||||
throw new RuntimeException("default directory must be absolute");
|
throw new RuntimeException("default directory must be absolute");
|
||||||
}
|
}
|
||||||
@ -204,7 +204,7 @@ abstract class UnixFileSystem
|
|||||||
SecurityManager sm = System.getSecurityManager();
|
SecurityManager sm = System.getSecurityManager();
|
||||||
if (sm != null) {
|
if (sm != null) {
|
||||||
try {
|
try {
|
||||||
sm.checkRead(new String(entry.dir()));
|
sm.checkRead(Util.toString(entry.dir()));
|
||||||
} catch (SecurityException x) {
|
} catch (SecurityException x) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -43,12 +43,12 @@ class UnixMountEntry {
|
|||||||
}
|
}
|
||||||
|
|
||||||
String name() {
|
String name() {
|
||||||
return new String(name);
|
return Util.toString(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
String fstype() {
|
String fstype() {
|
||||||
if (fstypeAsString == null)
|
if (fstypeAsString == null)
|
||||||
fstypeAsString = new String(fstype);
|
fstypeAsString = Util.toString(fstype);
|
||||||
return fstypeAsString;
|
return fstypeAsString;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -65,7 +65,7 @@ class UnixMountEntry {
|
|||||||
*/
|
*/
|
||||||
boolean hasOption(String requested) {
|
boolean hasOption(String requested) {
|
||||||
if (optionsAsString == null)
|
if (optionsAsString == null)
|
||||||
optionsAsString = new String(opts);
|
optionsAsString = Util.toString(opts);
|
||||||
for (String opt: Util.split(optionsAsString, ',')) {
|
for (String opt: Util.split(optionsAsString, ',')) {
|
||||||
if (opt.equals(requested))
|
if (opt.equals(requested))
|
||||||
return true;
|
return true;
|
||||||
|
@ -100,7 +100,7 @@ class UnixNativeDispatcher {
|
|||||||
*/
|
*/
|
||||||
static long fopen(UnixPath filename, String mode) throws UnixException {
|
static long fopen(UnixPath filename, String mode) throws UnixException {
|
||||||
NativeBuffer pathBuffer = copyToNativeBuffer(filename);
|
NativeBuffer pathBuffer = copyToNativeBuffer(filename);
|
||||||
NativeBuffer modeBuffer = NativeBuffers.asNativeBuffer(mode.getBytes());
|
NativeBuffer modeBuffer = NativeBuffers.asNativeBuffer(Util.toBytes(mode));
|
||||||
try {
|
try {
|
||||||
return fopen0(pathBuffer.address(), modeBuffer.address());
|
return fopen0(pathBuffer.address(), modeBuffer.address());
|
||||||
} finally {
|
} finally {
|
||||||
@ -473,7 +473,7 @@ class UnixNativeDispatcher {
|
|||||||
* @return passwd->pw_uid
|
* @return passwd->pw_uid
|
||||||
*/
|
*/
|
||||||
static int getpwnam(String name) throws UnixException {
|
static int getpwnam(String name) throws UnixException {
|
||||||
NativeBuffer buffer = NativeBuffers.asNativeBuffer(name.getBytes());
|
NativeBuffer buffer = NativeBuffers.asNativeBuffer(Util.toBytes(name));
|
||||||
try {
|
try {
|
||||||
return getpwnam0(buffer.address());
|
return getpwnam0(buffer.address());
|
||||||
} finally {
|
} finally {
|
||||||
@ -488,7 +488,7 @@ class UnixNativeDispatcher {
|
|||||||
* @return group->gr_name
|
* @return group->gr_name
|
||||||
*/
|
*/
|
||||||
static int getgrnam(String name) throws UnixException {
|
static int getgrnam(String name) throws UnixException {
|
||||||
NativeBuffer buffer = NativeBuffers.asNativeBuffer(name.getBytes());
|
NativeBuffer buffer = NativeBuffers.asNativeBuffer(Util.toBytes(name));
|
||||||
try {
|
try {
|
||||||
return getgrnam0(buffer.address());
|
return getgrnam0(buffer.address());
|
||||||
} finally {
|
} finally {
|
||||||
|
@ -120,7 +120,7 @@ class UnixPath
|
|||||||
SoftReference<CharsetEncoder> ref = encoder.get();
|
SoftReference<CharsetEncoder> ref = encoder.get();
|
||||||
CharsetEncoder ce = (ref != null) ? ref.get() : null;
|
CharsetEncoder ce = (ref != null) ? ref.get() : null;
|
||||||
if (ce == null) {
|
if (ce == null) {
|
||||||
ce = Charset.defaultCharset().newEncoder()
|
ce = Util.jnuEncoding().newEncoder()
|
||||||
.onMalformedInput(CodingErrorAction.REPORT)
|
.onMalformedInput(CodingErrorAction.REPORT)
|
||||||
.onUnmappableCharacter(CodingErrorAction.REPORT);
|
.onUnmappableCharacter(CodingErrorAction.REPORT);
|
||||||
encoder.set(new SoftReference<CharsetEncoder>(ce));
|
encoder.set(new SoftReference<CharsetEncoder>(ce));
|
||||||
@ -186,7 +186,7 @@ class UnixPath
|
|||||||
// use this path for permission checks
|
// use this path for permission checks
|
||||||
String getPathForPermissionCheck() {
|
String getPathForPermissionCheck() {
|
||||||
if (getFileSystem().needToResolveAgainstDefaultDirectory()) {
|
if (getFileSystem().needToResolveAgainstDefaultDirectory()) {
|
||||||
return new String(getByteArrayForSysCalls());
|
return Util.toString(getByteArrayForSysCalls());
|
||||||
} else {
|
} else {
|
||||||
return toString();
|
return toString();
|
||||||
}
|
}
|
||||||
@ -758,7 +758,7 @@ class UnixPath
|
|||||||
public String toString() {
|
public String toString() {
|
||||||
// OK if two or more threads create a String
|
// OK if two or more threads create a String
|
||||||
if (stringValue == null) {
|
if (stringValue == null) {
|
||||||
stringValue = fs.normalizeJavaPath(new String(path)); // platform encoding
|
stringValue = fs.normalizeJavaPath(Util.toString(path)); // platform encoding
|
||||||
}
|
}
|
||||||
return stringValue;
|
return stringValue;
|
||||||
}
|
}
|
||||||
|
@ -115,7 +115,7 @@ class UnixUserPrincipals {
|
|||||||
static User fromUid(int uid) {
|
static User fromUid(int uid) {
|
||||||
String name = null;
|
String name = null;
|
||||||
try {
|
try {
|
||||||
name = new String(getpwuid(uid));
|
name = Util.toString(getpwuid(uid));
|
||||||
} catch (UnixException x) {
|
} catch (UnixException x) {
|
||||||
name = Integer.toString(uid);
|
name = Integer.toString(uid);
|
||||||
}
|
}
|
||||||
@ -126,7 +126,7 @@ class UnixUserPrincipals {
|
|||||||
static Group fromGid(int gid) {
|
static Group fromGid(int gid) {
|
||||||
String name = null;
|
String name = null;
|
||||||
try {
|
try {
|
||||||
name = new String(getgrgid(gid));
|
name = Util.toString(getgrgid(gid));
|
||||||
} catch (UnixException x) {
|
} catch (UnixException x) {
|
||||||
name = Integer.toString(gid);
|
name = Integer.toString(gid);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user