Skip to content

Commit 77245dd

Browse files
committed
Upgrade both JDK and JRE requirements to Java 17
1 parent 19d64c3 commit 77245dd

File tree

18 files changed

+196
-52
lines changed

18 files changed

+196
-52
lines changed

.github/workflows/build.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ jobs:
4040
if: github.actor != 'dependabot[bot]'
4141
uses: apache/logging-parent/.github/workflows/build-reusable.yaml@main
4242
with:
43-
java-version: 11
43+
java-version: 17
4444
site-enabled: true
4545

4646
deploy-snapshot:
@@ -52,7 +52,7 @@ jobs:
5252
NEXUS_USER: ${{ secrets.NEXUS_USER }}
5353
NEXUS_PW: ${{ secrets.NEXUS_PW }}
5454
with:
55-
java-version: 11
55+
java-version: 17
5656

5757
deploy-release:
5858
needs: build
@@ -69,6 +69,6 @@ jobs:
6969
permissions:
7070
contents: write
7171
with:
72-
java-version: 11
72+
java-version: 17
7373
project-id: log4j
7474
site-enabled: true

.github/workflows/codeql-analysis.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ jobs:
3232
analyze:
3333
uses: apache/logging-parent/.github/workflows/codeql-analysis-reusable.yaml@main
3434
with:
35-
java-version: 11
35+
java-version: 17
3636
# Permissions required to publish Security Alerts
3737
permissions:
3838
actions: read

.github/workflows/merge-dependabot.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,13 @@ jobs:
3232
if: github.repository == 'apache/logging-log4j2' && github.event_name == 'pull_request_target' && github.actor == 'dependabot[bot]'
3333
uses: apache/logging-parent/.github/workflows/build-reusable.yaml@main
3434
with:
35-
java-version: 11
35+
java-version: 17
3636

3737
merge-dependabot:
3838
needs: build
3939
uses: apache/logging-parent/.github/workflows/merge-dependabot-reusable.yaml@main
4040
with:
41-
java-version: 11
41+
java-version: 17
4242
permissions:
4343
contents: write # to push changelog commits
4444
pull-requests: write # to close the PR

.java-version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
11
1+
17

