diff --git a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/lookup/MainInputArgumentsJmxLookupTest.java b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/lookup/MainInputArgumentsJmxLookupTest.java deleted file mode 100644 index fd60f1cc6e5..00000000000 --- a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/lookup/MainInputArgumentsJmxLookupTest.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * 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. - */ -package org.apache.logging.log4j.core.lookup; - -import static org.junit.jupiter.api.Assertions.assertNull; - -import java.util.Map; - -/** - * Tests {@link JmxRuntimeInputArgumentsLookup} from the command line, not a JUnit test. - * - * From an IDE or CLI: --file foo.txt - * - * @since 2.1 - */ -public class MainInputArgumentsJmxLookupTest { - - public static void main(final String[] args) { - new MainInputArgumentsJmxLookupTest().callFromMain(); - } - - public void callFromMain() { - final JmxRuntimeInputArgumentsLookup lookup = JmxRuntimeInputArgumentsLookup.JMX_SINGLETON; - String result1 = null; - assertNull(result1); - String result = null; - final Map map = lookup.getMap(); - result = map == null ? null : map.get("X"); - assertNull(result); - // Eclipse adds -Dfile.encoding=Cp1252 - // assertEquals("--file", lookup.lookup("0")); - // assertEquals("foo.txt", lookup.lookup("1")); - // - // JMX does not include the main arguments. - // assertEquals("foo.txt", lookup.lookup("--file")); - // assertEquals(null, lookup.lookup("foo.txt")); - } -} diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/lookup/Interpolator.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/lookup/Interpolator.java index 41f270aac6b..ce6354ad064 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/lookup/Interpolator.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/lookup/Interpolator.java @@ -53,8 +53,6 @@ public class Interpolator extends AbstractConfigurationAwareLookup implements Lo private static final String LOOKUP_KEY_JNDI = "jndi"; - private static final String LOOKUP_KEY_JVMRUNARGS = "jvmrunargs"; - private static final Logger LOGGER = StatusLogger.getLogger(); private final Map strLookupMap = new HashMap<>(); @@ -126,11 +124,6 @@ private void handleError(final String lookupKey, final Throwable t) { + " JNDI string lookups will not be available, continuing configuration. Ignoring " + t); break; - case LOOKUP_KEY_JVMRUNARGS: - // java.lang.VerifyError: org/apache/logging/log4j/core/lookup/JmxRuntimeInputArgumentsLookup - LOGGER.warn("JMX runtime input lookup class is not available because this JRE does not support JMX. " - + "JMX lookups will not be available, continuing configuration. Ignoring " + t); - break; case LOOKUP_KEY_WEB: LOGGER.info("Log4j appears to be running in a Servlet environment, but there's no log4j-web module " + "available. If you want better web container support, please add the log4j-web JAR to your " diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/lookup/JmxRuntimeInputArgumentsLookup.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/lookup/JmxRuntimeInputArgumentsLookup.java deleted file mode 100644 index 6fcf5435182..00000000000 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/lookup/JmxRuntimeInputArgumentsLookup.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * 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. - */ -package org.apache.logging.log4j.core.lookup; - -import java.lang.management.ManagementFactory; -import java.util.Collections; -import java.util.Map; -import org.apache.logging.log4j.Logger; -import org.apache.logging.log4j.core.LogEvent; -import org.apache.logging.log4j.core.config.plugins.Plugin; -import org.apache.logging.log4j.core.util.internal.SystemUtils; -import org.apache.logging.log4j.status.StatusLogger; - -/** - * Maps JVM input arguments (but not main arguments) using JMX to acquire JVM arguments. - * - * @see java.lang.management.RuntimeMXBean#getInputArguments() - * @since 2.1 - */ -@Plugin(name = "jvmrunargs", category = StrLookup.CATEGORY) -public class JmxRuntimeInputArgumentsLookup extends MapLookup { - - private static final Logger LOGGER = StatusLogger.getLogger(); - - public static final JmxRuntimeInputArgumentsLookup JMX_SINGLETON = new JmxRuntimeInputArgumentsLookup(); - - /** - * Constructor when used directly as a plugin. - */ - public JmxRuntimeInputArgumentsLookup() { - this(getMapFromJmx()); - } - - public JmxRuntimeInputArgumentsLookup(final Map map) { - super(map); - } - - @Override - public String lookup(final LogEvent ignored, final String key) { - if (key == null) { - return null; - } - final Map map = getMap(); - return map == null ? null : map.get(key); - } - - private static Map getMapFromJmx() { - if (!SystemUtils.isOsAndroid()) { - try { - return MapLookup.toMap(ManagementFactory.getRuntimeMXBean().getInputArguments()); - } catch (LinkageError e) { - LOGGER.warn("Failed to get JMX arguments from JVM.", e); - } - } - return Collections.emptyMap(); - } -} diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/lookup/package-info.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/lookup/package-info.java index 97fc2f0c6d1..47fab504b64 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/lookup/package-info.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/lookup/package-info.java @@ -20,9 +20,11 @@ * {@linkplain org.apache.logging.log4j.core.config.plugins.Plugin#category() plugin category} * {@link org.apache.logging.log4j.core.lookup.StrLookup#CATEGORY Lookup}. */ +@BaselineIgnore("2.26.0") @Export -@Version("2.24.1") +@Version("2.26.0") package org.apache.logging.log4j.core.lookup; +import aQute.bnd.annotation.baseline.BaselineIgnore; import org.osgi.annotation.bundle.Export; import org.osgi.annotation.versioning.Version; diff --git a/src/changelog/.2.x.x/3874_remove_jvmrunargs_lookup.xml b/src/changelog/.2.x.x/3874_remove_jvmrunargs_lookup.xml new file mode 100644 index 00000000000..ef0c2850bed --- /dev/null +++ b/src/changelog/.2.x.x/3874_remove_jvmrunargs_lookup.xml @@ -0,0 +1,13 @@ + + + + + + Remove the `jvmrunargs` lookup. + +