From 1d5587b887cd3885b2b80e2334c2f3ea2de7c5f3 Mon Sep 17 00:00:00 2001 From: Phil Race Date: Tue, 26 Nov 2024 20:11:52 +0000 Subject: [PATCH] 8344256: Clean up obsolete code in java.desktop/share/classes/sun/awt/datatransfer/DataTransferer.java Reviewed-by: azvegint, kizune --- .../sun/awt/datatransfer/DataTransferer.java | 109 +----------------- 1 file changed, 5 insertions(+), 104 deletions(-) diff --git a/src/java.desktop/share/classes/sun/awt/datatransfer/DataTransferer.java b/src/java.desktop/share/classes/sun/awt/datatransfer/DataTransferer.java index 5014bb78ead..568da951a7d 100644 --- a/src/java.desktop/share/classes/sun/awt/datatransfer/DataTransferer.java +++ b/src/java.desktop/share/classes/sun/awt/datatransfer/DataTransferer.java @@ -43,7 +43,6 @@ import java.io.BufferedReader; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.File; -import java.io.FilePermission; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; @@ -62,7 +61,6 @@ import java.nio.charset.Charset; import java.nio.charset.CharsetEncoder; import java.nio.charset.IllegalCharsetNameException; import java.nio.charset.UnsupportedCharsetException; -import java.security.ProtectionDomain; import java.util.AbstractMap; import java.util.ArrayList; import java.util.Arrays; @@ -756,7 +754,7 @@ search: (String.class.equals(flavor.getRepresentationClass()) && DataFlavorUtil.isFlavorCharsetTextType(flavor) && isTextFormat(format))) { - String str = removeSuspectedData(flavor, contents, (String)obj); + String str = (String)obj; return translateTransferableString( str, @@ -869,9 +867,7 @@ search: final List list = (List)obj; - final ProtectionDomain userProtectionDomain = getUserProtectionDomain(contents); - - final ArrayList fileList = castToFiles(list, userProtectionDomain); + final ArrayList fileList = castToFiles(list); try (ByteArrayOutputStream bos = convertFileListToBytes(fileList)) { theByteArray = bos.toByteArray(); @@ -896,8 +892,7 @@ search: targetCharset = "UTF-8"; } final List list = (List)obj; - final ProtectionDomain userProtectionDomain = getUserProtectionDomain(contents); - final ArrayList fileList = castToFiles(list, userProtectionDomain); + final ArrayList fileList = castToFiles(list); final ArrayList uriList = new ArrayList<>(fileList.size()); for (String fileObject : fileList) { final URI uri = new File(fileObject).toURI(); @@ -979,69 +974,12 @@ search: protected abstract ByteArrayOutputStream convertFileListToBytes(ArrayList fileList) throws IOException; - @SuppressWarnings("removal") - private String removeSuspectedData(DataFlavor flavor, final Transferable contents, final String str) - { - if (null == System.getSecurityManager() - || !flavor.isMimeTypeEqual("text/uri-list")) - { - return str; - } - - final ProtectionDomain userProtectionDomain = getUserProtectionDomain(contents); - StringBuilder allowedFiles = new StringBuilder(str.length()); - String [] uriArray = str.split("(\\s)+"); - - for (String fileName : uriArray) - { - File file = new File(fileName); - if (file.exists() && - !(isFileInWebstartedCache(file) || - isForbiddenToRead(file, userProtectionDomain))) - { - if (0 != allowedFiles.length()) - { - allowedFiles.append("\\r\\n"); - } - - allowedFiles.append(fileName); - } - } - return allowedFiles.toString(); - } - - private static ProtectionDomain getUserProtectionDomain(Transferable contents) { - return contents.getClass().getProtectionDomain(); - } - - private boolean isForbiddenToRead (File file, ProtectionDomain protectionDomain) - { - if (null == protectionDomain) { - return false; - } - try { - FilePermission filePermission = - new FilePermission(file.getCanonicalPath(), "read, delete"); - if (protectionDomain.implies(filePermission)) { - return false; - } - } catch (IOException e) {} - - return true; - } - - @SuppressWarnings("removal") - private ArrayList castToFiles(final List files, - final ProtectionDomain userProtectionDomain) throws IOException { + private ArrayList castToFiles(final List files) throws IOException { ArrayList fileList = new ArrayList<>(); for (Object fileObject : files) { File file = castToFile(fileObject); - if (file != null && - (null == System.getSecurityManager() || - !(isFileInWebstartedCache(file) || - isForbiddenToRead(file, userProtectionDomain)))) - { + if (file != null) { fileList.add(file.getCanonicalPath()); } } @@ -1062,43 +1000,6 @@ search: return new File(filePath); } - private static final String[] DEPLOYMENT_CACHE_PROPERTIES = { - "deployment.system.cachedir", - "deployment.user.cachedir", - "deployment.javaws.cachedir", - "deployment.javapi.cachedir" - }; - - private static final ArrayList deploymentCacheDirectoryList = new ArrayList<>(); - - private static boolean isFileInWebstartedCache(File f) { - - if (deploymentCacheDirectoryList.isEmpty()) { - for (String cacheDirectoryProperty : DEPLOYMENT_CACHE_PROPERTIES) { - String cacheDirectoryPath = System.getProperty(cacheDirectoryProperty); - if (cacheDirectoryPath != null) { - try { - File cacheDirectory = (new File(cacheDirectoryPath)).getCanonicalFile(); - if (cacheDirectory != null) { - deploymentCacheDirectoryList.add(cacheDirectory); - } - } catch (IOException ioe) {} - } - } - } - - for (File deploymentCacheDirectory : deploymentCacheDirectoryList) { - for (File dir = f; dir != null; dir = dir.getParentFile()) { - if (dir.equals(deploymentCacheDirectory)) { - return true; - } - } - } - - return false; - } - - public Object translateBytes(byte[] bytes, DataFlavor flavor, long format, Transferable localeTransferable) throws IOException