galovics commented on code in PR #4861:
URL: https://github.com/apache/fineract/pull/4861#discussion_r2208428637


##########
fineract-core/src/main/java/org/apache/fineract/organisation/monetary/domain/MoneyHelper.java:
##########
@@ -49,23 +52,42 @@ public void initialize() {
     }
 
     public static RoundingMode getRoundingMode() {
-        if (roundingMode == null) {
-            roundingMode = 
RoundingMode.valueOf(staticConfigurationDomainService.getRoundingMode());
-        }
-        return roundingMode;
+        String tenantId = getTenantIdentifier();
+        return roundingModeCache.computeIfAbsent(tenantId, k -> 
RoundingMode.valueOf(staticConfigurationDomainService.getRoundingMode()));
     }
 
     public static MathContext getMathContext() {
-        if (mathContext == null) {
-            mathContext = new MathContext(PRECISION, getRoundingMode());
-        }
-        return mathContext;
+        String tenantId = getTenantIdentifier();
+        return mathContextCache.computeIfAbsent(tenantId, k -> new 
MathContext(PRECISION, getRoundingMode()));
     }
 
     public static void fetchRoundingModeFromGlobalConfig() {
-        roundingMode = 
RoundingMode.valueOf(staticConfigurationDomainService.getRoundingMode());
-        log.info("Fetch Rounding Mode from Global Config {}", 
roundingMode.name());
-        mathContext = null;
+        String tenantId = getTenantIdentifier();
+        RoundingMode newRoundingMode = 
RoundingMode.valueOf(staticConfigurationDomainService.getRoundingMode());
+        roundingModeCache.put(tenantId, newRoundingMode);
+        log.info("Fetch Rounding Mode from Global Config for tenant {}: {}", 
tenantId, newRoundingMode.name());
+        mathContextCache.remove(tenantId); // Force recreation with new 
rounding mode
+    }
+
+    private static String getTenantIdentifier() {
+        FineractPlatformTenant tenant = ThreadLocalContextUtil.getTenant();
+        if (tenant != null) {
+            return tenant.getTenantIdentifier();
+        }
+        // Fallback for cases where tenant context is not available
+        return "default";

Review Comment:
   I'd really not hardcode something like this. You can't be sure that there 
will be a default tenant in the system.
   
   Throw an exception if we think this is an invalid case rather than hiding 
the problem.



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