This is an automated email from the ASF dual-hosted git repository. pkarwasz pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git
commit d5a05bdb6b6d683c2e8d2d807151351a3818c073 Author: Piotr P. Karwasz <[email protected]> AuthorDate: Mon Nov 20 21:51:40 2023 +0100 Apply OpenRewrite Java 11 migration Apply OpenRewrite's "Migrate from Java 8 to Java 11" recipe. This is part of #1706. --- .../log4j/message/ReusableMessageFactoryTest.java | 32 +++++++++++----------- .../org/apache/logging/log4j/util/Unbox1Test.java | 22 ++++++++------- .../log4j/core/tools/picocli/CommandLine.java | 4 +-- .../apache/logging/log4j/taglib/TagLevelTest.java | 2 +- pom.xml | 2 +- 5 files changed, 32 insertions(+), 30 deletions(-) diff --git a/log4j-api-test/src/test/java/org/apache/logging/log4j/message/ReusableMessageFactoryTest.java b/log4j-api-test/src/test/java/org/apache/logging/log4j/message/ReusableMessageFactoryTest.java index 171c0363b5..c0ae795a8c 100644 --- a/log4j-api-test/src/test/java/org/apache/logging/log4j/message/ReusableMessageFactoryTest.java +++ b/log4j-api-test/src/test/java/org/apache/logging/log4j/message/ReusableMessageFactoryTest.java @@ -73,19 +73,19 @@ public class ReusableMessageFactoryTest { public void testCreateEventOverwritesFields() throws Exception { final Message message1 = factory.newMessage("text, p0={} p1={} p2={} p3={}", 1, 2, 3, 4); assertReusableParameterizeMessage(message1, "text, p0={} p1={} p2={} p3={}", new Object[] { - new Integer(1), // - new Integer(2), // - new Integer(3), // - new Integer(4), // + Integer.valueOf(1), // + Integer.valueOf(2), // + Integer.valueOf(3), // + Integer.valueOf(4), // }); factory.recycle(message1); final Message message2 = factory.newMessage("other, A={} B={} C={} D={}", 1, 2, 3, 4); assertReusableParameterizeMessage(message1, "other, A={} B={} C={} D={}", new Object[] { - new Integer(1), // - new Integer(2), // - new Integer(3), // - new Integer(4), // + Integer.valueOf(1), // + Integer.valueOf(2), // + Integer.valueOf(3), // + Integer.valueOf(4), // }); assertSame(message1, message2); factory.recycle(message2); @@ -115,17 +115,17 @@ public class ReusableMessageFactoryTest { assertNotNull(message2[0]); assertNotSame(message1[0], message2[0]); assertReusableParameterizeMessage(message1[0], "text, p0={} p1={} p2={} p3={}", new Object[] { - new Integer(1), // - new Integer(2), // - new Integer(3), // - new Integer(4), // + Integer.valueOf(1), // + Integer.valueOf(2), // + Integer.valueOf(3), // + Integer.valueOf(4), // }); assertReusableParameterizeMessage(message2[0], "other, A={} B={} C={} D={}", new Object[] { - new Integer(1), // - new Integer(2), // - new Integer(3), // - new Integer(4), // + Integer.valueOf(1), // + Integer.valueOf(2), // + Integer.valueOf(3), // + Integer.valueOf(4), // }); factory.recycle(message1[0]); factory.recycle(message2[0]); diff --git a/log4j-api-test/src/test/java/org/apache/logging/log4j/util/Unbox1Test.java b/log4j-api-test/src/test/java/org/apache/logging/log4j/util/Unbox1Test.java index ed02927f85..4355d4c557 100644 --- a/log4j-api-test/src/test/java/org/apache/logging/log4j/util/Unbox1Test.java +++ b/log4j-api-test/src/test/java/org/apache/logging/log4j/util/Unbox1Test.java @@ -87,10 +87,10 @@ public class Unbox1Test { public void testBoxDouble() { assertEquals("3.14", Unbox.box(3.14).toString()); assertEquals( - new Double(Double.MAX_VALUE).toString(), + Double.valueOf(Double.MAX_VALUE).toString(), Unbox.box(Double.MAX_VALUE).toString()); assertEquals( - new Double(Double.MIN_VALUE).toString(), + Double.valueOf(Double.MIN_VALUE).toString(), Unbox.box(Double.MIN_VALUE).toString()); } @@ -98,10 +98,10 @@ public class Unbox1Test { public void testBoxFloat() { assertEquals("3.14", Unbox.box(3.14F).toString()); assertEquals( - new Float(Float.MAX_VALUE).toString(), + Float.valueOf(Float.MAX_VALUE).toString(), Unbox.box(Float.MAX_VALUE).toString()); assertEquals( - new Float(Float.MIN_VALUE).toString(), + Float.valueOf(Float.MIN_VALUE).toString(), Unbox.box(Float.MIN_VALUE).toString()); } @@ -113,10 +113,10 @@ public class Unbox1Test { assertEquals("-1", Unbox.box(-1).toString()); assertEquals("-128", Unbox.box(-128).toString()); assertEquals( - new Integer(Integer.MAX_VALUE).toString(), + Integer.valueOf(Integer.MAX_VALUE).toString(), Unbox.box(Integer.MAX_VALUE).toString()); assertEquals( - new Integer(Integer.MIN_VALUE).toString(), + Integer.valueOf(Integer.MIN_VALUE).toString(), Unbox.box(Integer.MIN_VALUE).toString()); } @@ -128,9 +128,11 @@ public class Unbox1Test { assertEquals("-1", Unbox.box(-1L).toString()); assertEquals("-128", Unbox.box(-128L).toString()); assertEquals( - new Long(Long.MAX_VALUE).toString(), Unbox.box(Long.MAX_VALUE).toString()); + Long.valueOf(Long.MAX_VALUE).toString(), + Unbox.box(Long.MAX_VALUE).toString()); assertEquals( - new Long(Long.MIN_VALUE).toString(), Unbox.box(Long.MIN_VALUE).toString()); + Long.valueOf(Long.MIN_VALUE).toString(), + Unbox.box(Long.MIN_VALUE).toString()); } @Test @@ -141,10 +143,10 @@ public class Unbox1Test { assertEquals("-1", Unbox.box((short) -1).toString()); assertEquals("-128", Unbox.box((short) -128).toString()); assertEquals( - new Short(Short.MAX_VALUE).toString(), + Short.valueOf(Short.MAX_VALUE).toString(), Unbox.box(Short.MAX_VALUE).toString()); assertEquals( - new Short(Short.MIN_VALUE).toString(), + Short.valueOf(Short.MIN_VALUE).toString(), Unbox.box(Short.MIN_VALUE).toString()); } diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/tools/picocli/CommandLine.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/tools/picocli/CommandLine.java index 8681229047..37b5b46bf2 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/tools/picocli/CommandLine.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/tools/picocli/CommandLine.java @@ -2891,12 +2891,12 @@ public class CommandLine { return new ArrayList<Object>(); } // custom Collection implementation class must have default constructor - return (Collection<Object>) collectionClass.newInstance(); + return (Collection<Object>) collectionClass.getDeclaredConstructor().newInstance(); } private Map<Object, Object> createMap(final Class<?> mapClass) throws Exception { try { // if it is an implementation class, instantiate it - return (Map<Object, Object>) mapClass.newInstance(); + return (Map<Object, Object>) mapClass.getDeclaredConstructor().newInstance(); } catch (final Exception ignored) { } return new LinkedHashMap<Object, Object>(); diff --git a/log4j-taglib/src/test/java/org/apache/logging/log4j/taglib/TagLevelTest.java b/log4j-taglib/src/test/java/org/apache/logging/log4j/taglib/TagLevelTest.java index db40aeb5e2..d680526b55 100644 --- a/log4j-taglib/src/test/java/org/apache/logging/log4j/taglib/TagLevelTest.java +++ b/log4j-taglib/src/test/java/org/apache/logging/log4j/taglib/TagLevelTest.java @@ -50,6 +50,6 @@ public class TagLevelTest { @Test public void testGetLevel() throws Exception { - assertEquals(level, cls.newInstance().getLevel()); + assertEquals(level, cls.getDeclaredConstructor().newInstance().getLevel()); } } diff --git a/pom.xml b/pom.xml index 68b44e401f..2b816bb2f2 100644 --- a/pom.xml +++ b/pom.xml @@ -317,7 +317,7 @@ Common properties ================= --> <manifestfile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestfile> - <maven.compiler.release>8</maven.compiler.release> + <maven.compiler.release>11</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>
