Skip to content

Commit 1d5587b

Browse files
committedNov 26, 2024
8344256: Clean up obsolete code in java.desktop/share/classes/sun/awt/datatransfer/DataTransferer.java
Reviewed-by: azvegint, kizune
1 parent 5e15415 commit 1d5587b

File tree

1 file changed

+5
-104
lines changed

1 file changed

+5
-104
lines changed
 

‎src/java.desktop/share/classes/sun/awt/datatransfer/DataTransferer.java

+5-104
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343
import java.io.ByteArrayInputStream;
4444
import java.io.ByteArrayOutputStream;
4545
import java.io.File;
46-
import java.io.FilePermission;
4746
import java.io.IOException;
4847
import java.io.InputStream;
4948
import java.io.InputStreamReader;
@@ -62,7 +61,6 @@
6261
import java.nio.charset.CharsetEncoder;
6362
import java.nio.charset.IllegalCharsetNameException;
6463
import java.nio.charset.UnsupportedCharsetException;
65-
import java.security.ProtectionDomain;
6664
import java.util.AbstractMap;
6765
import java.util.ArrayList;
6866
import java.util.Arrays;
@@ -756,7 +754,7 @@ public byte[] translateTransferable(Transferable contents,
756754
(String.class.equals(flavor.getRepresentationClass()) &&
757755
DataFlavorUtil.isFlavorCharsetTextType(flavor) && isTextFormat(format))) {
758756

759-
String str = removeSuspectedData(flavor, contents, (String)obj);
757+
String str = (String)obj;
760758

761759
return translateTransferableString(
762760
str,
@@ -869,9 +867,7 @@ public byte[] translateTransferable(Transferable contents,
869867

870868
final List<?> list = (List<?>)obj;
871869

872-
final ProtectionDomain userProtectionDomain = getUserProtectionDomain(contents);
873-
874-
final ArrayList<String> fileList = castToFiles(list, userProtectionDomain);
870+
final ArrayList<String> fileList = castToFiles(list);
875871

876872
try (ByteArrayOutputStream bos = convertFileListToBytes(fileList)) {
877873
theByteArray = bos.toByteArray();
@@ -896,8 +892,7 @@ public byte[] translateTransferable(Transferable contents,
896892
targetCharset = "UTF-8";
897893
}
898894
final List<?> list = (List<?>)obj;
899-
final ProtectionDomain userProtectionDomain = getUserProtectionDomain(contents);
900-
final ArrayList<String> fileList = castToFiles(list, userProtectionDomain);
895+
final ArrayList<String> fileList = castToFiles(list);
901896
final ArrayList<String> uriList = new ArrayList<>(fileList.size());
902897
for (String fileObject : fileList) {
903898
final URI uri = new File(fileObject).toURI();
@@ -979,69 +974,12 @@ private static byte[] convertObjectToBytes(Object object) throws IOException {
979974

980975
protected abstract ByteArrayOutputStream convertFileListToBytes(ArrayList<String> fileList) throws IOException;
981976

982-
@SuppressWarnings("removal")
983-
private String removeSuspectedData(DataFlavor flavor, final Transferable contents, final String str)
984-
{
985-
if (null == System.getSecurityManager()
986-
|| !flavor.isMimeTypeEqual("text/uri-list"))
987-
{
988-
return str;
989-
}
990-
991-
final ProtectionDomain userProtectionDomain = getUserProtectionDomain(contents);
992-
StringBuilder allowedFiles = new StringBuilder(str.length());
993-
String [] uriArray = str.split("(\\s)+");
994-
995-
for (String fileName : uriArray)
996-
{
997-
File file = new File(fileName);
998-
if (file.exists() &&
999-
!(isFileInWebstartedCache(file) ||
1000-
isForbiddenToRead(file, userProtectionDomain)))
1001-
{
1002-
if (0 != allowedFiles.length())
1003-
{
1004-
allowedFiles.append("\\r\\n");
1005-
}
1006-
1007-
allowedFiles.append(fileName);
1008-
}
1009-
}
1010-
return allowedFiles.toString();
1011-
}
1012-
1013-
private static ProtectionDomain getUserProtectionDomain(Transferable contents) {
1014-
return contents.getClass().getProtectionDomain();
1015-
}
1016-
1017-
private boolean isForbiddenToRead (File file, ProtectionDomain protectionDomain)
1018-
{
1019-
if (null == protectionDomain) {
1020-
return false;
1021-
}
1022-
try {
1023-
FilePermission filePermission =
1024-
new FilePermission(file.getCanonicalPath(), "read, delete");
1025-
if (protectionDomain.implies(filePermission)) {
1026-
return false;
1027-
}
1028-
} catch (IOException e) {}
1029-
1030-
return true;
1031-
}
1032-
1033-
@SuppressWarnings("removal")
1034-
private ArrayList<String> castToFiles(final List<?> files,
1035-
final ProtectionDomain userProtectionDomain) throws IOException {
977+
private ArrayList<String> castToFiles(final List<?> files) throws IOException {
1036978
ArrayList<String> fileList = new ArrayList<>();
1037979
for (Object fileObject : files)
1038980
{
1039981
File file = castToFile(fileObject);
1040-
if (file != null &&
1041-
(null == System.getSecurityManager() ||
1042-
!(isFileInWebstartedCache(file) ||
1043-
isForbiddenToRead(file, userProtectionDomain))))
1044-
{
982+
if (file != null) {
1045983
fileList.add(file.getCanonicalPath());
1046984
}
1047985
}
@@ -1062,43 +1000,6 @@ private File castToFile(Object fileObject) throws IOException {
10621000
return new File(filePath);
10631001
}
10641002

1065-
private static final String[] DEPLOYMENT_CACHE_PROPERTIES = {
1066-
"deployment.system.cachedir",
1067-
"deployment.user.cachedir",
1068-
"deployment.javaws.cachedir",
1069-
"deployment.javapi.cachedir"
1070-
};
1071-
1072-
private static final ArrayList <File> deploymentCacheDirectoryList = new ArrayList<>();
1073-
1074-
private static boolean isFileInWebstartedCache(File f) {
1075-
1076-
if (deploymentCacheDirectoryList.isEmpty()) {
1077-
for (String cacheDirectoryProperty : DEPLOYMENT_CACHE_PROPERTIES) {
1078-
String cacheDirectoryPath = System.getProperty(cacheDirectoryProperty);
1079-
if (cacheDirectoryPath != null) {
1080-
try {
1081-
File cacheDirectory = (new File(cacheDirectoryPath)).getCanonicalFile();
1082-
if (cacheDirectory != null) {
1083-
deploymentCacheDirectoryList.add(cacheDirectory);
1084-
}
1085-
} catch (IOException ioe) {}
1086-
}
1087-
}
1088-
}
1089-
1090-
for (File deploymentCacheDirectory : deploymentCacheDirectoryList) {
1091-
for (File dir = f; dir != null; dir = dir.getParentFile()) {
1092-
if (dir.equals(deploymentCacheDirectory)) {
1093-
return true;
1094-
}
1095-
}
1096-
}
1097-
1098-
return false;
1099-
}
1100-
1101-
11021003
public Object translateBytes(byte[] bytes, DataFlavor flavor,
11031004
long format, Transferable localeTransferable)
11041005
throws IOException

0 commit comments

Comments
 (0)