提交 838bf579 编写于 作者: C chegar

6991300: MimeTable is unsafe

Reviewed-by: alanb, michaelm
上级 042280ba
......@@ -73,29 +73,32 @@ public class MimeTable implements FileNameMap {
private static final String filePreamble = "sun.net.www MIME content-types table";
private static final String fileMagic = "#" + filePreamble;
private static MimeTable defaultInstance = null;
MimeTable() {
load();
}
private static class DefaultInstanceHolder {
static final MimeTable defaultInstance = getDefaultInstance();
static MimeTable getDefaultInstance() {
return java.security.AccessController.doPrivileged(
new java.security.PrivilegedAction<MimeTable>() {
public MimeTable run() {
MimeTable instance = new MimeTable();
URLConnection.setFileNameMap(instance);
return instance;
}
});
}
}
/**
* Get the single instance of this class. First use will load the
* table from a data file.
*/
public static MimeTable getDefaultTable() {
if (defaultInstance == null) {
java.security.AccessController.doPrivileged(
new java.security.PrivilegedAction<Void>() {
public Void run() {
defaultInstance = new MimeTable();
URLConnection.setFileNameMap(defaultInstance);
return null;
}
});
}
return defaultInstance;
return DefaultInstanceHolder.defaultInstance;
}
/**
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册