It is only used at configuration start, hence I don't think it is needed. Nevertheless, I have replaced it with Strings.EMPTY_ARRAY.
On Mon, Dec 13, 2021 at 12:39 PM Gary Gregory <[email protected]> wrote: > + return new String[0]; > > This should be a constant. > > Gary > > On Mon, Dec 13, 2021 at 6:35 AM <[email protected]> wrote: > > > This is an automated email from the ASF dual-hosted git repository. > > > > vy pushed a commit to branch release-2.x > > in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git > > > > > > The following commit(s) were added to refs/heads/release-2.x by this > push: > > new ad0d0c9 Remove SetUtils from core. > > ad0d0c9 is described below > > > > commit ad0d0c900f75961691eb98065453deca7ade5419 > > Author: Volkan Yazici <[email protected]> > > AuthorDate: Sun Dec 12 21:14:12 2021 +0100 > > > > Remove SetUtils from core. > > --- > > log4j-core/revapi.json | 5 +++ > > .../apache/logging/log4j/core/util/SetUtils.java | 47 > > ---------------------- > > .../logging/log4j/web/Log4jWebInitializerImpl.java | 40 > +++++++++++------- > > .../logging/log4j/web/Log4jWebInitializerImpl.java | 42 > > ++++++++++++------- > > 4 files changed, 58 insertions(+), 76 deletions(-) > > > > diff --git a/log4j-core/revapi.json b/log4j-core/revapi.json > > index af702c0..95e6d71 100644 > > --- a/log4j-core/revapi.json > > +++ b/log4j-core/revapi.json > > @@ -152,6 +152,11 @@ > > "old": "class > org.apache.logging.log4j.core.time.MutableInstant", > > "new": "class > org.apache.logging.log4j.core.time.MutableInstant", > > "justification": "LOG4J2-3075 MutableInstant extends from > > TemporalAccessor" > > + }, > > + { > > + "code": "java.class.removed", > > + "old": "class org.apache.logging.log4j.core.util.SetUtils", > > + "justification": "only used by web modules" > > } > > ] > > } > > diff --git > > > a/log4j-core/src/main/java/org/apache/logging/log4j/core/util/SetUtils.java > > > b/log4j-core/src/main/java/org/apache/logging/log4j/core/util/SetUtils.java > > deleted file mode 100644 > > index e1a5218..0000000 > > --- > > > a/log4j-core/src/main/java/org/apache/logging/log4j/core/util/SetUtils.java > > +++ /dev/null > > @@ -1,47 +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.util; > > - > > -import java.util.Set; > > - > > -/** > > - * Set-related convenience methods. > > - */ > > -public final class SetUtils { > > - > > - private static final String[] EMPTY_STRINGS = new String[0]; > > - > > - private SetUtils() {} > > - > > - /** > > - * Collects strings starting with the given {@code prefix} from the > > given {@code set}. > > - * > > - * @param set a (nullable) set of strings > > - * @param prefix a prefix to look for in the string set > > - * @return an array of the matching strings from the given set > > - */ > > - public static String[] prefixSet(final Set<String> set, final String > > prefix) { > > - if (set == null) { > > - return EMPTY_STRINGS; > > - } > > - return set > > - .stream() > > - .filter(string -> string.startsWith(prefix)) > > - .toArray(String[]::new); > > - } > > - > > -} > > diff --git > > > a/log4j-jakarta-web/src/main/java/org/apache/logging/log4j/web/Log4jWebInitializerImpl.java > > > b/log4j-jakarta-web/src/main/java/org/apache/logging/log4j/web/Log4jWebInitializerImpl.java > > index 3ecbe14..5279df9 100644 > > --- > > > a/log4j-jakarta-web/src/main/java/org/apache/logging/log4j/web/Log4jWebInitializerImpl.java > > +++ > > > b/log4j-jakarta-web/src/main/java/org/apache/logging/log4j/web/Log4jWebInitializerImpl.java > > @@ -16,19 +16,7 @@ > > */ > > package org.apache.logging.log4j.web; > > > > -import java.net.URI; > > -import java.net.URL; > > -import java.text.SimpleDateFormat; > > -import java.util.ArrayList; > > -import java.util.Arrays; > > -import java.util.Date; > > -import java.util.List; > > -import java.util.Map; > > -import java.util.concurrent.ConcurrentHashMap; > > -import java.util.concurrent.TimeUnit; > > - > > import jakarta.servlet.ServletContext; > > - > > import org.apache.logging.log4j.LogManager; > > import org.apache.logging.log4j.core.AbstractLifeCycle; > > import org.apache.logging.log4j.core.LoggerContext; > > @@ -42,10 +30,16 @@ import > > org.apache.logging.log4j.core.selector.ContextSelector; > > import org.apache.logging.log4j.core.selector.NamedContextSelector; > > import org.apache.logging.log4j.core.util.Loader; > > import org.apache.logging.log4j.core.util.NetUtils; > > -import org.apache.logging.log4j.core.util.SetUtils; > > import org.apache.logging.log4j.spi.LoggerContextFactory; > > import org.apache.logging.log4j.util.LoaderUtil; > > > > +import java.net.URI; > > +import java.net.URL; > > +import java.text.SimpleDateFormat; > > +import java.util.*; > > +import java.util.concurrent.ConcurrentHashMap; > > +import java.util.concurrent.TimeUnit; > > + > > /** > > * This class initializes and deinitializes Log4j no matter how the > > initialization occurs. > > */ > > @@ -193,7 +187,7 @@ final class Log4jWebInitializerImpl extends > > AbstractLifeCycle implements Log4jWe > > try { > > String configLocation = location; > > if (configLocation == null) { > > - final String[] paths = > > SetUtils.prefixSet(servletContext.getResourcePaths(WEB_INF), WEB_INF + > > "log4j2"); > > + final String[] paths = > > prefixSet(servletContext.getResourcePaths(WEB_INF), WEB_INF + "log4j2"); > > LOGGER.debug("getConfigURI found resource paths {} in > > servletContext at [{}]", Arrays.toString(paths), WEB_INF); > > if (paths.length == 1) { > > configLocation = paths[0]; > > @@ -235,6 +229,24 @@ final class Log4jWebInitializerImpl extends > > AbstractLifeCycle implements Log4jWe > > return null; > > } > > > > + /** > > + * Collects strings starting with the given {@code prefix} from the > > given {@code set}. > > + * > > + * @param set a (nullable) set of strings > > + * @param prefix a prefix to look for in the string set > > + * @return an array of the matching strings from the given set > > + */ > > + @SuppressWarnings("SameParameterValue") > > + private static String[] prefixSet(final Set<String> set, final > String > > prefix) { > > + if (set == null) { > > + return new String[0]; > > + } > > + return set > > + .stream() > > + .filter(string -> string.startsWith(prefix)) > > + .toArray(String[]::new); > > + } > > + > > @Override > > public synchronized boolean stop(final long timeout, final TimeUnit > > timeUnit) { > > if (!this.isStarted() && !this.isStopped()) { > > diff --git > > > a/log4j-web/src/main/java/org/apache/logging/log4j/web/Log4jWebInitializerImpl.java > > > b/log4j-web/src/main/java/org/apache/logging/log4j/web/Log4jWebInitializerImpl.java > > index ba53d4f..a53ab44 100644 > > --- > > > a/log4j-web/src/main/java/org/apache/logging/log4j/web/Log4jWebInitializerImpl.java > > +++ > > > b/log4j-web/src/main/java/org/apache/logging/log4j/web/Log4jWebInitializerImpl.java > > @@ -16,19 +16,6 @@ > > */ > > package org.apache.logging.log4j.web; > > > > -import java.net.URI; > > -import java.net.URL; > > -import java.text.SimpleDateFormat; > > -import java.util.ArrayList; > > -import java.util.Arrays; > > -import java.util.Date; > > -import java.util.List; > > -import java.util.Map; > > -import java.util.concurrent.ConcurrentHashMap; > > -import java.util.concurrent.TimeUnit; > > - > > -import javax.servlet.ServletContext; > > - > > import org.apache.logging.log4j.LogManager; > > import org.apache.logging.log4j.core.AbstractLifeCycle; > > import org.apache.logging.log4j.core.LoggerContext; > > @@ -42,10 +29,17 @@ import > > org.apache.logging.log4j.core.selector.ContextSelector; > > import org.apache.logging.log4j.core.selector.NamedContextSelector; > > import org.apache.logging.log4j.core.util.Loader; > > import org.apache.logging.log4j.core.util.NetUtils; > > -import org.apache.logging.log4j.core.util.SetUtils; > > import org.apache.logging.log4j.spi.LoggerContextFactory; > > import org.apache.logging.log4j.util.LoaderUtil; > > > > +import javax.servlet.ServletContext; > > +import java.net.URI; > > +import java.net.URL; > > +import java.text.SimpleDateFormat; > > +import java.util.*; > > +import java.util.concurrent.ConcurrentHashMap; > > +import java.util.concurrent.TimeUnit; > > + > > /** > > * This class initializes and deinitializes Log4j no matter how the > > initialization occurs. > > */ > > @@ -193,7 +187,7 @@ final class Log4jWebInitializerImpl extends > > AbstractLifeCycle implements Log4jWe > > try { > > String configLocation = location; > > if (configLocation == null) { > > - final String[] paths = > > SetUtils.prefixSet(servletContext.getResourcePaths(WEB_INF), WEB_INF + > > "log4j2"); > > + final String[] paths = > > prefixSet(servletContext.getResourcePaths(WEB_INF), WEB_INF + "log4j2"); > > LOGGER.debug("getConfigURI found resource paths {} in > > servletContext at [{}]", Arrays.toString(paths), WEB_INF); > > if (paths.length == 1) { > > configLocation = paths[0]; > > @@ -235,6 +229,24 @@ final class Log4jWebInitializerImpl extends > > AbstractLifeCycle implements Log4jWe > > return null; > > } > > > > + /** > > + * Collects strings starting with the given {@code prefix} from the > > given {@code set}. > > + * > > + * @param set a (nullable) set of strings > > + * @param prefix a prefix to look for in the string set > > + * @return an array of the matching strings from the given set > > + */ > > + @SuppressWarnings("SameParameterValue") > > + private static String[] prefixSet(final Set<String> set, final > String > > prefix) { > > + if (set == null) { > > + return new String[0]; > > + } > > + return set > > + .stream() > > + .filter(string -> string.startsWith(prefix)) > > + .toArray(String[]::new); > > + } > > + > > @Override > > public synchronized boolean stop(final long timeout, final TimeUnit > > timeUnit) { > > if (!this.isStarted() && !this.isStopped()) { > > >
