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 13f504b7053..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.getInstance(); - 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 2e2c7393dc5..ccfb8f20bcb 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 @@ -47,8 +47,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> strLookups = new ConcurrentHashMap<>(); @@ -79,11 +77,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-jakarta-web` module " 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 d14499f1dd0..00000000000 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/lookup/JmxRuntimeInputArgumentsLookup.java +++ /dev/null @@ -1,73 +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.Map; -import org.apache.logging.log4j.Logger; -import org.apache.logging.log4j.core.LogEvent; -import org.apache.logging.log4j.core.util.internal.SystemUtils; -import org.apache.logging.log4j.plugins.Plugin; -import org.apache.logging.log4j.plugins.PluginFactory; -import org.apache.logging.log4j.status.StatusLogger; -import org.apache.logging.log4j.util.Lazy; - -/** - * Maps JVM input arguments (but not main arguments) using JMX to acquire JVM arguments. - * - * @see java.lang.management.RuntimeMXBean#getInputArguments() - * @since 2.1 - */ -@Lookup -@Plugin("jvmrunargs") -public class JmxRuntimeInputArgumentsLookup extends MapLookup { - - private static final Logger LOGGER = StatusLogger.getLogger(); - - private static final Lazy INSTANCE = Lazy.lazy(() -> { - return new JmxRuntimeInputArgumentsLookup(getMapFromJmx()); - }); - - @PluginFactory - public static JmxRuntimeInputArgumentsLookup getInstance() { - return INSTANCE.get(); - } - - 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 Map.of(); - } -} diff --git a/src/changelog/.3.x.x/3874_remove_jvmrunargs_lookup.xml b/src/changelog/.3.x.x/3874_remove_jvmrunargs_lookup.xml new file mode 100644 index 00000000000..ef0c2850bed --- /dev/null +++ b/src/changelog/.3.x.x/3874_remove_jvmrunargs_lookup.xml @@ -0,0 +1,13 @@ + + + + + + Remove the `jvmrunargs` lookup. + +