gitgabrio commented on code in PR #3686:
URL: 
https://github.com/apache/incubator-kie-kogito-runtimes/pull/3686#discussion_r1805982472


##########
jbpm/jbpm-flow/src/main/java/org/jbpm/process/core/timer/BusinessCalendarImpl.java:
##########
@@ -103,38 +106,26 @@ public class BusinessCalendarImpl implements 
BusinessCalendar {
     public static final String WEEKEND_DAYS = "business.weekend.days";
     public static final String TIMEZONE = "business.cal.timezone";
 
-    private static final String DEFAULT_PROPERTIES_NAME = 
"/jbpm.business.calendar.properties";
-
     public BusinessCalendarImpl() {
-        String propertiesLocation = 
System.getProperty("jbpm.business.calendar.properties");
-
-        if (propertiesLocation == null) {
-            propertiesLocation = DEFAULT_PROPERTIES_NAME;
-        }
-        businessCalendarConfiguration = new Properties();
-
-        InputStream in = 
this.getClass().getResourceAsStream(propertiesLocation);
-        if (in != null) {
-
-            try {
-                businessCalendarConfiguration.load(in);
-            } catch (IOException e) {
-                logger.error("Error while loading properties for business 
calendar", e);
-
-            }
-        }
-        init();
-
+        this(null);
     }
 
     public BusinessCalendarImpl(Properties configuration) {
-        this.businessCalendarConfiguration = configuration;
-        init();
+        this(configuration, null);
     }
 
     public BusinessCalendarImpl(Properties configuration, SessionClock clock) {
-        this.businessCalendarConfiguration = configuration;
         this.clock = clock;
+        if (configuration == null) {
+            businessCalendarConfiguration = new Properties();
+            try (InputStream is = 
Thread.currentThread().getContextClassLoader().getResourceAsStream(BUSINESS_CALENDAR_PATH))
 {
+                businessCalendarConfiguration.load(is);
+            } catch (IOException e) {
+                logger.error("Error while loading properties for business 
calendar", e);

Review Comment:
   Thanks @martinweiler 
   So, @Abhitocode this is more or less what the code should be, IMO, to 
reflect the required behavior.
   I did not test it, so it may be wrong, but what's important it is to have 
the code reflecting the exacting the expected logic
   
   public BusinessCalendarImpl(Properties configuration, SessionClock clock) {
           this.clock = clock;
           if (configuration == null) {
               // logic is that
               // when configuration is null ->  a 
businessCalendarConfiguration is instantiated from scratch
               // otherwise, configuration will become 
businessCalendarConfiguration
               businessCalendarConfiguration = new Properties();
               // the "calendar.properties" file is Optional, so we must first 
check for its presence
               URL resource = 
Thread.currentThread().getContextClassLoader().getResource(BUSINESS_CALENDAR_PATH);
               if (resource != null) {
                   // if "calendar.properties" file is present, let's try to 
load it
                   try (InputStream is = resource.openStream()) {
                       businessCalendarConfiguration.load(is);
                   } catch (Exception e) {
                       logger.error("Error while loading properties for 
business calendar", e);
                       // and now, here, we should throw an exception back 
because:
                       // the "calendar.properties" file has been found (line 
125), so it should be loaded
                       // and the user expect it to be used
                       // but for some reason 
businessCalendarConfiguration.load(is); throws an exception
                       // we have to re-throw the exception because otherwise 
the application we'll keep working
                       // with the default values, leading to an 
not-comprensible situation for the user
                       throw new RuntimeException("Error while loading 
properties for business calendar", e);
                   }
               }
           } else {
               this.businessCalendarConfiguration = configuration;
           }
           init();
       }



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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to