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

gtully pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/activemq-artemis.git


The following commit(s) were added to refs/heads/main by this push:
     new d7d57e6d26 ARTEMIS-5372 trap load or parse errors and reflect in 
status for broker property files
d7d57e6d26 is described below

commit d7d57e6d265383e975764ff6ebbc45691aeb6986
Author: Gary Tully <[email protected]>
AuthorDate: Mon Mar 31 17:00:49 2025 +0100

    ARTEMIS-5372 trap load or parse errors and reflect in status for broker 
property files
---
 .../core/config/impl/ConfigurationImpl.java        | 15 ++++---
 .../core/config/impl/ConfigurationImplTest.java    | 47 ++++++++++++++++++++--
 2 files changed, 53 insertions(+), 9 deletions(-)

diff --git 
a/artemis-server/src/main/java/org/apache/activemq/artemis/core/config/impl/ConfigurationImpl.java
 
b/artemis-server/src/main/java/org/apache/activemq/artemis/core/config/impl/ConfigurationImpl.java
index 04cf003bd6..d7ee1c6d46 100644
--- 
a/artemis-server/src/main/java/org/apache/activemq/artemis/core/config/impl/ConfigurationImpl.java
+++ 
b/artemis-server/src/main/java/org/apache/activemq/artemis/core/config/impl/ConfigurationImpl.java
@@ -600,13 +600,18 @@ public class ConfigurationImpl implements Configuration, 
Serializable {
       InsertionOrderedProperties brokerProperties = new 
InsertionOrderedProperties();
       try (FileReader fileReader = new FileReader(file);
            BufferedReader reader = new BufferedReader(fileReader)) {
-         if (file.getName().endsWith(".json")) {
-            brokerProperties.loadJson(reader);
-         } else {
-            brokerProperties.load(reader);
+         try {
+            if (file.getName().endsWith(".json")) {
+               brokerProperties.loadJson(reader);
+            } else {
+               brokerProperties.load(reader);
+            }
+         } catch (Exception readOrParseError) {
+            logger.debug("Properties config load error on file {}, {}", 
file.getName(), readOrParseError);
+            updateApplyStatus(file.getName(), Map.of("loadError", 
readOrParseError.toString()));
+            return;
          }
       }
-
       parsePrefixedProperties(this, file.getName(), brokerProperties, null);
    }
 
diff --git 
a/artemis-server/src/test/java/org/apache/activemq/artemis/core/config/impl/ConfigurationImplTest.java
 
b/artemis-server/src/test/java/org/apache/activemq/artemis/core/config/impl/ConfigurationImplTest.java
index 06f35cd3ef..c1980c86ba 100644
--- 
a/artemis-server/src/test/java/org/apache/activemq/artemis/core/config/impl/ConfigurationImplTest.java
+++ 
b/artemis-server/src/test/java/org/apache/activemq/artemis/core/config/impl/ConfigurationImplTest.java
@@ -2076,6 +2076,36 @@ public class ConfigurationImplTest extends 
AbstractConfigurationTestBase {
       testSimpleConfig(configuration);
    }
 
+   @Test
+   public void testInvalidPropertiesReaderFromFile() throws Exception {
+
+      char[] invalidUnicode = {'\\', 'u', '9', '-', '0', 'E'};
+      File tmpFile = File.createTempFile("invalid-props-test", ".properties", 
temporaryFolder);
+      try (FileOutputStream fileOutputStream = new FileOutputStream(tmpFile);
+           PrintWriter printWriter = new PrintWriter(fileOutputStream)) {
+         printWriter.write(invalidUnicode);
+         printWriter.write("\\n");
+      }
+
+      ConfigurationImpl configuration = new ConfigurationImpl();
+      configuration.parseProperties(tmpFile.getAbsolutePath());
+
+      
assertFalse(configuration.getStatus().contains(".properties\":{\"errors\":[]"), 
configuration.getStatus());
+
+      
assertTrue(configuration.getStatus().contains("IllegalArgumentException"));
+      assertTrue(configuration.getStatus().contains(tmpFile.getName()));
+
+      // update to sane
+      try (FileOutputStream fileOutputStream = new FileOutputStream(tmpFile);
+           PrintWriter printWriter = new PrintWriter(fileOutputStream)) {
+         printWriter.write("brokerPropertiesKeySurround=$$");
+      }
+      configuration.parseProperties(tmpFile.getAbsolutePath());
+
+      
assertTrue(configuration.getStatus().contains(".properties\":{\"errors\":[]"), 
configuration.getStatus());
+      assertEquals("$$", configuration.getBrokerPropertiesKeySurround());
+   }
+
    @Test
    public void testInvalidJsonPropertiesReaderFromFile() throws Exception {
 
@@ -2087,11 +2117,20 @@ public class ConfigurationImplTest extends 
AbstractConfigurationTestBase {
 
       ConfigurationImpl configuration = new ConfigurationImpl();
 
-      try {
-         configuration.parseProperties(tmpFile.getAbsolutePath());
-         fail("Expected JSON parsing exception.");
-      } catch (Exception e) {
+      configuration.parseProperties(tmpFile.getAbsolutePath());
+      
assertFalse(configuration.getStatus().contains(".json\":{\"errors\":[]"), 
configuration.getStatus());
+
+      assertTrue(configuration.getStatus().contains("JsonParsingException"));
+      assertTrue(configuration.getStatus().contains(tmpFile.getName()));
+
+      // update to sane
+      try (FileOutputStream fileOutputStream = new FileOutputStream(tmpFile);
+           PrintWriter printWriter = new PrintWriter(fileOutputStream)) {
+         printWriter.write("{\"brokerPropertiesKeySurround\": \"$$\"}");
       }
+      configuration.parseProperties(tmpFile.getAbsolutePath());
+      assertTrue(configuration.getStatus().contains(".json\":{\"errors\":[]"), 
configuration.getStatus());
+      assertEquals("$$", configuration.getBrokerPropertiesKeySurround());
    }
 
    private JsonObject buildSimpleConfigJsonObject() {


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
For further information, visit: https://activemq.apache.org/contact


Reply via email to