diff --git a/logback-classic/src/main/java/ch/qos/logback/classic/model/processor/ConfigurationModelHandler.java b/logback-classic/src/main/java/ch/qos/logback/classic/model/processor/ConfigurationModelHandler.java index bb5edb1942..7d3443a9d9 100755 --- a/logback-classic/src/main/java/ch/qos/logback/classic/model/processor/ConfigurationModelHandler.java +++ b/logback-classic/src/main/java/ch/qos/logback/classic/model/processor/ConfigurationModelHandler.java @@ -69,7 +69,7 @@ public void handle(ModelInterpretationContext mic, Model model) { } - if (!(OptionHelper.isNullOrEmpty(debugAttrib) || debugAttrib.equalsIgnoreCase(FALSE.toString()) + if (!(OptionHelper.isNullOrEmptyOrAllSpaces(debugAttrib) || debugAttrib.equalsIgnoreCase(FALSE.toString()) || debugAttrib.equalsIgnoreCase(NULL_STR))) { StatusListenerConfigHelper.addOnConsoleListenerInstance(context, new OnConsoleStatusListener()); } @@ -87,7 +87,7 @@ public void handle(ModelInterpretationContext mic, Model model) { protected void processScanAttrib(ModelInterpretationContext mic, ConfigurationModel configurationModel) { String scanStr = mic.subst(configurationModel.getScanStr()); - if (!OptionHelper.isNullOrEmpty(scanStr) && !"false".equalsIgnoreCase(scanStr)) { + if (!OptionHelper.isNullOrEmptyOrAllSpaces(scanStr) && !"false".equalsIgnoreCase(scanStr)) { addInfo("Skipping ReconfigureOnChangeTask registration"); } } diff --git a/logback-classic/src/main/java/ch/qos/logback/classic/model/processor/ConfigurationModelHandlerFull.java b/logback-classic/src/main/java/ch/qos/logback/classic/model/processor/ConfigurationModelHandlerFull.java index d64ed758ac..2512de234b 100755 --- a/logback-classic/src/main/java/ch/qos/logback/classic/model/processor/ConfigurationModelHandlerFull.java +++ b/logback-classic/src/main/java/ch/qos/logback/classic/model/processor/ConfigurationModelHandlerFull.java @@ -13,31 +13,21 @@ */ package ch.qos.logback.classic.model.processor; -import ch.qos.logback.classic.LoggerContext; import ch.qos.logback.classic.joran.ReconfigureOnChangeTask; import ch.qos.logback.classic.model.ConfigurationModel; import ch.qos.logback.core.Context; import ch.qos.logback.core.joran.util.ConfigurationWatchListUtil; -import ch.qos.logback.core.model.Model; import ch.qos.logback.core.model.processor.ModelHandlerBase; -import ch.qos.logback.core.model.processor.ModelHandlerException; import ch.qos.logback.core.model.processor.ModelInterpretationContext; import ch.qos.logback.core.spi.ConfigurationEvent; -import ch.qos.logback.core.status.OnConsoleStatusListener; -import ch.qos.logback.core.util.ContextUtil; import ch.qos.logback.core.util.Duration; import ch.qos.logback.core.util.OptionHelper; -import ch.qos.logback.core.util.StatusListenerConfigHelper; import java.net.URL; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.ScheduledFuture; import java.util.concurrent.TimeUnit; -import static ch.qos.logback.core.model.ModelConstants.DEBUG_SYSTEM_PROPERTY_KEY; -import static ch.qos.logback.core.model.ModelConstants.NULL_STR; -import static java.lang.Boolean.FALSE; - /** * This is a subclass of {@link ConfigurationModelHandler} offering configuration reloading support. * @@ -57,7 +47,7 @@ static public ModelHandlerBase makeInstance2(Context context, ModelInterpretatio protected void processScanAttrib(ModelInterpretationContext mic, ConfigurationModel configurationModel) { String scanStr = mic.subst(configurationModel.getScanStr()); - if (!OptionHelper.isNullOrEmpty(scanStr) && !"false".equalsIgnoreCase(scanStr)) { + if (!OptionHelper.isNullOrEmptyOrAllSpaces(scanStr) && !"false".equalsIgnoreCase(scanStr)) { ScheduledExecutorService scheduledExecutorService = context.getScheduledExecutorService(); URL mainURL = ConfigurationWatchListUtil.getMainWatchURL(context); @@ -94,7 +84,7 @@ protected void processScanAttrib(ModelInterpretationContext mic, ConfigurationMo private Duration getDurationOfScanPeriodAttribute(String scanPeriodAttrib, Duration defaultDuration) { Duration duration = null; - if (!OptionHelper.isNullOrEmpty(scanPeriodAttrib)) { + if (!OptionHelper.isNullOrEmptyOrAllSpaces(scanPeriodAttrib)) { try { duration = Duration.valueOf(scanPeriodAttrib); } catch (IllegalStateException | IllegalArgumentException e) { diff --git a/logback-classic/src/main/java/ch/qos/logback/classic/model/processor/LoggerContextListenerModelHandler.java b/logback-classic/src/main/java/ch/qos/logback/classic/model/processor/LoggerContextListenerModelHandler.java index daffb0be3b..c3fb0a8180 100755 --- a/logback-classic/src/main/java/ch/qos/logback/classic/model/processor/LoggerContextListenerModelHandler.java +++ b/logback-classic/src/main/java/ch/qos/logback/classic/model/processor/LoggerContextListenerModelHandler.java @@ -34,7 +34,7 @@ public void handle(ModelInterpretationContext mic, Model model) throws ModelHand LoggerContextListenerModel lclModel = (LoggerContextListenerModel) model; String className = lclModel.getClassName(); - if (OptionHelper.isNullOrEmpty(className)) { + if (OptionHelper.isNullOrEmptyOrAllSpaces(className)) { addError("Empty class name for LoggerContextListener"); inError = true; } else { diff --git a/logback-classic/src/main/java/ch/qos/logback/classic/model/processor/LoggerModelHandler.java b/logback-classic/src/main/java/ch/qos/logback/classic/model/processor/LoggerModelHandler.java index 16ce2bbf08..ab4ad85572 100755 --- a/logback-classic/src/main/java/ch/qos/logback/classic/model/processor/LoggerModelHandler.java +++ b/logback-classic/src/main/java/ch/qos/logback/classic/model/processor/LoggerModelHandler.java @@ -45,7 +45,7 @@ public void handle(ModelInterpretationContext mic, Model model) throws ModelHand logger = loggerContext.getLogger(finalLoggerName); String levelStr = mic.subst(loggerModel.getLevel()); - if (!OptionHelper.isNullOrEmpty(levelStr)) { + if (!OptionHelper.isNullOrEmptyOrAllSpaces(levelStr)) { if (JoranConstants.INHERITED.equalsIgnoreCase(levelStr) || NULL.equalsIgnoreCase(levelStr)) { if(Logger.ROOT_LOGGER_NAME.equalsIgnoreCase(finalLoggerName)) { addError(ErrorCodes.ROOT_LEVEL_CANNOT_BE_SET_TO_NULL); @@ -61,7 +61,7 @@ public void handle(ModelInterpretationContext mic, Model model) throws ModelHand } String additivityStr = mic.subst(loggerModel.getAdditivity()); - if (!OptionHelper.isNullOrEmpty(additivityStr)) { + if (!OptionHelper.isNullOrEmptyOrAllSpaces(additivityStr)) { boolean additive = OptionHelper.toBoolean(additivityStr, true); addInfo("Setting additivity of logger [" + finalLoggerName + "] to " + additive); logger.setAdditive(additive); diff --git a/logback-classic/src/main/java/ch/qos/logback/classic/model/processor/ReceiverModelHandler.java b/logback-classic/src/main/java/ch/qos/logback/classic/model/processor/ReceiverModelHandler.java index df7a4d31fc..227480541c 100644 --- a/logback-classic/src/main/java/ch/qos/logback/classic/model/processor/ReceiverModelHandler.java +++ b/logback-classic/src/main/java/ch/qos/logback/classic/model/processor/ReceiverModelHandler.java @@ -51,7 +51,7 @@ public void handle(ModelInterpretationContext mic, Model model) throws ModelHand ReceiverModel receiverModel = (ReceiverModel) model; String className = receiverModel.getClassName(); - if (OptionHelper.isNullOrEmpty(className)) { + if (OptionHelper.isNullOrEmptyOrAllSpaces(className)) { addError("Missing class name for receiver. "); inError = true; return; diff --git a/logback-classic/src/main/java/ch/qos/logback/classic/model/processor/RootLoggerModelHandler.java b/logback-classic/src/main/java/ch/qos/logback/classic/model/processor/RootLoggerModelHandler.java index 8c2ae9a572..cecd84aad0 100755 --- a/logback-classic/src/main/java/ch/qos/logback/classic/model/processor/RootLoggerModelHandler.java +++ b/logback-classic/src/main/java/ch/qos/logback/classic/model/processor/RootLoggerModelHandler.java @@ -38,7 +38,7 @@ public void handle(ModelInterpretationContext mic, Model model) throws ModelHand root = loggerContext.getLogger(Logger.ROOT_LOGGER_NAME); String levelStr = mic.subst(rootLoggerModel.getLevel()); - if (!OptionHelper.isNullOrEmpty(levelStr)) { + if (!OptionHelper.isNullOrEmptyOrAllSpaces(levelStr)) { Level level = Level.toLevel(levelStr); addInfo("Setting level of ROOT logger to " + level); root.setLevel(level); diff --git a/logback-classic/src/main/java/ch/qos/logback/classic/servlet/LogbackServletContainerInitializer.java b/logback-classic/src/main/java/ch/qos/logback/classic/servlet/LogbackServletContainerInitializer.java index e5a35613e2..e1c159e90d 100755 --- a/logback-classic/src/main/java/ch/qos/logback/classic/servlet/LogbackServletContainerInitializer.java +++ b/logback-classic/src/main/java/ch/qos/logback/classic/servlet/LogbackServletContainerInitializer.java @@ -51,11 +51,11 @@ boolean isDisabledByConfiguration(ServletContext ctx) { disableAttributeStr = (String) disableAttribute; } - if (OptionHelper.isNullOrEmpty(disableAttributeStr)) { + if (OptionHelper.isNullOrEmptyOrAllSpaces(disableAttributeStr)) { disableAttributeStr = OptionHelper.getSystemProperty(DISABLE_SERVLET_CONTAINER_INITIALIZER_KEY); } - if (OptionHelper.isNullOrEmpty(disableAttributeStr)) { + if (OptionHelper.isNullOrEmptyOrAllSpaces(disableAttributeStr)) { disableAttributeStr = OptionHelper.getEnv(DISABLE_SERVLET_CONTAINER_INITIALIZER_KEY); } diff --git a/logback-classic/src/main/java/ch/qos/logback/classic/sift/MDCBasedDiscriminator.java b/logback-classic/src/main/java/ch/qos/logback/classic/sift/MDCBasedDiscriminator.java index 2098f69ccf..206098e238 100644 --- a/logback-classic/src/main/java/ch/qos/logback/classic/sift/MDCBasedDiscriminator.java +++ b/logback-classic/src/main/java/ch/qos/logback/classic/sift/MDCBasedDiscriminator.java @@ -55,11 +55,11 @@ public String getDiscriminatingValue(ILoggingEvent event) { @Override public void start() { int errors = 0; - if (OptionHelper.isNullOrEmpty(key)) { + if (OptionHelper.isNullOrEmptyOrAllSpaces(key)) { errors++; addError("The \"Key\" property must be set"); } - if (OptionHelper.isNullOrEmpty(defaultValue)) { + if (OptionHelper.isNullOrEmptyOrAllSpaces(defaultValue)) { errors++; addError("The \"DefaultValue\" property must be set"); } diff --git a/logback-classic/src/main/java/ch/qos/logback/classic/spi/LoggingEvent.java b/logback-classic/src/main/java/ch/qos/logback/classic/spi/LoggingEvent.java index a0c9689c41..b6e9072e26 100755 --- a/logback-classic/src/main/java/ch/qos/logback/classic/spi/LoggingEvent.java +++ b/logback-classic/src/main/java/ch/qos/logback/classic/spi/LoggingEvent.java @@ -225,7 +225,7 @@ private String extractThreadName(Thread aThread) { return CoreConstants.NA; } String threadName = aThread.getName(); - if (threadName != null) + if (threadName != null && !threadName.isEmpty()) return threadName; Long virtualThreadId = getVirtualThreadId(aThread); if (virtualThreadId != null) { diff --git a/logback-core/src/main/java/ch/qos/logback/core/joran/action/ConversionRuleAction.java b/logback-core/src/main/java/ch/qos/logback/core/joran/action/ConversionRuleAction.java index 6266cbaca7..317f9ba140 100644 --- a/logback-core/src/main/java/ch/qos/logback/core/joran/action/ConversionRuleAction.java +++ b/logback-core/src/main/java/ch/qos/logback/core/joran/action/ConversionRuleAction.java @@ -39,7 +39,7 @@ public void begin(SaxEventInterpretationContext ec, String localName, Attributes String conversionWord = attributes.getValue(JoranConstants.CONVERSION_WORD_ATTRIBUTE); String converterClass = attributes.getValue(JoranConstants.CONVERTER_CLASS_ATTRIBUTE); - if (OptionHelper.isNullOrEmpty(conversionWord)) { + if (OptionHelper.isNullOrEmptyOrAllSpaces(conversionWord)) { inError = true; errorMsg = "No 'conversionWord' attribute in "; addError(errorMsg); @@ -47,7 +47,7 @@ public void begin(SaxEventInterpretationContext ec, String localName, Attributes return; } - if (OptionHelper.isNullOrEmpty(converterClass)) { + if (OptionHelper.isNullOrEmptyOrAllSpaces(converterClass)) { inError = true; errorMsg = "No 'converterClass' attribute in "; ec.addError(errorMsg); diff --git a/logback-core/src/main/java/ch/qos/logback/core/joran/action/IncludeAction.java b/logback-core/src/main/java/ch/qos/logback/core/joran/action/IncludeAction.java index c28c3b7d01..375434b284 100755 --- a/logback-core/src/main/java/ch/qos/logback/core/joran/action/IncludeAction.java +++ b/logback-core/src/main/java/ch/qos/logback/core/joran/action/IncludeAction.java @@ -138,13 +138,13 @@ private boolean checkAttributes(Attributes attributes) { int count = 0; - if (!OptionHelper.isNullOrEmpty(fileAttribute)) { + if (!OptionHelper.isNullOrEmptyOrAllSpaces(fileAttribute)) { count++; } - if (!OptionHelper.isNullOrEmpty(urlAttribute)) { + if (!OptionHelper.isNullOrEmptyOrAllSpaces(urlAttribute)) { count++; } - if (!OptionHelper.isNullOrEmpty(resourceAttribute)) { + if (!OptionHelper.isNullOrEmptyOrAllSpaces(resourceAttribute)) { count++; } @@ -210,17 +210,17 @@ URL getInputURL(SaxEventInterpretationContext ec, Attributes attributes) { String urlAttribute = attributes.getValue(URL_ATTR); String resourceAttribute = attributes.getValue(RESOURCE_ATTR); - if (!OptionHelper.isNullOrEmpty(fileAttribute)) { + if (!OptionHelper.isNullOrEmptyOrAllSpaces(fileAttribute)) { this.attributeInUse = ec.subst(fileAttribute); return filePathAsURL(attributeInUse); } - if (!OptionHelper.isNullOrEmpty(urlAttribute)) { + if (!OptionHelper.isNullOrEmptyOrAllSpaces(urlAttribute)) { this.attributeInUse = ec.subst(urlAttribute); return attributeToURL(attributeInUse); } - if (!OptionHelper.isNullOrEmpty(resourceAttribute)) { + if (!OptionHelper.isNullOrEmptyOrAllSpaces(resourceAttribute)) { this.attributeInUse = ec.subst(resourceAttribute); return resourceAsURL(attributeInUse); } diff --git a/logback-core/src/main/java/ch/qos/logback/core/joran/action/NewRuleAction.java b/logback-core/src/main/java/ch/qos/logback/core/joran/action/NewRuleAction.java index 1db28408b6..ad80bcbd85 100644 --- a/logback-core/src/main/java/ch/qos/logback/core/joran/action/NewRuleAction.java +++ b/logback-core/src/main/java/ch/qos/logback/core/joran/action/NewRuleAction.java @@ -32,14 +32,14 @@ public void begin(SaxEventInterpretationContext ec, String localName, Attributes String pattern = attributes.getValue(Action.PATTERN_ATTRIBUTE); String actionClass = attributes.getValue(Action.ACTION_CLASS_ATTRIBUTE); - if (OptionHelper.isNullOrEmpty(pattern)) { + if (OptionHelper.isNullOrEmptyOrAllSpaces(pattern)) { inError = true; errorMsg = "No 'pattern' attribute in "; addError(errorMsg); return; } - if (OptionHelper.isNullOrEmpty(actionClass)) { + if (OptionHelper.isNullOrEmptyOrAllSpaces(actionClass)) { inError = true; errorMsg = "No 'actionClass' attribute in "; addError(errorMsg); diff --git a/logback-core/src/main/java/ch/qos/logback/core/joran/action/PreconditionValidator.java b/logback-core/src/main/java/ch/qos/logback/core/joran/action/PreconditionValidator.java index fdbbc1698f..96f37d4c5e 100755 --- a/logback-core/src/main/java/ch/qos/logback/core/joran/action/PreconditionValidator.java +++ b/logback-core/src/main/java/ch/qos/logback/core/joran/action/PreconditionValidator.java @@ -68,7 +68,7 @@ public PreconditionValidator validateRefAttribute() { public PreconditionValidator generic(String attributeName) { String attributeValue = attributes.getValue(attributeName); - if (OptionHelper.isNullOrEmpty(attributeValue)) { + if (OptionHelper.isNullOrEmptyOrAllSpaces(attributeValue)) { addError("Missing attribute [" + attributeName + "] in element [" + tag + "] near line " + Action.getLineNumber(intercon)); this.valid = false; diff --git a/logback-core/src/main/java/ch/qos/logback/core/joran/action/StatusListenerAction.java b/logback-core/src/main/java/ch/qos/logback/core/joran/action/StatusListenerAction.java index 8a1665158d..78022264c8 100644 --- a/logback-core/src/main/java/ch/qos/logback/core/joran/action/StatusListenerAction.java +++ b/logback-core/src/main/java/ch/qos/logback/core/joran/action/StatusListenerAction.java @@ -31,7 +31,7 @@ public class StatusListenerAction extends BaseModelAction { protected boolean validPreconditions(SaxEventInterpretationContext interpretationContext, String name, Attributes attributes) { String className = attributes.getValue(CLASS_ATTRIBUTE); - if (OptionHelper.isNullOrEmpty(className)) { + if (OptionHelper.isNullOrEmptyOrAllSpaces(className)) { addError("Missing class name for statusListener. Near [" + name + "] line " + getLineNumber(interpretationContext)); return false; diff --git a/logback-core/src/main/java/ch/qos/logback/core/joran/action/TimestampAction.java b/logback-core/src/main/java/ch/qos/logback/core/joran/action/TimestampAction.java index f0d33be742..71ddaa0490 100644 --- a/logback-core/src/main/java/ch/qos/logback/core/joran/action/TimestampAction.java +++ b/logback-core/src/main/java/ch/qos/logback/core/joran/action/TimestampAction.java @@ -38,12 +38,12 @@ protected boolean validPreconditions(SaxEventInterpretationContext interpretatio Attributes attributes) { boolean valid = true; String keyStr = attributes.getValue(KEY_ATTRIBUTE); - if (OptionHelper.isNullOrEmpty(keyStr)) { + if (OptionHelper.isNullOrEmptyOrAllSpaces(keyStr)) { addError("Attribute named [" + KEY_ATTRIBUTE + "] cannot be empty"); valid = false; } String datePatternStr = attributes.getValue(DATE_PATTERN_ATTRIBUTE); - if (OptionHelper.isNullOrEmpty(datePatternStr)) { + if (OptionHelper.isNullOrEmptyOrAllSpaces(datePatternStr)) { addError("Attribute named [" + DATE_PATTERN_ATTRIBUTE + "] cannot be empty"); valid = false; } diff --git a/logback-core/src/main/java/ch/qos/logback/core/model/processor/DefineModelHandler.java b/logback-core/src/main/java/ch/qos/logback/core/model/processor/DefineModelHandler.java index 3923e0cffb..88ceac58d6 100755 --- a/logback-core/src/main/java/ch/qos/logback/core/model/processor/DefineModelHandler.java +++ b/logback-core/src/main/java/ch/qos/logback/core/model/processor/DefineModelHandler.java @@ -62,7 +62,7 @@ public void handle(ModelInterpretationContext interpretationContext, Model model scope = ActionUtil.stringToScope(scopeStr); - if (OptionHelper.isNullOrEmpty(propertyName)) { + if (OptionHelper.isNullOrEmptyOrAllSpaces(propertyName)) { addError("Missing property name for property definer. Near [" + model.getTag() + "] line " + model.getLineNumber()); inError = true; @@ -70,7 +70,7 @@ public void handle(ModelInterpretationContext interpretationContext, Model model // read property definer class name String className = defineModel.getClassName(); - if (OptionHelper.isNullOrEmpty(className)) { + if (OptionHelper.isNullOrEmptyOrAllSpaces(className)) { addError("Missing class name for property definer. Near [" + model.getTag() + "] line " + model.getLineNumber()); inError = true; diff --git a/logback-core/src/main/java/ch/qos/logback/core/model/processor/EventEvaluatorModelHandler.java b/logback-core/src/main/java/ch/qos/logback/core/model/processor/EventEvaluatorModelHandler.java index c681ba6ffa..7eeede6da5 100755 --- a/logback-core/src/main/java/ch/qos/logback/core/model/processor/EventEvaluatorModelHandler.java +++ b/logback-core/src/main/java/ch/qos/logback/core/model/processor/EventEvaluatorModelHandler.java @@ -36,9 +36,9 @@ public void handle(ModelInterpretationContext intercon, Model model) throws Mode EventEvaluatorModel eem = (EventEvaluatorModel) model; String className = eem.getClassName(); - if (OptionHelper.isNullOrEmpty(className)) { + if (OptionHelper.isNullOrEmptyOrAllSpaces(className)) { String defaultClassName = defaultClassName(intercon, eem); - if (OptionHelper.isNullOrEmpty(defaultClassName)) { + if (OptionHelper.isNullOrEmptyOrAllSpaces(defaultClassName)) { inError = true; addError("Mandatory \"" + CLASS_ATTRIBUTE + "\" attribute missing for "); addError("No default classname could be found."); diff --git a/logback-core/src/main/java/ch/qos/logback/core/model/processor/ImplicitModelHandler.java b/logback-core/src/main/java/ch/qos/logback/core/model/processor/ImplicitModelHandler.java index aaa7b660cc..ae77a4e1c7 100755 --- a/logback-core/src/main/java/ch/qos/logback/core/model/processor/ImplicitModelHandler.java +++ b/logback-core/src/main/java/ch/qos/logback/core/model/processor/ImplicitModelHandler.java @@ -130,7 +130,7 @@ public void doComplex(ModelInterpretationContext interpretationContext, Componen Class componentClass = null; try { - if (!OptionHelper.isNullOrEmpty(fqcn)) { + if (!OptionHelper.isNullOrEmptyOrAllSpaces(fqcn)) { componentClass = Loader.loadClass(fqcn, context); } else { // guess class name via implicit rules @@ -146,7 +146,7 @@ public void doComplex(ModelInterpretationContext interpretationContext, Componen return; } - if (OptionHelper.isNullOrEmpty(fqcn)) { + if (OptionHelper.isNullOrEmptyOrAllSpaces(fqcn)) { addInfo("Assuming default type [" + componentClass.getName() + "] for [" + componentModel.getTag() + "] property"); } diff --git a/logback-core/src/main/java/ch/qos/logback/core/model/processor/ImportModelHandler.java b/logback-core/src/main/java/ch/qos/logback/core/model/processor/ImportModelHandler.java index 0f673dd18a..b89f9d9993 100644 --- a/logback-core/src/main/java/ch/qos/logback/core/model/processor/ImportModelHandler.java +++ b/logback-core/src/main/java/ch/qos/logback/core/model/processor/ImportModelHandler.java @@ -26,7 +26,7 @@ public void handle(ModelInterpretationContext intercon, Model model) throws Mode ImportModel importModel = (ImportModel) model; String className = importModel.getClassName(); - if (OptionHelper.isNullOrEmpty(className)) { + if (OptionHelper.isNullOrEmptyOrAllSpaces(className)) { addWarn("Empty className not allowed"); return; } diff --git a/logback-core/src/main/java/ch/qos/logback/core/model/processor/InsertFromJNDIModelHandler.java b/logback-core/src/main/java/ch/qos/logback/core/model/processor/InsertFromJNDIModelHandler.java index 4e76ec8a1f..446637030e 100644 --- a/logback-core/src/main/java/ch/qos/logback/core/model/processor/InsertFromJNDIModelHandler.java +++ b/logback-core/src/main/java/ch/qos/logback/core/model/processor/InsertFromJNDIModelHandler.java @@ -40,12 +40,12 @@ public void handle(ModelInterpretationContext mic, Model model) throws ModelHand String envEntryValue; - if (OptionHelper.isNullOrEmpty(envEntryName)) { + if (OptionHelper.isNullOrEmptyOrAllSpaces(envEntryName)) { addError("[" + InsertFromJNDIModel.ENV_ENTRY_NAME_ATTR + "] missing"); errorCount++; } - if (OptionHelper.isNullOrEmpty(asKey)) { + if (OptionHelper.isNullOrEmptyOrAllSpaces(asKey)) { addError("[" + InsertFromJNDIModel.AS_ATTR + "] missing"); errorCount++; } @@ -57,7 +57,7 @@ public void handle(ModelInterpretationContext mic, Model model) throws ModelHand try { javax.naming.Context ctx = JNDIUtil.getInitialContext(); envEntryValue = JNDIUtil.lookupString(ctx, envEntryName); - if (OptionHelper.isNullOrEmpty(envEntryValue)) { + if (OptionHelper.isNullOrEmptyOrAllSpaces(envEntryValue)) { addError("[" + envEntryName + "] has null or empty value"); } else { addInfo("Setting variable [" + asKey + "] to [" + envEntryValue + "] in [" + scope + "] scope"); diff --git a/logback-core/src/main/java/ch/qos/logback/core/model/processor/PropertyModelHandler.java b/logback-core/src/main/java/ch/qos/logback/core/model/processor/PropertyModelHandler.java index 5d96995a8c..23e95dcfe8 100755 --- a/logback-core/src/main/java/ch/qos/logback/core/model/processor/PropertyModelHandler.java +++ b/logback-core/src/main/java/ch/qos/logback/core/model/processor/PropertyModelHandler.java @@ -13,7 +13,6 @@ import ch.qos.logback.core.model.Model; import ch.qos.logback.core.model.ModelUtil; import ch.qos.logback.core.model.PropertyModel; -import ch.qos.logback.core.pattern.util.RegularEscapeUtil; import ch.qos.logback.core.util.Loader; import ch.qos.logback.core.util.OptionHelper; @@ -93,8 +92,8 @@ boolean checkFileAttributeSanity(PropertyModel propertyModel) { String value = propertyModel.getValue(); String resource = propertyModel.getResource(); - return !(OptionHelper.isNullOrEmpty(file)) && (OptionHelper.isNullOrEmpty(name) - && OptionHelper.isNullOrEmpty(value) && OptionHelper.isNullOrEmpty(resource)); + return !(OptionHelper.isNullOrEmptyOrAllSpaces(file)) && (OptionHelper.isNullOrEmptyOrAllSpaces(name) + && OptionHelper.isNullOrEmptyOrAllSpaces(value) && OptionHelper.isNullOrEmptyOrAllSpaces(resource)); } boolean checkResourceAttributeSanity(PropertyModel propertyModel) { @@ -103,8 +102,8 @@ boolean checkResourceAttributeSanity(PropertyModel propertyModel) { String value = propertyModel.getValue(); String resource = propertyModel.getResource(); - return !(OptionHelper.isNullOrEmpty(resource)) && (OptionHelper.isNullOrEmpty(name) - && OptionHelper.isNullOrEmpty(value) && OptionHelper.isNullOrEmpty(file)); + return !(OptionHelper.isNullOrEmptyOrAllSpaces(resource)) && (OptionHelper.isNullOrEmptyOrAllSpaces(name) + && OptionHelper.isNullOrEmptyOrAllSpaces(value) && OptionHelper.isNullOrEmptyOrAllSpaces(file)); } boolean checkValueNameAttributesSanity(PropertyModel propertyModel) { @@ -112,8 +111,8 @@ boolean checkValueNameAttributesSanity(PropertyModel propertyModel) { String name = propertyModel.getName(); String value = propertyModel.getValue(); String resource = propertyModel.getResource(); - return (!(OptionHelper.isNullOrEmpty(name) || OptionHelper.isNullOrEmpty(value)) - && (OptionHelper.isNullOrEmpty(file) && OptionHelper.isNullOrEmpty(resource))); + return (!(OptionHelper.isNullOrEmptyOrAllSpaces(name) || OptionHelper.isNullOrEmptyOrAllSpaces(value)) + && (OptionHelper.isNullOrEmptyOrAllSpaces(file) && OptionHelper.isNullOrEmptyOrAllSpaces(resource))); } } diff --git a/logback-core/src/main/java/ch/qos/logback/core/model/processor/SequenceNumberGeneratorModelHandler.java b/logback-core/src/main/java/ch/qos/logback/core/model/processor/SequenceNumberGeneratorModelHandler.java index 9f6e506173..b37b0ac5d7 100644 --- a/logback-core/src/main/java/ch/qos/logback/core/model/processor/SequenceNumberGeneratorModelHandler.java +++ b/logback-core/src/main/java/ch/qos/logback/core/model/processor/SequenceNumberGeneratorModelHandler.java @@ -43,7 +43,7 @@ public void handle(ModelInterpretationContext mic, Model model) throws ModelHand SequenceNumberGeneratorModel sequenceNumberGeneratorModel = (SequenceNumberGeneratorModel) model; String className = sequenceNumberGeneratorModel.getClassName(); - if (OptionHelper.isNullOrEmpty(className)) { + if (OptionHelper.isNullOrEmptyOrAllSpaces(className)) { addWarn("Missing className. This should have been caught earlier."); inError = true; return; diff --git a/logback-core/src/main/java/ch/qos/logback/core/model/processor/ShutdownHookModelHandler.java b/logback-core/src/main/java/ch/qos/logback/core/model/processor/ShutdownHookModelHandler.java index df88ff7b80..dc14303a45 100755 --- a/logback-core/src/main/java/ch/qos/logback/core/model/processor/ShutdownHookModelHandler.java +++ b/logback-core/src/main/java/ch/qos/logback/core/model/processor/ShutdownHookModelHandler.java @@ -51,7 +51,7 @@ public void handle(ModelInterpretationContext mic, Model model) { ShutdownHookModel shutdownHookModel = (ShutdownHookModel) model; String className = shutdownHookModel.getClassName(); - if (OptionHelper.isNullOrEmpty(className)) { + if (OptionHelper.isNullOrEmptyOrAllSpaces(className)) { className = DEFAULT_SHUTDOWN_HOOK_CLASSNAME; addInfo("Assuming className [" + className + "]"); } else { diff --git a/logback-core/src/main/java/ch/qos/logback/core/model/processor/StatusListenerModelHandler.java b/logback-core/src/main/java/ch/qos/logback/core/model/processor/StatusListenerModelHandler.java index b0854e8e2d..dcfd559abf 100755 --- a/logback-core/src/main/java/ch/qos/logback/core/model/processor/StatusListenerModelHandler.java +++ b/logback-core/src/main/java/ch/qos/logback/core/model/processor/StatusListenerModelHandler.java @@ -34,7 +34,7 @@ public void handle(ModelInterpretationContext ic, Model model) throws ModelHandl String className = slModel.getClassName(); - if (OptionHelper.isNullOrEmpty(className)) { + if (OptionHelper.isNullOrEmptyOrAllSpaces(className)) { addError("Empty class name for StatusListener"); inError = true; return; diff --git a/logback-core/src/main/java/ch/qos/logback/core/model/processor/TimestampModelHandler.java b/logback-core/src/main/java/ch/qos/logback/core/model/processor/TimestampModelHandler.java index a86cdd097b..9d6facad21 100755 --- a/logback-core/src/main/java/ch/qos/logback/core/model/processor/TimestampModelHandler.java +++ b/logback-core/src/main/java/ch/qos/logback/core/model/processor/TimestampModelHandler.java @@ -44,12 +44,12 @@ protected Class getSupportedModelClass() { public void handle(ModelInterpretationContext interpretationContext, Model model) { TimestampModel timestampModel = (TimestampModel) model; String keyStr = timestampModel.getKey(); - if (OptionHelper.isNullOrEmpty(keyStr)) { + if (OptionHelper.isNullOrEmptyOrAllSpaces(keyStr)) { addError("Attribute named [" + Action.KEY_ATTRIBUTE + "] cannot be empty"); inError = true; } String datePatternStr = timestampModel.getDatePattern(); - if (OptionHelper.isNullOrEmpty(datePatternStr)) { + if (OptionHelper.isNullOrEmptyOrAllSpaces(datePatternStr)) { addError("Attribute named [" + TimestampAction.DATE_PATTERN_ATTRIBUTE + "] cannot be empty"); inError = true; } diff --git a/logback-core/src/main/java/ch/qos/logback/core/model/processor/conditional/IfModelHandler.java b/logback-core/src/main/java/ch/qos/logback/core/model/processor/conditional/IfModelHandler.java index 7dcaf4abf1..0b9a39a375 100644 --- a/logback-core/src/main/java/ch/qos/logback/core/model/processor/conditional/IfModelHandler.java +++ b/logback-core/src/main/java/ch/qos/logback/core/model/processor/conditional/IfModelHandler.java @@ -66,7 +66,7 @@ public void handle(ModelInterpretationContext mic, Model model) throws ModelHand int lineNum = model.getLineNumber(); String conditionStr = ifModel.getCondition(); - if (!OptionHelper.isNullOrEmpty(conditionStr)) { + if (!OptionHelper.isNullOrEmptyOrAllSpaces(conditionStr)) { try { conditionStr = OptionHelper.substVars(conditionStr, mic, context); } catch (ScanException e) { diff --git a/logback-core/src/main/java/ch/qos/logback/core/net/SMTPAppenderBase.java b/logback-core/src/main/java/ch/qos/logback/core/net/SMTPAppenderBase.java index eb0cd1e4fb..e3e1775b2c 100755 --- a/logback-core/src/main/java/ch/qos/logback/core/net/SMTPAppenderBase.java +++ b/logback-core/src/main/java/ch/qos/logback/core/net/SMTPAppenderBase.java @@ -156,7 +156,7 @@ private Session buildSessionFromProperties() { LoginAuthenticator loginAuthenticator = null; - if (!OptionHelper.isNullOrEmpty(username)) { + if (!OptionHelper.isNullOrEmptyOrAllSpaces(username)) { loginAuthenticator = new LoginAuthenticator(username, password); props.put("mail.smtp.auth", "true"); } diff --git a/logback-core/src/main/java/ch/qos/logback/core/net/ssl/SSLParametersConfiguration.java b/logback-core/src/main/java/ch/qos/logback/core/net/ssl/SSLParametersConfiguration.java index 19689f2fb9..a1ebb7607b 100644 --- a/logback-core/src/main/java/ch/qos/logback/core/net/ssl/SSLParametersConfiguration.java +++ b/logback-core/src/main/java/ch/qos/logback/core/net/ssl/SSLParametersConfiguration.java @@ -85,8 +85,8 @@ private String[] enabledProtocols(String[] supportedProtocols, String[] defaultP if (enabledProtocols == null) { // we're assuming that the same engine is used for all configurables // so once we determine the enabled set, we won't do it again - if (OptionHelper.isNullOrEmpty(getIncludedProtocols()) - && OptionHelper.isNullOrEmpty(getExcludedProtocols())) { + if (OptionHelper.isNullOrEmptyOrAllSpaces(getIncludedProtocols()) + && OptionHelper.isNullOrEmptyOrAllSpaces(getExcludedProtocols())) { enabledProtocols = Arrays.copyOf(defaultProtocols, defaultProtocols.length); } else { enabledProtocols = includedStrings(supportedProtocols, getIncludedProtocols(), getExcludedProtocols()); @@ -109,8 +109,8 @@ private String[] enabledCipherSuites(String[] supportedCipherSuites, String[] de if (enabledCipherSuites == null) { // we're assuming that the same engine is used for all configurables // so once we determine the enabled set, we won't do it again - if (OptionHelper.isNullOrEmpty(getIncludedCipherSuites()) - && OptionHelper.isNullOrEmpty(getExcludedCipherSuites())) { + if (OptionHelper.isNullOrEmptyOrAllSpaces(getIncludedCipherSuites()) + && OptionHelper.isNullOrEmptyOrAllSpaces(getExcludedCipherSuites())) { enabledCipherSuites = Arrays.copyOf(defaultCipherSuites, defaultCipherSuites.length); } else { enabledCipherSuites = includedStrings(supportedCipherSuites, getIncludedCipherSuites(), diff --git a/logback-core/src/main/java/ch/qos/logback/core/property/FileExistsPropertyDefiner.java b/logback-core/src/main/java/ch/qos/logback/core/property/FileExistsPropertyDefiner.java index 0ced55e251..4a1dcfef13 100644 --- a/logback-core/src/main/java/ch/qos/logback/core/property/FileExistsPropertyDefiner.java +++ b/logback-core/src/main/java/ch/qos/logback/core/property/FileExistsPropertyDefiner.java @@ -51,7 +51,7 @@ public void setPath(String path) { * @return "true"|"false" depending on the existence of file */ public String getPropertyValue() { - if (OptionHelper.isNullOrEmpty(path)) { + if (OptionHelper.isNullOrEmptyOrAllSpaces(path)) { addError("The \"path\" property must be set."); return null; } diff --git a/logback-core/src/main/java/ch/qos/logback/core/property/ResourceExistsPropertyDefiner.java b/logback-core/src/main/java/ch/qos/logback/core/property/ResourceExistsPropertyDefiner.java index 69709658ad..0a0868b11a 100644 --- a/logback-core/src/main/java/ch/qos/logback/core/property/ResourceExistsPropertyDefiner.java +++ b/logback-core/src/main/java/ch/qos/logback/core/property/ResourceExistsPropertyDefiner.java @@ -56,7 +56,7 @@ public void setResource(String resource) { * classpath */ public String getPropertyValue() { - if (OptionHelper.isNullOrEmpty(resourceStr)) { + if (OptionHelper.isNullOrEmptyOrAllSpaces(resourceStr)) { addError("The \"resource\" property must be set."); return null; } diff --git a/logback-core/src/main/java/ch/qos/logback/core/util/ExecutorServiceUtil.java b/logback-core/src/main/java/ch/qos/logback/core/util/ExecutorServiceUtil.java index 471bbcee74..f7e1e03a83 100755 --- a/logback-core/src/main/java/ch/qos/logback/core/util/ExecutorServiceUtil.java +++ b/logback-core/src/main/java/ch/qos/logback/core/util/ExecutorServiceUtil.java @@ -37,6 +37,9 @@ public class ExecutorServiceUtil { static private final String NEW_VIRTUAL_TPT_METHOD_NAME = "newVirtualThreadPerTaskExecutor"; + public static final String OF_VIRTUAL_METHOD_NAME = "ofVirtual"; + public static final String FACTORY_METHOD_NAME = "factory"; + private static final ThreadFactory THREAD_FACTORY_FOR_SCHEDULED_EXECUTION_SERVICE = new ThreadFactory() { private final AtomicInteger threadNumber = new AtomicInteger(1); @@ -52,9 +55,9 @@ public class ExecutorServiceUtil { private ThreadFactory makeThreadFactory() { if(EnvUtil.isJDK21OrHigher()) { try { - Method ofVirtualMethod = Thread.class.getMethod("ofVirtual"); + Method ofVirtualMethod = Thread.class.getMethod(OF_VIRTUAL_METHOD_NAME); Object threadBuilderOfVirtual = ofVirtualMethod.invoke(null); - Method factoryMethod = threadBuilderOfVirtual.getClass().getMethod("factory"); + Method factoryMethod = threadBuilderOfVirtual.getClass().getMethod(FACTORY_METHOD_NAME); return (ThreadFactory) factoryMethod.invoke(threadBuilderOfVirtual); } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) { return Executors.defaultThreadFactory(); diff --git a/logback-core/src/main/java/ch/qos/logback/core/util/JNDIUtil.java b/logback-core/src/main/java/ch/qos/logback/core/util/JNDIUtil.java index 405ebbf191..09b738e776 100644 --- a/logback-core/src/main/java/ch/qos/logback/core/util/JNDIUtil.java +++ b/logback-core/src/main/java/ch/qos/logback/core/util/JNDIUtil.java @@ -47,7 +47,7 @@ public static Object lookupObject(Context ctx, String name) throws NamingExcepti return null; } - if (OptionHelper.isNullOrEmpty(name)) { + if (OptionHelper.isNullOrEmptyOrAllSpaces(name)) { return null; } diff --git a/logback-core/src/main/java/ch/qos/logback/core/util/OptionHelper.java b/logback-core/src/main/java/ch/qos/logback/core/util/OptionHelper.java index de4961eedc..e38b8ebafe 100644 --- a/logback-core/src/main/java/ch/qos/logback/core/util/OptionHelper.java +++ b/logback-core/src/main/java/ch/qos/logback/core/util/OptionHelper.java @@ -260,7 +260,7 @@ public static boolean toBoolean(String value, boolean dEfault) { * @since 1.3 */ public static boolean isEmpty(String str) { - return isNullOrEmpty(str); + return isNullOrEmptyOrAllSpaces(str); } /** @@ -273,6 +273,17 @@ public static boolean isNullOrEmpty(String str) { return ((str == null) || str.trim().length() == 0); } + /** + * isNullOrEmpty xisNullOrEmptyOrAllSpaces + * @param str + * @return + * @since 1.5.0 + */ + public static boolean isNullOrEmptyOrAllSpaces(String str) { + return ((str == null) || str.trim().length() == 0); + } + + final public static boolean isNullOrEmpty(Object[] array) { if(array == null || array.length == 0) return true; diff --git a/logback-core/src/main/java/ch/qos/logback/core/util/StatusListenerConfigHelper.java b/logback-core/src/main/java/ch/qos/logback/core/util/StatusListenerConfigHelper.java index c9772542be..3701975b83 100755 --- a/logback-core/src/main/java/ch/qos/logback/core/util/StatusListenerConfigHelper.java +++ b/logback-core/src/main/java/ch/qos/logback/core/util/StatusListenerConfigHelper.java @@ -28,7 +28,7 @@ public class StatusListenerConfigHelper { public static void installIfAsked(Context context) { String slClass = OptionHelper.getSystemProperty(CoreConstants.STATUS_LISTENER_CLASS_KEY); - if (!OptionHelper.isNullOrEmpty(slClass)) { + if (!OptionHelper.isNullOrEmptyOrAllSpaces(slClass)) { addStatusListener(context, slClass); } } diff --git a/logback-core/src/main/java/ch/qos/logback/core/util/StringUtil.java b/logback-core/src/main/java/ch/qos/logback/core/util/StringUtil.java new file mode 100644 index 0000000000..1974d70259 --- /dev/null +++ b/logback-core/src/main/java/ch/qos/logback/core/util/StringUtil.java @@ -0,0 +1,2 @@ +package ch.qos.logback.core.util;public class StringUtil { +}