This is an automated email from the ASF dual-hosted git repository.

swebb2066 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/logging-log4cxx.git


The following commit(s) were added to refs/heads/master by this push:
     new 60f483ed Ignore an invalid time zone specifier in a date pattern (#462)
60f483ed is described below

commit 60f483ed80e973dd16cb51e110047a15f4a8e50f
Author: Stephen Webb <[email protected]>
AuthorDate: Sun Jan 26 11:38:49 2025 +1100

    Ignore an invalid time zone specifier in a date pattern (#462)
    
    * Check new behaviour in a unit test
---
 src/main/cpp/datepatternconverter.cpp          | 14 +++++++++++---
 src/test/cpp/pattern/patternparsertestcase.cpp |  4 ++++
 2 files changed, 15 insertions(+), 3 deletions(-)

diff --git a/src/main/cpp/datepatternconverter.cpp 
b/src/main/cpp/datepatternconverter.cpp
index d41fd29a..9f20d9ce 100644
--- a/src/main/cpp/datepatternconverter.cpp
+++ b/src/main/cpp/datepatternconverter.cpp
@@ -97,7 +97,7 @@ DateFormatPtr DatePatternConverter::getDateFormat(const 
OptionsList& options)
                                        maximumCacheValidity =
                                                
CachedDateFormat::getMaximumCacheValidity(dateFormatStr);
                                }
-                               catch (IllegalArgumentException& e)
+                               catch (std::exception& e)
                                {
                                        df = 
std::make_shared<ISO8601DateFormat>();
                                        LogLog::warn(((LogString)
@@ -113,9 +113,17 @@ DateFormatPtr DatePatternConverter::getDateFormat(const 
OptionsList& options)
 
                if (options.size() >= 2)
                {
-                       TimeZonePtr tz(TimeZone::getTimeZone(options[1]));
+                       TimeZonePtr tz;
+                       try
+                       {
+                               tz = TimeZone::getTimeZone(options[1]);
+                       }
+                       catch (std::exception& e)
+                       {
+                               LogLog::warn(LOG4CXX_STR("Invalid time zone: ") 
+ options[1], e);
+                       }
 
-                       if (tz != NULL)
+                       if (tz)
                        {
                                df->setTimeZone(tz);
                        }
diff --git a/src/test/cpp/pattern/patternparsertestcase.cpp 
b/src/test/cpp/pattern/patternparsertestcase.cpp
index 7a653cb4..746572da 100644
--- a/src/test/cpp/pattern/patternparsertestcase.cpp
+++ b/src/test/cpp/pattern/patternparsertestcase.cpp
@@ -270,6 +270,10 @@ public:
                assertFormattedEquals(LOG4CXX_STR("%d{HH:mm:ss}{GMT} 
%d{HH:mm:ss} %c  - %m"),
                        getFormatSpecifiers(),
                        expected);
+               // Check an invalid timezone is equivalent to an unspecified 
timezone
+               assertFormattedEquals(LOG4CXX_STR("%d{HH:mm:ss}{GMT} 
%d{HH:mm:ss}{GMT-X} %c  - %m"),
+                       getFormatSpecifiers(),
+                       expected);
        }
 
        void testThreadUsername()

Reply via email to