BUILDING.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
[#requirements]
1919
== Requirements
2020
21-
* JDK 11+
21+
* JDK 17+
2222
* A modern Linux, OSX, or Windows host
2323
2424
[#building]

log4j-1.2-api/pom.xml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,8 @@
132132

133133
<build>
134134
<plugins>
135+
136+
<!-- Enable Log4j plugin processing -->
135137
<plugin>
136138
<groupId>org.apache.maven.plugins</groupId>
137139
<artifactId>maven-compiler-plugin</artifactId>
@@ -145,6 +147,18 @@
145147
</annotationProcessorPaths>
146148
</configuration>
147149
</plugin>
150+
151+
<!-- Illegal access is disabled by default in Java 16 due to JEP-396.
152+
We are relaxing it for tests. -->
153+
<plugin>
154+
<groupId>org.apache.maven.plugins</groupId>
155+
<artifactId>maven-surefire-plugin</artifactId>
156+
<configuration>
157+
<argLine>--add-opens java.base/java.io=ALL-UNNAMED</argLine>
158+
</configuration>
159+
</plugin>
160+
148161
</plugins>
149162
</build>
163+
150164
</project>

log4j-core-test/pom.xml

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,13 @@
276276
<artifactId>mockito-junit-jupiter</artifactId>
277277
<scope>test</scope>
278278
</dependency>
279+
<!-- JEP-335 has deprecated the built-in JavaScript engine (Nashorn) in Java 11, and JEP-372 removed it in Java 15.
280+
We are adding it back for tests that use JavaScript. -->
281+
<dependency>
282+
<groupId>org.openjdk.nashorn</groupId>
283+
<artifactId>nashorn-core</artifactId>
284+
<scope>test</scope>
285+
</dependency>
279286
<!-- SLF4J tests -->
280287
<dependency>
281288
<groupId>org.slf4j</groupId>
@@ -313,6 +320,7 @@
313320
<build>
314321
<plugins>
315322

323+
<!-- Enable Log4j plugin processing -->
316324
<plugin>
317325
<groupId>org.apache.maven.plugins</groupId>
318326
<artifactId>maven-compiler-plugin</artifactId>
@@ -350,14 +358,11 @@
350358
<groupId>org.apache.maven.plugins</groupId>
351359
<artifactId>maven-surefire-plugin</artifactId>
352360
<configuration>
353-
<argLine>
354-
<!--
355-
~ Allow environment modification:
356-
~ https://junit-pioneer.org/docs/environment-variables/#warnings-for-reflective-access
357-
-->
358-
--add-opens java.base/java.util=ALL-UNNAMED
359-
--add-opens java.base/java.lang=ALL-UNNAMED
360-
</argLine>
361+
<!-- Illegal access is disabled by default in Java 16 due to JEP-396.
362+
We are relaxing it for tests. -->
363+
<argLine>--add-opens java.base/java.lang=ALL-UNNAMED
364+
--add-opens java.base/java.net=ALL-UNNAMED
365+
--add-opens java.base/java.util=ALL-UNNAMED</argLine>
361366
<runOrder>random</runOrder>
362367
<systemPropertyVariables>
363368
<Web.isWebApp>false</Web.isWebApp>

log4j-core-test/src/test/java/org/apache/logging/log4j/core/net/UrlConnectionFactoryTest.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,10 @@
5757
import org.junit.jupiter.api.AfterAll;
5858
import org.junit.jupiter.api.BeforeAll;
5959
import org.junit.jupiter.api.Test;
60+
import org.junit.jupiter.api.condition.DisabledOnOs;
61+
import org.junit.jupiter.api.condition.OS;
6062
import org.junit.jupiter.api.parallel.Isolated;
63+
import org.junitpioneer.jupiter.RetryingTest;
6164

6265
/**
6366
* Tests the UrlConnectionFactory
@@ -142,7 +145,8 @@ private int verifyNotModified(final URI uri, final long lastModifiedMillis) thro
142145
}
143146
}
144147

145-
@Test
148+
@RetryingTest(maxAttempts = 5, suspendForMs = 1000)
149+
@DisabledOnOs(value = OS.WINDOWS, disabledReason = "Fails frequently on Windows (#2011)")
146150
public void testNoJarFileLeak() throws Exception {
147151
ConfigurationSourceTest.prepareJarConfigURL();
148152
final URL url = new File("target/test-classes/jarfile.jar").toURI().toURL();

log4j-core-test/src/test/java/org/apache/logging/log4j/core/pattern/DatePatternConverterTest.java renamed to log4j-core-test/src/test/java/org/apache/logging/log4j/core/pattern/DatePatternConverterTestBase.java

Lines changed: 20 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,11 @@
1616
*/
1717
package org.apache.logging.log4j.core.pattern;
1818

19-
import static org.junit.Assert.assertEquals;
20-
import static org.junit.Assert.assertNull;
19+
import static org.junit.jupiter.api.Assertions.assertEquals;
20+
import static org.junit.jupiter.api.Assertions.assertNull;
2121

2222
import java.text.SimpleDateFormat;
23-
import java.util.Arrays;
2423
import java.util.Calendar;
25-
import java.util.Collection;
2624
import java.util.Date;
2725
import java.util.TimeZone;
2826
import org.apache.logging.log4j.core.AbstractLogEvent;
@@ -33,14 +31,11 @@
3331
import org.apache.logging.log4j.core.time.internal.format.FixedDateFormat.FixedTimeZoneFormat;
3432
import org.apache.logging.log4j.util.Constants;
3533
import org.apache.logging.log4j.util.Strings;
36-
import org.junit.Test;
37-
import org.junit.runner.RunWith;
38-
import org.junit.runners.Parameterized;
34+
import org.junit.jupiter.api.Test;
3935

40-
@RunWith(Parameterized.class)
41-
public class DatePatternConverterTest {
36+
abstract class DatePatternConverterTestBase {
4237

43-
private static class MyLogEvent extends AbstractLogEvent {
38+
private static final class MyLogEvent extends AbstractLogEvent {
4439

4540
@Override
4641
public Instant getInstant() {
@@ -82,13 +77,10 @@ public long getTimeMillis() {
8277

8378
private static final String[] ISO8601_FORMAT_OPTIONS = {ISO8601};
8479

85-
@Parameterized.Parameters(name = "threadLocalEnabled={0}")
86-
public static Collection<Object[]> data() {
87-
return Arrays.asList(new Object[][] {{Boolean.TRUE}, {Boolean.FALSE}});
88-
}
80+
private final boolean threadLocalsEnabled;
8981

90-
public DatePatternConverterTest(final Boolean threadLocalEnabled) {
91-
Constants.setThreadLocalsEnabled(threadLocalEnabled);
82+
DatePatternConverterTestBase(final boolean threadLocalsEnabled) {
83+
this.threadLocalsEnabled = threadLocalsEnabled;
9284
}
9385

9486
private static Date date(final int year, final int month, final int date) {
@@ -106,6 +98,11 @@ private String precisePattern(final String pattern, final int precision) {
10698
return seconds + "nnnnnnnnn".substring(0, precision) + remainder;
10799
}
108100

101+
@Test
102+
void testThreadLocalsConstant() {
103+
assertEquals(threadLocalsEnabled, Constants.isThreadLocalsEnabled());
104+
}
105+
109106
@Test
110107
public void testFormatDateStringBuilderDefaultPattern() {
111108
assertDatePattern(null, date(2001, 1, 1), "2001-02-01 14:15:16,123");
@@ -390,9 +387,9 @@ public void testInvalidLongPatternIgnoresExcessiveDigits() {
390387
final String expected = milliBuilder.append(tz).toString();
391388

392389
assertEquals(
393-
"format = " + format + ", pattern = " + pattern + ", precisePattern = " + precisePattern,
394390
expected,
395-
preciseBuilder.toString());
391+
preciseBuilder.toString(),
392+
"format = " + format + ", pattern = " + pattern + ", precisePattern = " + precisePattern);
396393
// System.out.println(preciseOptions[0] + ": " + precise);
397394
}
398395
}
@@ -416,7 +413,7 @@ public void testPredefinedFormatWithAnyValidNanoPrecision() {
416413
if (pattern.endsWith("n")
417414
|| pattern.matches(".+n+X*")
418415
|| pattern.matches(".+n+Z*")
419-
|| pattern.indexOf("SSS") < 0) {
416+
|| !pattern.contains("SSS")) {
420417
// ignore patterns that already have precise time formats
421418
// ignore patterns that do not use seconds.
422419
continue;
@@ -438,15 +435,13 @@ public void testPredefinedFormatWithAnyValidNanoPrecision() {
438435
milliBuilder.length() - timeZoneFormat.getLength(), milliBuilder.length())
439436
: Strings.EMPTY;
440437
milliBuilder.setLength(milliBuilder.length() - truncateLen); // truncate millis
441-
final String expected = milliBuilder
442-
.append("987123456".substring(0, i))
443-
.append(tz)
444-
.toString();
438+
final String expected =
439+
milliBuilder.append("987123456", 0, i).append(tz).toString();
445440

446441
assertEquals(
447-
"format = " + format + ", pattern = " + pattern + ", precisePattern = " + precisePattern,
448442
expected,
449-
preciseBuilder.toString());
443+
preciseBuilder.toString(),
444+
"format = " + format + ", pattern = " + pattern + ", precisePattern = " + precisePattern);
450445
// System.out.println(preciseOptions[0] + ": " + precise);
451446
}
452447
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to you under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package org.apache.logging.log4j.core.pattern;
18+
19+
import org.apache.logging.log4j.spi.LoggingSystemProperty;
20+
import org.apache.logging.log4j.test.junit.SetTestProperty;
21+
import org.apache.logging.log4j.test.junit.UsingTestProperties;
22+
23+
@SetTestProperty(key = LoggingSystemProperty.Constant.WEB_IS_WEBAPP, value = "false")
24+
@SetTestProperty(key = LoggingSystemProperty.Constant.THREAD_LOCALS_ENABLE, value = "true")
25+
@UsingTestProperties
26+
class DatePatternConverterWithThreadLocalsTest extends DatePatternConverterTestBase {
27+
28+
DatePatternConverterWithThreadLocalsTest() {
29+
super(true);
30+
}
31+
}

0 commit comments

Comments
 (0)