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

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


The following commit(s) were added to refs/heads/2.x by this push:
     new 6b9d122e95 Upgrade compiler baseline to Java 17 (#2021)
6b9d122e95 is described below

commit 6b9d122e95556ec3dd6456bfbbd330d832a6f0db
Author: Volkan Yazıcı <[email protected]>
AuthorDate: Fri Dec 1 22:41:43 2023 +0100

    Upgrade compiler baseline to Java 17 (#2021)
---
 .github/workflows/build.yaml                       |  6 +--
 .github/workflows/codeql-analysis.yaml             |  2 +-
 .github/workflows/merge-dependabot.yaml            |  4 +-
 .java-version                                      |  2 +-
 BUILDING.adoc                                      |  2 +-
 log4j-1.2-api/pom.xml                              | 47 +++++++++++++++--
 .../logging/log4j/NoopThreadContextTest.java       |  8 ++-
 .../log4j/ThreadContextInheritanceTest.java        |  7 ++-
 .../log4j/spi/DefaultThreadContextMapTest.java     |  4 +-
 log4j-core-test/pom.xml                            | 59 ++++++++++++++++++++--
 .../log4j/core/net/UrlConnectionFactoryTest.java   |  3 +-
 ...Test.java => DatePatternConverterTestBase.java} | 56 ++++++++------------
 .../DatePatternConverterWithThreadLocalsTest.java  | 29 ++++-------
 ...atePatternConverterWithoutThreadLocalsTest.java | 28 +++-------
 .../logging/log4j/core/util/ClockFactoryTest.java  |  5 --
 .../logging/log4j/core/async/AsyncLogger.java      |  5 +-
 .../logging/log4j/core/impl/Log4jLogEvent.java     |  5 +-
 log4j-jpa/pom.xml                                  | 47 +++++++++++++++--
 log4j-osgi-test/pom.xml                            | 39 ++++++++++++++
 log4j-parent/pom.xml                               |  7 +++
 pom.xml                                            |  4 --
 src/changelog/.2.x.x/java_17.xml                   | 26 ++++++++++
 src/site/_constants.adoc                           |  2 +-
 src/site/_release-notes/_2.x.x.adoc                |  1 +
 24 files changed, 278 insertions(+), 120 deletions(-)

diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml
index b2031dd9d9..0daa1cfe8d 100644
--- a/.github/workflows/build.yaml
+++ b/.github/workflows/build.yaml
@@ -42,7 +42,7 @@ jobs:
     with:
       java-version: |
         8
-        11
+        17
       site-enabled: true
 
   deploy-snapshot:
@@ -56,7 +56,7 @@ jobs:
     with:
       java-version: |
         8
-        11
+        17
 
   deploy-release:
     needs: build
@@ -75,6 +75,6 @@ jobs:
     with:
       java-version: |
         8
-        11
+        17
       project-id: log4j
       site-enabled: true
diff --git a/.github/workflows/codeql-analysis.yaml 
b/.github/workflows/codeql-analysis.yaml
index 012bb99c18..de440779f4 100644
--- a/.github/workflows/codeql-analysis.yaml
+++ b/.github/workflows/codeql-analysis.yaml
@@ -34,7 +34,7 @@ jobs:
     with:
       java-version: |
         8
-        11
+        17
     # Permissions required to publish Security Alerts
     permissions:
       actions: read
diff --git a/.github/workflows/merge-dependabot.yaml 
b/.github/workflows/merge-dependabot.yaml
index a8963ebf6e..83a59f12fe 100644
--- a/.github/workflows/merge-dependabot.yaml
+++ b/.github/workflows/merge-dependabot.yaml
@@ -34,13 +34,13 @@ jobs:
     with:
       java-version: |
         8
-        11
+        17
 
   merge-dependabot:
     needs: build
     uses: 
apache/logging-parent/.github/workflows/merge-dependabot-reusable.yaml@main
     with:
-      java-version: 11
+      java-version: 17
     permissions:
       contents: write                                             # to push 
changelog commits
       pull-requests: write                                        # to close 
the PR
diff --git a/.java-version b/.java-version
index b4de394767..98d9bcb75a 100644
--- a/.java-version
+++ b/.java-version
@@ -1 +1 @@
-11
+17
diff --git a/BUILDING.adoc b/BUILDING.adoc
index 8f878df5e2..38b43d9d3e 100644
--- a/BUILDING.adoc
+++ b/BUILDING.adoc
@@ -18,7 +18,7 @@
 [#requirements]
 == Requirements
 
-* JDK 11+
+* JDK 17+
 * A modern Linux, OSX, or Windows host
 
 [#building]
diff --git a/log4j-1.2-api/pom.xml b/log4j-1.2-api/pom.xml
index ba8091687c..58c18dd5bc 100644
--- a/log4j-1.2-api/pom.xml
+++ b/log4j-1.2-api/pom.xml
@@ -140,15 +140,12 @@
 
   <build>
     <plugins>
+
+      <!-- Enable Log4j plugin processing -->
       <plugin>
         <groupId>org.apache.maven.plugins</groupId>
         <artifactId>maven-compiler-plugin</artifactId>
         <configuration>
-          <!--
-            ~ Modules that contain `log4j-core` plugins, must be compiled with:
-            ~
-            ~   
org.apache.logging.log4j.core.config.plugins.processor.PluginProcessor
-            -->
           <annotationProcessorPaths combine.children="append">
             <path>
               <groupId>org.apache.logging.log4j</groupId>
@@ -158,6 +155,46 @@
           </annotationProcessorPaths>
         </configuration>
       </plugin>
+
     </plugins>
   </build>
+
+  <profiles>
+
+    <!-- Fixes incompatible with Java 8 -->
+    <profile>
+
+      <id>java8-incompat-fixes</id>
+
+      <!-- CI uses Java 8 for running tests.
+           Hence, we assume CI=Java8 and apply our changes elsewhere.
+
+           One might think why not activate using `<jdk>[16,)` instead?
+           This doesn't work, since the match is not against "the JDK running 
tests", but "the JDK running Maven".
+           These two JDKs can differ due to Maven Toolchains.
+           See `java8-tests` profile in `/pom.xml` for details. -->
+      <activation>
+        <property>
+          <name>!env.CI</name>
+        </property>
+      </activation>
+
+      <!-- Illegal access is disabled by default in Java 16 due to JEP-396.
+           We are relaxing it for tests. -->
+      <build>
+        <plugins>
+          <plugin>
+            <groupId>org.apache.maven.plugins</groupId>
+            <artifactId>maven-surefire-plugin</artifactId>
+            <configuration>
+              <argLine>--add-opens java.base/java.io=ALL-UNNAMED</argLine>
+            </configuration>
+          </plugin>
+        </plugins>
+      </build>
+
+    </profile>
+
+  </profiles>
+
 </project>
diff --git 
a/log4j-api-test/src/test/java/org/apache/logging/log4j/NoopThreadContextTest.java
 
b/log4j-api-test/src/test/java/org/apache/logging/log4j/NoopThreadContextTest.java
index 61add403b5..d4ce703b56 100644
--- 
a/log4j-api-test/src/test/java/org/apache/logging/log4j/NoopThreadContextTest.java
+++ 
b/log4j-api-test/src/test/java/org/apache/logging/log4j/NoopThreadContextTest.java
@@ -18,17 +18,15 @@ package org.apache.logging.log4j;
 
 import static org.junit.jupiter.api.Assertions.assertNull;
 
-import org.apache.logging.log4j.test.junit.InitializesThreadContext;
+import org.apache.logging.log4j.test.junit.SetTestProperty;
 import org.apache.logging.log4j.test.junit.UsingThreadContextMap;
 import org.junit.jupiter.api.Test;
-import org.junitpioneer.jupiter.SetSystemProperty;
 
 /**
  * Tests {@link ThreadContext}.
  */
-@SetSystemProperty(key = "log4j2.disableThreadContext", value = "true")
-@SetSystemProperty(key = "log4j2.disableThreadContextMap", value = "true")
-@InitializesThreadContext
+@SetTestProperty(key = "log4j2.disableThreadContext", value = "true")
+@SetTestProperty(key = "log4j2.disableThreadContextMap", value = "true")
 @UsingThreadContextMap
 public class NoopThreadContextTest {
 
diff --git 
a/log4j-api-test/src/test/java/org/apache/logging/log4j/ThreadContextInheritanceTest.java
 
b/log4j-api-test/src/test/java/org/apache/logging/log4j/ThreadContextInheritanceTest.java
index 26fb296a6d..96783ae600 100644
--- 
a/log4j-api-test/src/test/java/org/apache/logging/log4j/ThreadContextInheritanceTest.java
+++ 
b/log4j-api-test/src/test/java/org/apache/logging/log4j/ThreadContextInheritanceTest.java
@@ -24,6 +24,9 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
 import org.apache.logging.log4j.spi.DefaultThreadContextMap;
 import org.apache.logging.log4j.test.ThreadContextUtilityClass;
 import org.apache.logging.log4j.test.junit.InitializesThreadContext;
+import org.apache.logging.log4j.test.junit.SetTestProperty;
+import org.apache.logging.log4j.test.junit.UsingThreadContextMap;
+import org.apache.logging.log4j.test.junit.UsingThreadContextStack;
 import org.junit.jupiter.api.AfterAll;
 import org.junit.jupiter.api.BeforeAll;
 import org.junit.jupiter.api.Tag;
@@ -33,8 +36,10 @@ import org.junitpioneer.jupiter.SetSystemProperty;
 /**
  * Tests {@link ThreadContext}.
  */
-@SetSystemProperty(key = DefaultThreadContextMap.INHERITABLE_MAP, value = 
"true")
+@SetTestProperty(key = DefaultThreadContextMap.INHERITABLE_MAP, value = "true")
 @InitializesThreadContext
+@UsingThreadContextMap
+@UsingThreadContextStack
 public class ThreadContextInheritanceTest {
 
     @BeforeAll
diff --git 
a/log4j-api-test/src/test/java/org/apache/logging/log4j/spi/DefaultThreadContextMapTest.java
 
b/log4j-api-test/src/test/java/org/apache/logging/log4j/spi/DefaultThreadContextMapTest.java
index 368fc3ca6f..a0ca976d73 100644
--- 
a/log4j-api-test/src/test/java/org/apache/logging/log4j/spi/DefaultThreadContextMapTest.java
+++ 
b/log4j-api-test/src/test/java/org/apache/logging/log4j/spi/DefaultThreadContextMapTest.java
@@ -25,10 +25,10 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
 import java.util.HashMap;
 import java.util.Map;
 import org.apache.logging.log4j.test.junit.InitializesThreadContext;
+import org.apache.logging.log4j.test.junit.SetTestProperty;
 import org.apache.logging.log4j.test.junit.UsingThreadContextMap;
 import org.junit.jupiter.api.Test;
 import org.junitpioneer.jupiter.ClearSystemProperty;
-import org.junitpioneer.jupiter.SetSystemProperty;
 
 /**
  * Tests the {@code DefaultThreadContextMap} class.
@@ -228,7 +228,7 @@ public class DefaultThreadContextMapTest {
     }
 
     @Test
-    @SetSystemProperty(key = DefaultThreadContextMap.INHERITABLE_MAP, value = 
"true")
+    @SetTestProperty(key = DefaultThreadContextMap.INHERITABLE_MAP, value = 
"true")
     @InitializesThreadContext
     public void testThreadLocalInheritableIfConfigured() {
         ThreadContextMapFactory.init();
diff --git a/log4j-core-test/pom.xml b/log4j-core-test/pom.xml
index 98d39a04d3..fb79c45da2 100644
--- a/log4j-core-test/pom.xml
+++ b/log4j-core-test/pom.xml
@@ -355,15 +355,12 @@
 
   <build>
     <plugins>
+
+      <!-- Enable Log4j plugin processing -->
       <plugin>
         <groupId>org.apache.maven.plugins</groupId>
         <artifactId>maven-compiler-plugin</artifactId>
         <configuration>
-          <!--
-            ~ Modules that contain `log4j-core` plugins, must be compiled with:
-            ~
-            ~   
org.apache.logging.log4j.core.config.plugins.processor.PluginProcessor
-            -->
           <annotationProcessorPaths combine.children="append">
             <path>
               <groupId>org.apache.logging.log4j</groupId>
@@ -373,6 +370,58 @@
           </annotationProcessorPaths>
         </configuration>
       </plugin>
+
     </plugins>
   </build>
+
+  <profiles>
+
+    <!-- Fixes incompatible with Java 8 -->
+    <profile>
+
+      <id>java8-incompat-fixes</id>
+
+      <!-- CI uses Java 8 for running tests.
+           Hence, we assume CI=Java8 and apply our changes elsewhere.
+
+           One might think why not activate using `<jdk>[16,)` instead?
+           This doesn't work, since the match is not against "the JDK running 
tests", but "the JDK running Maven".
+           These two JDKs can differ due to Maven Toolchains.
+           See `java8-tests` profile in `/pom.xml` for details. -->
+      <activation>
+        <property>
+          <name>!env.CI</name>
+        </property>
+      </activation>
+
+      <!-- JEP-335 has deprecated the built-in JavaScript engine (Nashorn) in 
Java 11, and JEP-372 removed it in Java 15.
+           We are adding it back for tests that use JavaScript. -->
+      <dependencies>
+        <dependency>
+          <groupId>org.openjdk.nashorn</groupId>
+          <artifactId>nashorn-core</artifactId>
+          <scope>test</scope>
+        </dependency>
+      </dependencies>
+
+      <!-- Illegal access is disabled by default in Java 16 due to JEP-396.
+           We are relaxing it for tests. -->
+      <build>
+        <plugins>
+          <plugin>
+            <groupId>org.apache.maven.plugins</groupId>
+            <artifactId>maven-surefire-plugin</artifactId>
+            <configuration>
+              <argLine>--add-opens java.base/java.lang=ALL-UNNAMED
+                --add-opens java.base/java.net=ALL-UNNAMED
+                --add-opens java.base/java.util=ALL-UNNAMED</argLine>
+            </configuration>
+          </plugin>
+        </plugins>
+      </build>
+
+    </profile>
+
+  </profiles>
+
 </project>
diff --git 
a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/net/UrlConnectionFactoryTest.java
 
b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/net/UrlConnectionFactoryTest.java
index c5912fc77e..e6bb7d5928 100644
--- 
a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/net/UrlConnectionFactoryTest.java
+++ 
b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/net/UrlConnectionFactoryTest.java
@@ -58,6 +58,7 @@ import org.junit.jupiter.api.BeforeAll;
 import org.junit.jupiter.api.Test;
 import org.junit.jupiter.api.condition.DisabledOnOs;
 import org.junit.jupiter.api.condition.OS;
+import org.junitpioneer.jupiter.RetryingTest;
 
 /**
  * Tests the UrlConnectionFactory
@@ -142,7 +143,7 @@ public class UrlConnectionFactoryTest {
         }
     }
 
-    @Test
+    @RetryingTest(maxAttempts = 5, suspendForMs = 1000)
     @DisabledOnOs(value = OS.WINDOWS, disabledReason = "Fails frequently on 
Windows (#2011)")
     public void testNoJarFileLeak() throws Exception {
         ConfigurationSourceTest.prepareJarConfigURL();
diff --git 
a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/pattern/DatePatternConverterTest.java
 
b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/pattern/DatePatternConverterTestBase.java
similarity index 91%
rename from 
log4j-core-test/src/test/java/org/apache/logging/log4j/core/pattern/DatePatternConverterTest.java
rename to 
log4j-core-test/src/test/java/org/apache/logging/log4j/core/pattern/DatePatternConverterTestBase.java
index 278305d252..b9680290a0 100644
--- 
a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/pattern/DatePatternConverterTest.java
+++ 
b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/pattern/DatePatternConverterTestBase.java
@@ -16,14 +16,11 @@
  */
 package org.apache.logging.log4j.core.pattern;
 
-import static org.junit.Assert.*;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
 
-import java.lang.reflect.Field;
-import java.lang.reflect.Modifier;
 import java.text.SimpleDateFormat;
-import java.util.Arrays;
 import java.util.Calendar;
-import java.util.Collection;
 import java.util.Date;
 import java.util.TimeZone;
 import org.apache.logging.log4j.core.AbstractLogEvent;
@@ -34,14 +31,11 @@ import org.apache.logging.log4j.core.util.Constants;
 import org.apache.logging.log4j.core.util.datetime.FixedDateFormat;
 import 
org.apache.logging.log4j.core.util.datetime.FixedDateFormat.FixedTimeZoneFormat;
 import org.apache.logging.log4j.util.Strings;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.Parameterized;
+import org.junit.jupiter.api.Test;
 
-@RunWith(Parameterized.class)
-public class DatePatternConverterTest {
+abstract class DatePatternConverterTestBase {
 
-    private class MyLogEvent extends AbstractLogEvent {
+    private static final class MyLogEvent extends AbstractLogEvent {
         private static final long serialVersionUID = 0;
 
         @Override
@@ -84,23 +78,10 @@ public class DatePatternConverterTest {
 
     private static final String[] ISO8601_FORMAT_OPTIONS = {ISO8601};
 
-    @Parameterized.Parameters(name = "threadLocalEnabled={0}")
-    public static Collection<Object[]> data() {
-        return Arrays.asList(new Object[][] {{Boolean.TRUE}, {Boolean.FALSE}});
-    }
-
-    public DatePatternConverterTest(final Boolean threadLocalEnabled) throws 
Exception {
-        // Setting the system property does not work: the Constant field has 
already been initialized...
-        // System.setProperty("log4j2.enable.threadlocals", 
threadLocalEnabled.toString());
-
-        final Field field = 
Constants.class.getDeclaredField("ENABLE_THREADLOCALS");
-        field.setAccessible(true); // make non-private
-
-        final Field modifiersField = Field.class.getDeclaredField("modifiers");
-        modifiersField.setAccessible(true);
-        modifiersField.setInt(field, field.getModifiers() & ~Modifier.FINAL); 
// make non-final
+    private final boolean threadLocalsEnabled;
 
-        field.setBoolean(null, threadLocalEnabled.booleanValue());
+    DatePatternConverterTestBase(final boolean threadLocalsEnabled) {
+        this.threadLocalsEnabled = threadLocalsEnabled;
     }
 
     private static Date date(final int year, final int month, final int date) {
@@ -118,6 +99,11 @@ public class DatePatternConverterTest {
         return seconds + "nnnnnnnnn".substring(0, precision) + remainder;
     }
 
+    @Test
+    void testThreadLocalsConstant() {
+        assertEquals(threadLocalsEnabled, Constants.ENABLE_THREADLOCALS);
+    }
+
     @Test
     public void testFormatDateStringBuilderDefaultPattern() {
         assertDatePattern(null, date(2001, 1, 1), "2001-02-01 14:15:16,123");
@@ -402,9 +388,9 @@ public class DatePatternConverterTest {
             final String expected = milliBuilder.append(tz).toString();
 
             assertEquals(
-                    "format = " + format + ", pattern = " + pattern + ", 
precisePattern = " + precisePattern,
                     expected,
-                    preciseBuilder.toString());
+                    preciseBuilder.toString(),
+                    "format = " + format + ", pattern = " + pattern + ", 
precisePattern = " + precisePattern);
             // System.out.println(preciseOptions[0] + ": " + precise);
         }
     }
@@ -428,7 +414,7 @@ public class DatePatternConverterTest {
                     if (pattern.endsWith("n")
                             || pattern.matches(".+n+X*")
                             || pattern.matches(".+n+Z*")
-                            || pattern.indexOf("SSS") < 0) {
+                            || !pattern.contains("SSS")) {
                         // ignore patterns that already have precise time 
formats
                         // ignore patterns that do not use seconds.
                         continue;
@@ -450,15 +436,13 @@ public class DatePatternConverterTest {
                                     milliBuilder.length() - 
timeZoneFormat.getLength(), milliBuilder.length())
                             : Strings.EMPTY;
                     milliBuilder.setLength(milliBuilder.length() - 
truncateLen); // truncate millis
-                    final String expected = milliBuilder
-                            .append("987123456".substring(0, i))
-                            .append(tz)
-                            .toString();
+                    final String expected =
+                            milliBuilder.append("987123456", 0, 
i).append(tz).toString();
 
                     assertEquals(
-                            "format = " + format + ", pattern = " + pattern + 
", precisePattern = " + precisePattern,
                             expected,
-                            preciseBuilder.toString());
+                            preciseBuilder.toString(),
+                            "format = " + format + ", pattern = " + pattern + 
", precisePattern = " + precisePattern);
                     // System.out.println(preciseOptions[0] + ": " + precise);
                 }
             }
diff --git 
a/log4j-api-test/src/test/java/org/apache/logging/log4j/NoopThreadContextTest.java
 
b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/pattern/DatePatternConverterWithThreadLocalsTest.java
similarity index 51%
copy from 
log4j-api-test/src/test/java/org/apache/logging/log4j/NoopThreadContextTest.java
copy to 
log4j-core-test/src/test/java/org/apache/logging/log4j/core/pattern/DatePatternConverterWithThreadLocalsTest.java
index 61add403b5..e116120a97 100644
--- 
a/log4j-api-test/src/test/java/org/apache/logging/log4j/NoopThreadContextTest.java
+++ 
b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/pattern/DatePatternConverterWithThreadLocalsTest.java
@@ -14,28 +14,17 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.logging.log4j;
+package org.apache.logging.log4j.core.pattern;
 
-import static org.junit.jupiter.api.Assertions.assertNull;
+import org.apache.logging.log4j.test.junit.SetTestProperty;
+import org.apache.logging.log4j.test.junit.UsingTestProperties;
 
-import org.apache.logging.log4j.test.junit.InitializesThreadContext;
-import org.apache.logging.log4j.test.junit.UsingThreadContextMap;
-import org.junit.jupiter.api.Test;
-import org.junitpioneer.jupiter.SetSystemProperty;
+@SetTestProperty(key = "log4j2.is.webapp", value = "false")
+@SetTestProperty(key = "log4j2.enable.threadlocals", value = "true")
+@UsingTestProperties
+class DatePatternConverterWithThreadLocalsTest extends 
DatePatternConverterTestBase {
 
-/**
- * Tests {@link ThreadContext}.
- */
-@SetSystemProperty(key = "log4j2.disableThreadContext", value = "true")
-@SetSystemProperty(key = "log4j2.disableThreadContextMap", value = "true")
-@InitializesThreadContext
-@UsingThreadContextMap
-public class NoopThreadContextTest {
-
-    @Test
-    public void testNoop() {
-        ThreadContext.put("Test", "Test");
-        final String value = ThreadContext.get("Test");
-        assertNull(value, "value was saved");
+    DatePatternConverterWithThreadLocalsTest() {
+        super(true);
     }
 }
diff --git 
a/log4j-api-test/src/test/java/org/apache/logging/log4j/NoopThreadContextTest.java
 
b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/pattern/DatePatternConverterWithoutThreadLocalsTest.java
similarity index 51%
copy from 
log4j-api-test/src/test/java/org/apache/logging/log4j/NoopThreadContextTest.java
copy to 
log4j-core-test/src/test/java/org/apache/logging/log4j/core/pattern/DatePatternConverterWithoutThreadLocalsTest.java
index 61add403b5..1559e28efb 100644
--- 
a/log4j-api-test/src/test/java/org/apache/logging/log4j/NoopThreadContextTest.java
+++ 
b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/pattern/DatePatternConverterWithoutThreadLocalsTest.java
@@ -14,28 +14,16 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.logging.log4j;
+package org.apache.logging.log4j.core.pattern;
 
-import static org.junit.jupiter.api.Assertions.assertNull;
+import org.apache.logging.log4j.test.junit.SetTestProperty;
+import org.apache.logging.log4j.test.junit.UsingTestProperties;
 
-import org.apache.logging.log4j.test.junit.InitializesThreadContext;
-import org.apache.logging.log4j.test.junit.UsingThreadContextMap;
-import org.junit.jupiter.api.Test;
-import org.junitpioneer.jupiter.SetSystemProperty;
+@SetTestProperty(key = "log4j2.enable.threadlocals", value = "false")
+@UsingTestProperties
+class DatePatternConverterWithoutThreadLocalsTest extends 
DatePatternConverterTestBase {
 
-/**
- * Tests {@link ThreadContext}.
- */
-@SetSystemProperty(key = "log4j2.disableThreadContext", value = "true")
-@SetSystemProperty(key = "log4j2.disableThreadContextMap", value = "true")
-@InitializesThreadContext
-@UsingThreadContextMap
-public class NoopThreadContextTest {
-
-    @Test
-    public void testNoop() {
-        ThreadContext.put("Test", "Test");
-        final String value = ThreadContext.get("Test");
-        assertNull(value, "value was saved");
+    DatePatternConverterWithoutThreadLocalsTest() {
+        super(false);
     }
 }
diff --git 
a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/util/ClockFactoryTest.java
 
b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/util/ClockFactoryTest.java
index 0cd0ae257b..aa3771c140 100644
--- 
a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/util/ClockFactoryTest.java
+++ 
b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/util/ClockFactoryTest.java
@@ -24,11 +24,7 @@ import org.apache.logging.log4j.core.async.AsyncLogger;
 import org.apache.logging.log4j.core.impl.Log4jLogEvent;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.condition.EnabledOnJre;
-import org.junit.jupiter.api.condition.JRE;
 
-// as of Java 12, final fields can no longer be overwritten via reflection
-@EnabledOnJre({JRE.JAVA_8, JRE.JAVA_9, JRE.JAVA_10, JRE.JAVA_11})
 public class ClockFactoryTest {
 
     public static void resetClocks() throws IllegalAccessException {
@@ -39,7 +35,6 @@ public class ClockFactoryTest {
     public static void resetClock(final Class<?> clazz) throws 
IllegalAccessException {
         System.clearProperty(ClockFactory.PROPERTY_NAME);
         final Field field = FieldUtils.getField(clazz, "CLOCK", true);
-        FieldUtils.removeFinalModifier(field);
         FieldUtils.writeStaticField(field, ClockFactory.getClock(), false);
     }
 
diff --git 
a/log4j-core/src/main/java/org/apache/logging/log4j/core/async/AsyncLogger.java 
b/log4j-core/src/main/java/org/apache/logging/log4j/core/async/AsyncLogger.java
index 1151a0a1dc..0378d010cc 100644
--- 
a/log4j-core/src/main/java/org/apache/logging/log4j/core/async/AsyncLogger.java
+++ 
b/log4j-core/src/main/java/org/apache/logging/log4j/core/async/AsyncLogger.java
@@ -69,7 +69,10 @@ public class AsyncLogger extends Logger implements 
EventTranslatorVararg<RingBuf
     // immediate inlining instead of waiting until they are designated "hot 
enough".
 
     private static final StatusLogger LOGGER = StatusLogger.getLogger();
-    private static final Clock CLOCK = ClockFactory.getClock(); // not 
reconfigurable
+
+    @SuppressWarnings("FieldMayBeFinal") // enable mutation for tests
+    private static Clock CLOCK = ClockFactory.getClock(); // not reconfigurable
+
     private static final ContextDataInjector CONTEXT_DATA_INJECTOR = 
ContextDataInjectorFactory.createInjector();
 
     private static final ThreadNameCachingStrategy 
THREAD_NAME_CACHING_STRATEGY = ThreadNameCachingStrategy.create();
diff --git 
a/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/Log4jLogEvent.java
 
b/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/Log4jLogEvent.java
index 2e3ec3e451..2c7c571fd6 100644
--- 
a/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/Log4jLogEvent.java
+++ 
b/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/Log4jLogEvent.java
@@ -55,7 +55,10 @@ import org.apache.logging.log4j.util.Strings;
 public class Log4jLogEvent implements LogEvent {
 
     private static final long serialVersionUID = -8393305700508709443L;
-    private static final Clock CLOCK = ClockFactory.getClock();
+
+    @SuppressWarnings("FieldMayBeFinal") // enable mutation for tests
+    private static Clock CLOCK = ClockFactory.getClock();
+
     private static volatile NanoClock nanoClock = new DummyNanoClock();
     private static final ContextDataInjector CONTEXT_DATA_INJECTOR = 
ContextDataInjectorFactory.createInjector();
 
diff --git a/log4j-jpa/pom.xml b/log4j-jpa/pom.xml
index 95f52cd080..54e535b2b6 100644
--- a/log4j-jpa/pom.xml
+++ b/log4j-jpa/pom.xml
@@ -100,15 +100,12 @@
 
   <build>
     <plugins>
+
+      <!-- Enable Log4j plugin processing -->
       <plugin>
         <groupId>org.apache.maven.plugins</groupId>
         <artifactId>maven-compiler-plugin</artifactId>
         <configuration>
-          <!--
-            ~ Modules that contain `log4j-core` plugins, must be compiled with:
-            ~
-            ~   
org.apache.logging.log4j.core.config.plugins.processor.PluginProcessor
-            -->
           <annotationProcessorPaths combine.children="append">
             <path>
               <groupId>org.apache.logging.log4j</groupId>
@@ -118,6 +115,46 @@
           </annotationProcessorPaths>
         </configuration>
       </plugin>
+
     </plugins>
   </build>
+
+  <profiles>
+
+    <!-- Fixes incompatible with Java 8 -->
+    <profile>
+
+      <id>java8-incompat-fixes</id>
+
+      <!-- CI uses Java 8 for running tests.
+           Hence, we assume CI=Java8 and apply our changes elsewhere.
+
+           One might think why not activate using `<jdk>[16,)` instead?
+           This doesn't work, since the match is not against "the JDK running 
tests", but "the JDK running Maven".
+           These two JDKs can differ due to Maven Toolchains.
+           See `java8-tests` profile in `/pom.xml` for details. -->
+      <activation>
+        <property>
+          <name>!env.CI</name>
+        </property>
+      </activation>
+
+      <!-- Illegal access is disabled by default in Java 16 due to JEP-396.
+           We are relaxing it for tests. -->
+      <build>
+        <plugins>
+          <plugin>
+            <groupId>org.apache.maven.plugins</groupId>
+            <artifactId>maven-surefire-plugin</artifactId>
+            <configuration>
+              <argLine>--add-opens java.base/java.lang=ALL-UNNAMED</argLine>
+            </configuration>
+          </plugin>
+        </plugins>
+      </build>
+
+    </profile>
+
+  </profiles>
+
 </project>
diff --git a/log4j-osgi-test/pom.xml b/log4j-osgi-test/pom.xml
index a9c4317790..b181d642cd 100644
--- a/log4j-osgi-test/pom.xml
+++ b/log4j-osgi-test/pom.xml
@@ -206,4 +206,43 @@
 
     </plugins>
   </build>
+
+  <profiles>
+
+    <!-- Fixes incompatible with Java 8 -->
+    <profile>
+
+      <id>java8-incompat-fixes</id>
+
+      <!-- CI uses Java 8 for running tests.
+           Hence, we assume CI=Java8 and apply our changes elsewhere.
+
+           One might think why not activate using `<jdk>[16,)` instead?
+           This doesn't work, since the match is not against "the JDK running 
tests", but "the JDK running Maven".
+           These two JDKs can differ due to Maven Toolchains.
+           See `java8-tests` profile in `/pom.xml` for details. -->
+      <activation>
+        <property>
+          <name>!env.CI</name>
+        </property>
+      </activation>
+
+      <!-- Illegal access is disabled by default in Java 16 due to JEP-396.
+           We are relaxing it for tests. -->
+      <build>
+        <plugins>
+          <plugin>
+            <groupId>org.apache.maven.plugins</groupId>
+            <artifactId>maven-surefire-plugin</artifactId>
+            <configuration>
+              <argLine>--add-opens java.base/java.net=ALL-UNNAMED</argLine>
+            </configuration>
+          </plugin>
+        </plugins>
+      </build>
+
+    </profile>
+
+  </profiles>
+
 </project>
diff --git a/log4j-parent/pom.xml b/log4j-parent/pom.xml
index 34ef4816c0..737245871e 100644
--- a/log4j-parent/pom.xml
+++ b/log4j-parent/pom.xml
@@ -130,6 +130,7 @@
     <maven.version>3.9.0</maven.version>
     <mockito.version>4.11.0</mockito.version>
     <mongodb.version>4.11.1</mongodb.version>
+    <nashorn.version>15.4</nashorn.version>
     <netty.version>4.1.101.Final</netty.version>
     <org.eclipse.osgi.version>3.13.0.v20180226-1711</org.eclipse.osgi.version>
     <org.eclipse.persistence.version>2.7.13</org.eclipse.persistence.version>
@@ -867,6 +868,12 @@
         <version>${mongodb.version}</version>
       </dependency>
 
+      <dependency>
+        <groupId>org.openjdk.nashorn</groupId>
+        <artifactId>nashorn-core</artifactId>
+        <version>${nashorn.version}</version>
+      </dependency>
+
       <dependency>
         <groupId>org.apache.felix</groupId>
         <artifactId>org.apache.felix.framework</artifactId>
diff --git a/pom.xml b/pom.xml
index 9fe502d261..e955ab921d 100644
--- a/pom.xml
+++ b/pom.xml
@@ -309,10 +309,6 @@
     <!-- =================
          Common properties
          ================= -->
-    <maven.compiler.release>8</maven.compiler.release>
-    <maven.compiler.target>${maven.compiler.release}</maven.compiler.target>
-    <!-- JDK version of the main Maven process (used in ASF parent POM) -->
-    <minimalJavaBuildVersion>[11,12)</minimalJavaBuildVersion>
     <module.name />
 
     <!-- `project.build.outputTimestamp` is required to be present for 
reproducible builds.
diff --git a/src/changelog/.2.x.x/java_17.xml b/src/changelog/.2.x.x/java_17.xml
new file mode 100644
index 0000000000..fd91bd6be5
--- /dev/null
+++ b/src/changelog/.2.x.x/java_17.xml
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  ~ Licensed to the Apache Software Foundation (ASF) under one or more
+  ~ contributor license agreements.  See the NOTICE file distributed with
+  ~ this work for additional information regarding copyright ownership.
+  ~ The ASF licenses this file to you under the Apache License, Version 2.0
+  ~ (the "License"); you may not use this file except in compliance with
+  ~ the License.  You may obtain a copy of the License at
+  ~
+  ~      http://www.apache.org/licenses/LICENSE-2.0
+  ~
+  ~ Unless required by applicable law or agreed to in writing, software
+  ~ distributed under the License is distributed on an "AS IS" BASIS,
+  ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  ~ See the License for the specific language governing permissions and
+  ~ limitations under the License.
+  -->
+<entry xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+       xmlns="http://logging.apache.org/log4j/changelog";
+       xsi:schemaLocation="http://logging.apache.org/log4j/changelog 
https://logging.apache.org/log4j/changelog-0.1.2.xsd";
+       type="changed">
+  <issue id="2021" 
link="https://github.com/apache/logging-log4j2/issues/2021"/>
+  <description format="asciidoc">
+    Bumped the minimum Java version required for the build to Java 17. Runtime 
requirements remain unchanged.
+  </description>
+</entry>
diff --git a/src/site/_constants.adoc b/src/site/_constants.adoc
index 8e500fa73d..d321d39568 100644
--- a/src/site/_constants.adoc
+++ b/src/site/_constants.adoc
@@ -38,4 +38,4 @@
 :project-name: Log4j
 :project-id: log4j
 :java-target-version: 8
-:java-compiler-version: [11,12)
+:java-compiler-version: [17,18)
diff --git a/src/site/_release-notes/_2.x.x.adoc 
b/src/site/_release-notes/_2.x.x.adoc
index 44ca474139..613779fad4 100644
--- a/src/site/_release-notes/_2.x.x.adoc
+++ b/src/site/_release-notes/_2.x.x.adoc
@@ -26,6 +26,7 @@ This releases contains ...
 [#release-notes-2-x-x-changed]
 === Changed
 
+* Bumped the minimum Java version required for the build to Java 17. Runtime 
requirements remain unchanged. 
(https://github.com/apache/logging-log4j2/issues/2021[2021])
 * Update `ch.qos.logback:logback-classic` to version `1.3.13` 
(https://github.com/apache/logging-log4j2/pull/2017[2017])
 * Update `de.flapdoodle.reverse:de.flapdoodle.reverse` to version `1.7.2` 
(https://github.com/apache/logging-log4j2/pull/1979[1979])
 * Update `github/codeql-action` to version `2.22.8` 
(https://github.com/apache/logging-log4j2/pull/2005[2005])


Reply via email to