This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-lang.git

commit 97fb6a23e02d67cc52506e819363d3781f33c1b3
Author: Gary Gregory <garydgreg...@gmail.com>
AuthorDate: Fri Feb 28 16:47:01 2025 -0500

    Add SystemUtils.getJavaIoTmpDirPath()
---
 src/changes/changes.xml                                    |  1 +
 src/main/java/org/apache/commons/lang3/SystemUtils.java    | 14 ++++++++++++++
 .../java/org/apache/commons/lang3/SystemUtilsTest.java     | 12 ++++++++++++
 3 files changed, 27 insertions(+)

diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index b54c9b36b..292a83c68 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -104,6 +104,7 @@ The <action> type attribute can be add,update,fix,remove.
     <action                   type="add" dev="ggregory" due-to="Gary 
Gregory">Add EnumUtils.getFirstEnum(Class&lt;E&gt;, int, 
ToIntFunction&lt;E&gt;, E).</action>
     <action                   type="add" dev="ggregory" due-to="Gary 
Gregory">Add FailableToBooleanFunction.</action>
     <action                   type="add" dev="ggregory" due-to="Gary 
Gregory">Add the @FunctionalInterface annotation to 
org.apache.commons.lang3.concurrent.Computable.</action>
+    <action                   type="add" dev="ggregory" due-to="Gary 
Gregory">SystemUtils.getJavaIoTmpDirPath().</action>
     <!-- UPDATE -->
     <action                   type="update" dev="ggregory" due-to="Gary 
Gregory, Dependabot">Bump org.apache.commons:commons-parent from 73 to 81 
#1267, #1277, #1283, #1288, #1302.</action>
     <action                   type="update" dev="ggregory" due-to="Gary 
Gregory, Dependabot">[site] Bump org.codehaus.mojo:taglist-maven-plugin from 
3.1.0 to 3.2.1 #1300.</action>
diff --git a/src/main/java/org/apache/commons/lang3/SystemUtils.java 
b/src/main/java/org/apache/commons/lang3/SystemUtils.java
index c6008f19b..957e08d08 100644
--- a/src/main/java/org/apache/commons/lang3/SystemUtils.java
+++ b/src/main/java/org/apache/commons/lang3/SystemUtils.java
@@ -17,6 +17,8 @@
 package org.apache.commons.lang3;
 
 import java.io.File;
+import java.nio.file.Path;
+import java.nio.file.Paths;
 
 /**
  * Helpers for {@link System}.
@@ -2073,6 +2075,18 @@ public static File getJavaIoTmpDir() {
         return new File(SystemProperties.getJavaIoTmpdir());
     }
 
+    /**
+     * Gets the current Java IO temporary directory as a {@link Path}.
+     *
+     * @return a directory
+     * @throws SecurityException if a security manager exists and its {@code 
checkPropertyAccess} method doesn't allow access to the specified system 
property.
+     * @see SystemProperties#getJavaIoTmpdir()
+     * @since 3.18.0
+     */
+    public static Path getJavaIoTmpDirPath() {
+        return Paths.get(SystemProperties.getJavaIoTmpdir());
+    }
+
     /**
      * Tests if the Java version matches the version we are running.
      * <p>
diff --git a/src/test/java/org/apache/commons/lang3/SystemUtilsTest.java 
b/src/test/java/org/apache/commons/lang3/SystemUtilsTest.java
index debd60d29..5e98f587b 100644
--- a/src/test/java/org/apache/commons/lang3/SystemUtilsTest.java
+++ b/src/test/java/org/apache/commons/lang3/SystemUtilsTest.java
@@ -29,6 +29,8 @@
 import java.lang.reflect.Constructor;
 import java.lang.reflect.Field;
 import java.lang.reflect.Modifier;
+import java.nio.file.Files;
+import java.nio.file.Path;
 import java.util.Locale;
 
 import org.junit.jupiter.api.Test;
@@ -290,6 +292,16 @@ public void testGetJavaIoTmpDir() {
         assertTrue(dir.exists());
     }
 
+    /**
+     * Assumes no security manager exists.
+     */
+    @Test
+    public void testGetJavaIoTmpDirPath() {
+        final Path dir = SystemUtils.getJavaIoTmpDirPath();
+        assertNotNull(dir);
+        assertTrue(Files.exists(dir));
+    }
+
     /**
      * Assumes no security manager exists.
      */

Reply via email to