You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by rg...@apache.org on 2019/05/13 05:31:30 UTC

[logging-log4j2] 05/06: Use existing JDK version detection that is JEP223 aware. Version testing moved to org.apache.logging.log4j.util.ConstantsTest.testJdkVersionDetection

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

rgoers pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git

commit 93e66ae7d88e829d0019fde332cf4aca67fb6693
Author: ulrichenslin <ue...@apple.com>
AuthorDate: Mon Mar 4 08:25:41 2019 +0200

    Use existing JDK version detection that is JEP223 aware.
    Version testing moved to org.apache.logging.log4j.util.ConstantsTest.testJdkVersionDetection
---
 .../log4j/core/layout/AbstractStringLayout.java    | 15 +------------
 .../core/layout/AbstractStringLayoutTest.java      | 25 ----------------------
 2 files changed, 1 insertion(+), 39 deletions(-)

diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/AbstractStringLayout.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/AbstractStringLayout.java
index deea87f..3b9eb61 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/AbstractStringLayout.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/AbstractStringLayout.java
@@ -131,20 +131,7 @@ public abstract class AbstractStringLayout extends AbstractLayout<String> implem
 
     // LOG4J2-1151: If the built-in JDK 8 encoders are available we should use them.
     private static boolean isPreJava8() {
-        final String version = System.getProperty("java.version");
-        final String[] parts = version.split("\\.");
-        try {
-            int major = Integer.parseInt(parts[1]);
-
-            final int token = Integer.parseInt(parts[0]);
-            boolean isJEP223 = token != 1;
-            if (isJEP223) {
-                major = token;
-            }
-            return major < 8;
-        } catch (final Exception ex) {
-            return true;
-        }
+        return org.apache.logging.log4j.util.Constants.JAVA_MAJOR_VERSION < 8;
     }
 
     private static int size(final String property, final int defaultValue) {
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/AbstractStringLayoutTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/AbstractStringLayoutTest.java
index 9dce991..2b35bac 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/AbstractStringLayoutTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/AbstractStringLayoutTest.java
@@ -78,29 +78,4 @@ public class AbstractStringLayoutTest {
         assertEquals("empty, ready for use", 0, sb3.length());
     }
 
-    @Test
-    public void testJdkVersionDetection() throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
-
-        final String currentVersion = System.getProperty("java.version");
-
-        Properties properties = new Properties();
-        properties.put("java.version","1.2.0");
-        System.setProperties(properties);
-
-        Method method = AbstractStringLayout.class.getDeclaredMethod("isPreJava8",null);
-        method.setAccessible(true);
-        assertTrue ((Boolean) method.invoke("isPreJava8"));
-
-        properties = new Properties();
-        properties.put("java.version","9.1.0");
-        System.setProperties(properties);
-
-        assertFalse ((Boolean) method.invoke("isPreJava8"));
-
-        //reset the value to the current version
-        properties = new Properties();
-        properties.put("java.version", currentVersion);
-        System.setProperties(properties);
-
-    }
 }
\ No newline at end of file