aubreyyan opened a new issue, #2851:
URL: https://github.com/apache/logging-log4j2/issues/2851

   ## Description
   
   `PropertiesUtil.extractSubset` does what it describes here:
   
   
https://github.com/apache/logging-log4j2/blob/9fded3e199fde285e0df1ebc6c64d6b61c8b28ba/log4j-api/src/main/java/org/apache/logging/log4j/util/PropertiesUtil.java#L655-L685
   
   But the issue is that when the properties key has only one delimiter, the 
delimiter is removed and the property key becomes a standalone string, like 
`client` (from `logger.client`) and is passed directly into 
`PropertiesUtil.partitionOnCommonPrefixes`...
   
   
https://github.com/apache/logging-log4j2/blob/9fded3e199fde285e0df1ebc6c64d6b61c8b28ba/log4j-core/src/main/java/org/apache/logging/log4j/core/config/properties/PropertiesConfigurationBuilder.java#L105-L106
   
   ... which expects at least one delimiter, as it is expecting a prefix to 
exist, and is searching for it without any validation that there might not be a 
delimiter anymore.
   
   
https://github.com/apache/logging-log4j2/blob/9fded3e199fde285e0df1ebc6c64d6b61c8b28ba/log4j-api/src/main/java/org/apache/logging/log4j/util/PropertiesUtil.java#L703-L733
   
   ## Configuration
   
   **Version:** 2.17.1
   
   **Operating system:** Ubuntu 20.04 LTS
   
   **JDK:** openjdk version "17.0.12" 2024-07-16
   
   ## Logs
   
   These errors occur when trying to run tests in Visual Studio Code using the 
Language Support for Java 
[extension](https://marketplace.visualstudio.com/items?itemName=redhat.java), 
which complicates things slightly because they don't expose the underlying 
commands that they run when you try to run a test through their IDE elements.
   ```
   java.lang.ExceptionInInitializerError
    at 
java.base/java.lang.reflect.Constructor.newInstanceWithCaller([Constructor.java:500])
    at 
java.base/java.lang.reflect.Constructor.newInstance([Constructor.java:481])
    at java.base/java.util.Optional.orElseGet([Optional.java:364])
    at java.base/java.util.ArrayList.forEach([ArrayList.java:1511]])
    at java.base/java.util.ArrayList.forEach([ArrayList.java:1511])
   Caused by: java.lang.StringIndexOutOfBoundsException: begin 0, end -1, 
length 6
    at java.base/java.lang.String.checkBoundsBeginEnd([String.java:4606])
    at java.base/java.lang.String.substring([String.java:2709])
    at 
org.apache.logging.log4j.util.PropertiesUtil.partitionOnCommonPrefixes([PropertiesUtil.java:555])
    at 
org.apache.logging.log4j.core.config.properties.PropertiesConfigurationBuilder.build([PropertiesConfigurationBuilder.java:174])
    at 
org.apache.logging.log4j.core.config.properties.PropertiesConfigurationFactory.getConfiguration([PropertiesConfigurationFactory.java:56])
    at 
org.apache.logging.log4j.core.config.properties.PropertiesConfigurationFactory.getConfiguration([PropertiesConfigurationFactory.java:35])
    at 
org.apache.logging.log4j.core.config.ConfigurationFactory$Factory.getConfiguration([ConfigurationFactory.java:557])
    at 
org.apache.logging.log4j.core.config.ConfigurationFactory$Factory.getConfiguration([ConfigurationFactory.java:481])
    at 
org.apache.logging.log4j.core.config.ConfigurationFactory.getConfiguration([ConfigurationFactory.java:323])
    at 
org.apache.logging.log4j.core.LoggerContext.reconfigure([LoggerContext.java:695])
    at 
org.apache.logging.log4j.core.LoggerContext.reconfigure([LoggerContext.java:716])
    at 
org.apache.logging.log4j.core.LoggerContext.start([LoggerContext.java:270])
    at 
org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext([Log4jContextFactory.java:155])
    at 
org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext([Log4jContextFactory.java:47])
    at org.apache.logging.log4j.LogManager.getContext([LogManager.java:196])
    at 
org.apache.logging.log4j.spi.AbstractLoggerAdapter.getContext([AbstractLoggerAdapter.java:137])
    at 
org.apache.logging.slf4j.Log4jLoggerFactory.getContext([Log4jLoggerFactory.java:55])
    at 
org.apache.logging.log4j.spi.AbstractLoggerAdapter.getLogger([AbstractLoggerAdapter.java:47])
    at 
org.apache.logging.slf4j.Log4jLoggerFactory.getLogger([Log4jLoggerFactory.java:33])
    at org.slf4j.LoggerFactory.getLogger([LoggerFactory.java:284])
    at org.slf4j.LoggerFactory.getLogger([LoggerFactory.java:304])
    at 
com.*********.*********.*********.*********.*********.*********UnitTest.([*********UnitTest.java:52])
    ... 5 more
   ```
   
   I also extracted some values in debug mode, which may aid you in reproducing 
this bug at a unit level:
   ```
   rootProperties.toString()
   "{rootLogger=INFO, STDOUT, logger.client.name=com.*********.*********, 
logger.jsonrpc=ERROR, STDOUT, logger.client.additivity=false, 
logger.jsonrpc.name=com.googlecode.jsonrpc4j, logger.client=DEBUG, STDOUT, 
logger.jsonrpc.additivity=false}"
   ```
   from
   
https://github.com/apache/logging-log4j2/blob/9fded3e199fde285e0df1ebc6c64d6b61c8b28ba/log4j-core/src/main/java/org/apache/logging/log4j/core/config/properties/PropertiesConfigurationBuilder.java#L105-L106
   
   ```
   subset.toString()
   "{jsonrpc.additivity=false, client.additivity=false, 
jsonrpc.name=com.googlecode.jsonrpc4j, client=DEBUG, STDOUT, jsonrpc=ERROR, 
STDOUT, client.name=com.*********.*********}"
   ```
   from
   
https://github.com/apache/logging-log4j2/blob/9fded3e199fde285e0df1ebc6c64d6b61c8b28ba/log4j-api/src/main/java/org/apache/logging/log4j/util/PropertiesUtil.java#L684
   
   ## Reproduction
   
   I have censored some elements that would identify the company's codebase 
that I am working from, but obviously that precludes me from sharing the source 
code.
   
   I am hopeful that this is not actually a bug in log4j and that from these 
logs and debug elements you can help point me to a higher level configuration 
issue. Happy to answer any questions or debug in my repository on your behalf.
   
   Thanks.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to