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 5035fdd788bc8e77bd90b52d49f70903044e7e63
Author: Gary Gregory <garydgreg...@gmail.com>
AuthorDate: Fri Feb 28 16:48:57 2025 -0500

    Add SystemUtils.getJavaHomePath()
---
 src/changes/changes.xml                                     |  3 ++-
 src/main/java/org/apache/commons/lang3/SystemUtils.java     | 12 ++++++++++++
 src/test/java/org/apache/commons/lang3/SystemUtilsTest.java | 10 ++++++++++
 3 files changed, 24 insertions(+), 1 deletion(-)

diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 292a83c68..c8c6f656a 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -104,7 +104,8 @@ 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>
+    <action                   type="add" dev="ggregory" due-to="Gary 
Gregory">Add SystemUtils.getJavaIoTmpDirPath().</action>
+    <action                   type="add" dev="ggregory" due-to="Gary 
Gregory">Add SystemUtils.getJavaHomePath().</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 957e08d08..23a6559db 100644
--- a/src/main/java/org/apache/commons/lang3/SystemUtils.java
+++ b/src/main/java/org/apache/commons/lang3/SystemUtils.java
@@ -2063,6 +2063,18 @@ public static File getJavaHome() {
         return new File(SystemProperties.getJavaHome());
     }
 
+    /**
+     * Gets the current Java home directory as a {@link File}.
+     *
+     * @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#getJavaHome()
+     * @since 3.18.0
+     */
+    public static Path getJavaHomePath() {
+        return Paths.get(SystemProperties.getJavaHome());
+    }
+
     /**
      * Gets the current Java IO temporary directory as a {@link File}.
      *
diff --git a/src/test/java/org/apache/commons/lang3/SystemUtilsTest.java 
b/src/test/java/org/apache/commons/lang3/SystemUtilsTest.java
index 5e98f587b..a9ce53b29 100644
--- a/src/test/java/org/apache/commons/lang3/SystemUtilsTest.java
+++ b/src/test/java/org/apache/commons/lang3/SystemUtilsTest.java
@@ -282,6 +282,16 @@ public void testGetJavaHome() {
         assertTrue(dir.exists());
     }
 
+    /**
+     * Assumes no security manager exists.
+     */
+    @Test
+    public void testGetJavaHomePath() {
+        final Path dir = SystemUtils.getJavaHomePath();
+        assertNotNull(dir);
+        assertTrue(Files.exists(dir));
+    }
+
     /**
      * Assumes no security manager exists.
      */

Reply via email to