Skip to content

Commit fec0dbc

Browse files
nick-someonenetdpb
authored andcommitted
Deprecate Files.createTempDir(), noting that better alternatives exist for Android as well as for users running Java 7 or later.
RELNOTES=`io`: Deprecated `Files.createTempDir()`. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=328552787
1 parent 554546c commit fec0dbc

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

android/guava/src/com/google/common/io/Files.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,11 @@ public static boolean equal(File file1, File file2) throws IOException {
398398
* be exploited to create security vulnerabilities, especially when executable files are to be
399399
* written into the directory.
400400
*
401+
* <p>Depending on the environmment that this code is run in, the system temporary directory (and
402+
* thus the directory this method creates) may be more visible that a program would like - files
403+
* written to this directory may be read or overwritten by hostile programs running on the same
404+
* machine.
405+
*
401406
* <p>This method assumes that the temporary volume is writable, has free inodes and free blocks,
402407
* and that it will not be called thousands of times per second.
403408
*
@@ -406,8 +411,15 @@ public static boolean equal(File file1, File file2) throws IOException {
406411
*
407412
* @return the newly-created directory
408413
* @throws IllegalStateException if the directory could not be created
414+
* @deprecated For Android users, see the <a
415+
* href="https://developer.android.com/training/data-storage" target="_blank">Data and File
416+
* Storage overview</a> to select an appropriate temporary directory (perhaps {@code
417+
* context.getCacheDir()}). For developers on Java 7 or later, use {@link
418+
* java.nio.file.Files#createTempDirectory}, transforming it to a {@link File} using {@link
419+
* java.nio.file.Path#toFile() toFile()} if needed.
409420
*/
410421
@Beta
422+
@Deprecated
411423
public static File createTempDir() {
412424
File baseDir = new File(System.getProperty("java.io.tmpdir"));
413425
@SuppressWarnings("GoodTime") // reading system time without TimeSource

guava/src/com/google/common/io/Files.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,11 @@ public static boolean equal(File file1, File file2) throws IOException {
398398
* be exploited to create security vulnerabilities, especially when executable files are to be
399399
* written into the directory.
400400
*
401+
* <p>Depending on the environmment that this code is run in, the system temporary directory (and
402+
* thus the directory this method creates) may be more visible that a program would like - files
403+
* written to this directory may be read or overwritten by hostile programs running on the same
404+
* machine.
405+
*
401406
* <p>This method assumes that the temporary volume is writable, has free inodes and free blocks,
402407
* and that it will not be called thousands of times per second.
403408
*
@@ -406,8 +411,15 @@ public static boolean equal(File file1, File file2) throws IOException {
406411
*
407412
* @return the newly-created directory
408413
* @throws IllegalStateException if the directory could not be created
414+
* @deprecated For Android users, see the <a
415+
* href="https://developer.android.com/training/data-storage" target="_blank">Data and File
416+
* Storage overview</a> to select an appropriate temporary directory (perhaps {@code
417+
* context.getCacheDir()}). For developers on Java 7 or later, use {@link
418+
* java.nio.file.Files#createTempDirectory}, transforming it to a {@link File} using {@link
419+
* java.nio.file.Path#toFile() toFile()} if needed.
409420
*/
410421
@Beta
422+
@Deprecated
411423
public static File createTempDir() {
412424
File baseDir = new File(System.getProperty("java.io.tmpdir"));
413425
@SuppressWarnings("GoodTime") // reading system time without TimeSource

0 commit comments

Comments
 (0)