NopeCharon opened a new pull request, #803:
URL: https://github.com/apache/logging-log4cxx/pull/803

   Fixes #801
   
   ## Problem
   
   `OptionConverter::selectAndConfigure` creates the requested configurator 
with `Loader::loadClass` and `Class::newInstance` and does not handle the 
exception they throw. An unknown class name, such as a misspelt 
`LOG4CXX_CONFIGURATOR_CLASS` environment variable value, makes 
`helpers::ClassNotFoundException` escape from `DefaultConfigurator::configure`, 
and so from the first `LogManager::getLogger()` call. It also stops 
`DefaultConfigurator::configureFromFile` from trying the remaining candidate 
files.
   
   ## Fix
   
   Create the configurator with `OptionConverter::instantiateByClassName`. It 
reports the failure to the internal log and returns a null pointer, so 
`selectAndConfigure` logs "Could not instantiate configurator [...]" and 
returns `ConfigurationStatus::NotConfigured`. That is what it already did for a 
class that exists but is not a `Configurator`.
   
   The "Preferred configurator class" debug message is removed, because 
`instantiateByClassName` emits an equivalent "Desired ... sub-class" message.
   
   ## Testing
   
   - Added 
`OptionConverterTestCase::selectAndConfigureWithUnknownConfiguratorClass`. 
Without the fix it fails with `Unexpected std::exception: Class not found: 
org.example.NoSuchConfigurator`.
   - With the fix, the full `ctest` suite passes (70/70) on Linux (GCC 13, 
Ubuntu 24.04).
   - Ran a small program that calls `LogManager::getLogger()` with 
`LOG4CXX_CONFIGURATOR_CLASS=org.example.Bogus`. It now logs `Could not 
instantiate configurator [org.example.Bogus].` instead of throwing.
   


-- 
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]

  • [PR] Do not throw from selectAnd... NopeCharon (via GitHub) via notifications

Reply via email to