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

mridulpathak pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/ofbiz-framework.git


The following commit(s) were added to refs/heads/trunk by this push:
     new effb806fb6 Remove this-escape warnings in UtilTimer, MapContext, 
LabelInfo and others
effb806fb6 is described below

commit effb806fb6b2d0c05202351a9e18557ce2c26893
Author: Mridul Pathak <[email protected]>
AuthorDate: Tue Oct 27 13:11:03 2026 +0530

    Remove this-escape warnings in UtilTimer, MapContext, LabelInfo and others
    
    UtilTimer, UtilResourceBundle, MultivaluedMapContext, LabelInfo, 
ServiceArtifactInfo, EntityArtifactInfo, EntitySyncContext and OFBizApiConfig 
called overridable or inherited methods from their constructors. The 
constructors now assign fields directly or use private and static helpers that 
the existing methods delegate to. MapContext gets a protected constructor that 
seeds its first map, and OFBizApiConfig builds a plain ResourceConfig that it 
passes to super(). There is no change to  [...]
---
 .../org/apache/ofbiz/base/util/UtilProperties.java | 12 ++++--
 .../java/org/apache/ofbiz/base/util/UtilTimer.java |  8 +++-
 .../ofbiz/base/util/collections/MapContext.java    | 11 ++++-
 .../util/collections/MultivaluedMapContext.java    |  3 +-
 .../synchronization/EntitySyncContext.java         | 28 +++++++++----
 .../apache/ofbiz/ws/rs/core/OFBizApiConfig.java    | 48 ++++++++++++----------
 .../webtools/artifactinfo/ArtifactInfoBase.java    |  2 +-
 .../webtools/artifactinfo/EntityArtifactInfo.java  |  2 +-
 .../webtools/artifactinfo/ServiceArtifactInfo.java |  2 +-
 .../ofbiz/webtools/labelmanager/LabelInfo.java     | 12 +++---
 10 files changed, 83 insertions(+), 45 deletions(-)

diff --git 
a/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilProperties.java 
b/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilProperties.java
index 1adf38018c..b9508b115a 100644
--- 
a/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilProperties.java
+++ 
b/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilProperties.java
@@ -1012,11 +1012,15 @@ public final class UtilProperties implements 
Serializable {
      */
     public static class UtilResourceBundle extends ResourceBundle {
         private static final UtilCache<String, UtilResourceBundle> 
BUNDLE_CACHE = 
UtilCache.createUtilCache("properties.UtilPropertiesBundleCache");
-        private Properties properties = null;
-        private Locale locale = null;
-        private int hashCode = hashCode();
+        private final Properties properties;
+        private final Locale locale;
+        private final int hashCode;
 
-        protected UtilResourceBundle() { }
+        protected UtilResourceBundle() {
+            this.properties = null;
+            this.locale = null;
+            this.hashCode = 0;
+        }
 
         UtilResourceBundle(Properties properties, Locale locale, 
UtilResourceBundle parent) {
             this.properties = properties;
diff --git 
a/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilTimer.java 
b/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilTimer.java
index 7b02183c63..f2cd5719bc 100644
--- a/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilTimer.java
+++ b/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilTimer.java
@@ -56,9 +56,9 @@ public class UtilTimer {
 
     public UtilTimer(String timerName, boolean start, boolean log) {
         this.timerName = timerName;
-        this.setLog(log);
+        this.log = log;
         if (start) {
-            this.startTimer();
+            start();
         }
     }
 
@@ -66,6 +66,10 @@ public class UtilTimer {
      * Start timer.
      */
     public void startTimer() {
+        start();
+    }
+
+    private void start() {
         startTime = System.currentTimeMillis();
         realStartTime = startTime;
         this.lastMessageTime = startTime;
diff --git 
a/framework/base/src/main/java/org/apache/ofbiz/base/util/collections/MapContext.java
 
b/framework/base/src/main/java/org/apache/ofbiz/base/util/collections/MapContext.java
index 321f0c15b9..9399609593 100644
--- 
a/framework/base/src/main/java/org/apache/ofbiz/base/util/collections/MapContext.java
+++ 
b/framework/base/src/main/java/org/apache/ofbiz/base/util/collections/MapContext.java
@@ -47,7 +47,16 @@ import org.apache.ofbiz.base.util.UtilGenerics;
  */
 public class MapContext<K, V> implements Map<K, V>, LocalizedMap<V> {
 
-    private Deque<Map<K, V>> contexts = new LinkedList<>();
+    private final Deque<Map<K, V>> contexts = new LinkedList<>();
+
+    /** Creates a MapContext with no Map on the stack. */
+    public MapContext() {
+    }
+
+    /** Creates a MapContext with {@code initialMap} as its only Map on the 
stack. */
+    protected MapContext(Map<K, V> initialMap) {
+        contexts.addFirst(initialMap);
+    }
 
     /**
      * Gets contexts.
diff --git 
a/framework/base/src/main/java/org/apache/ofbiz/base/util/collections/MultivaluedMapContext.java
 
b/framework/base/src/main/java/org/apache/ofbiz/base/util/collections/MultivaluedMapContext.java
index 79f543f2d8..bf17a8f061 100644
--- 
a/framework/base/src/main/java/org/apache/ofbiz/base/util/collections/MultivaluedMapContext.java
+++ 
b/framework/base/src/main/java/org/apache/ofbiz/base/util/collections/MultivaluedMapContext.java
@@ -18,6 +18,7 @@
  
*******************************************************************************/
 package org.apache.ofbiz.base.util.collections;
 
+import java.util.HashMap;
 import java.util.LinkedList;
 import java.util.List;
 
@@ -34,7 +35,7 @@ public class MultivaluedMapContext<K, V> extends 
MapContext<K, List<V>> {
      * Create a multi-value map initialized with one context
      */
     public MultivaluedMapContext() {
-        push();
+        super(new HashMap<>());
     }
 
     /**
diff --git 
a/framework/entityext/src/main/java/org/apache/ofbiz/entityext/synchronization/EntitySyncContext.java
 
b/framework/entityext/src/main/java/org/apache/ofbiz/entityext/synchronization/EntitySyncContext.java
index 775b63895c..d1e34b743f 100644
--- 
a/framework/entityext/src/main/java/org/apache/ofbiz/entityext/synchronization/EntitySyncContext.java
+++ 
b/framework/entityext/src/main/java/org/apache/ofbiz/entityext/synchronization/EntitySyncContext.java
@@ -237,12 +237,13 @@ public class EntitySyncContext {
             this.maxRunningNoUpdateMillis = 
getMaxRunningNoUpdateMillis(entitySync);
 
             this.lastSuccessfulSynchTime = 
entitySync.getTimestamp("lastSuccessfulSynchTime");
-            this.entityModelToUseList = this.makeEntityModelToUseList();
-            this.entityNameToUseSet = this.makeEntityNameToUseSet();
+            this.entityModelToUseList = makeEntityModelToUseList(entitySync, 
delegator);
+            this.entityNameToUseSet = 
makeEntityNameToUseSet(entityModelToUseList);
 
             // set start and end times for the first/current pass
             this.currentRunStartTime = 
getCurrentRunStartTime(lastSuccessfulSynchTime, entityModelToUseList, 
delegator);
-            this.setCurrentRunEndTime();
+            this.currentRunEndTime = getNextRunEndTime(currentRunStartTime, 
isOfflineSync ? offlineSyncSplitMillis : syncSplitMillis,
+                    syncEndStamp);
 
             // this is mostly for the pull side... will always be null for at 
the beginning of a push process, to be filled in later
             this.startDate = (Timestamp) context.get("startDate");
@@ -312,10 +313,13 @@ public class EntitySyncContext {
      * @return the next run end time
      */
     protected Timestamp getNextRunEndTime() {
-        long syncSplit = this.isOfflineSync ? offlineSyncSplitMillis : 
syncSplitMillis;
-        Timestamp nextRunEndTime = new 
Timestamp(this.currentRunStartTime.getTime() + syncSplit);
-        if (nextRunEndTime.after(this.syncEndStamp)) {
-            nextRunEndTime = this.syncEndStamp;
+        return getNextRunEndTime(currentRunStartTime, isOfflineSync ? 
offlineSyncSplitMillis : syncSplitMillis, syncEndStamp);
+    }
+
+    private static Timestamp getNextRunEndTime(Timestamp currentRunStartTime, 
long syncSplit, Timestamp syncEndStamp) {
+        Timestamp nextRunEndTime = new Timestamp(currentRunStartTime.getTime() 
+ syncSplit);
+        if (nextRunEndTime.after(syncEndStamp)) {
+            nextRunEndTime = syncEndStamp;
         }
         return nextRunEndTime;
     }
@@ -1007,8 +1011,12 @@ public class EntitySyncContext {
      * @return the set
      */
     public Set<String> makeEntityNameToUseSet() {
+        return makeEntityNameToUseSet(entityModelToUseList);
+    }
+
+    private static Set<String> makeEntityNameToUseSet(List<ModelEntity> 
entityModelToUseList) {
         Set<String> entityNameToUseSet = new HashSet<>();
-        for (ModelEntity modelEntity: this.entityModelToUseList) {
+        for (ModelEntity modelEntity: entityModelToUseList) {
             entityNameToUseSet.add(modelEntity.getEntityName());
         }
         return entityNameToUseSet;
@@ -1017,6 +1025,10 @@ public class EntitySyncContext {
     /** prepare a list of all entities we want to synchronize: remove all 
view-entities and all entities that don't match the patterns attached
      * to this EntitySync */
     protected List<ModelEntity> makeEntityModelToUseList() throws 
GenericEntityException {
+        return makeEntityModelToUseList(entitySync, delegator);
+    }
+
+    private static List<ModelEntity> makeEntityModelToUseList(GenericValue 
entitySync, Delegator delegator) throws GenericEntityException {
         List<GenericValue> entitySyncIncludes = 
entitySync.getRelated("EntitySyncInclude", null, null, false);
         // get these ones as well, and just add them to the main list, it will 
have an extra field but that shouldn't hurt anything in the code below
         List<GenericValue> entitySyncGroupIncludes = 
entitySync.getRelated("EntitySyncInclGrpDetailView", null, null, false);
diff --git 
a/framework/rest-api/src/main/java/org/apache/ofbiz/ws/rs/core/OFBizApiConfig.java
 
b/framework/rest-api/src/main/java/org/apache/ofbiz/ws/rs/core/OFBizApiConfig.java
index a58796253f..8a3ddc4a6e 100644
--- 
a/framework/rest-api/src/main/java/org/apache/ofbiz/ws/rs/core/OFBizApiConfig.java
+++ 
b/framework/rest-api/src/main/java/org/apache/ofbiz/ws/rs/core/OFBizApiConfig.java
@@ -64,27 +64,33 @@ public class OFBizApiConfig extends ResourceConfig {
      * directory.
      */
     public OFBizApiConfig() {
-        packages("org.apache.ofbiz.ws.rs.resources");
-        packages("org.apache.ofbiz.ws.rs.security.auth");
-        packages("org.apache.ofbiz.ws.rs.spi.impl");
-        // packages("io.swagger.v3.jaxrs2.integration.resources"); 
//commenting it out
+        super(createResourceConfig());
+    }
+
+    private static ResourceConfig createResourceConfig() {
+        ResourceConfig config = new ResourceConfig();
+        config.packages("org.apache.ofbiz.ws.rs.resources");
+        config.packages("org.apache.ofbiz.ws.rs.security.auth");
+        config.packages("org.apache.ofbiz.ws.rs.spi.impl");
+        // config.packages("io.swagger.v3.jaxrs2.integration.resources"); 
//commenting it out
         // to generate customized OpenApi Spec
-        register(JacksonFeature.class);
-        register(MultiPartFeature.class);
-        register(ServiceContextCleanupFilter.class);
-        //property(ServerProperties.TRACING, "ALL");
+        config.register(JacksonFeature.class);
+        config.register(MultiPartFeature.class);
+        config.register(ServiceContextCleanupFilter.class);
+        //config.property(ServerProperties.TRACING, "ALL");
         if (Debug.verboseOn()) {
             // headers only, the ones carrying credentials or tokens being 
redacted: bodies can hold credentials and tokens
-            register(LoggingFeature.builder()
+            config.register(LoggingFeature.builder()
                     
.withLogger(Logger.getLogger(LoggingFeature.DEFAULT_LOGGER_NAME))
                     .level(Level.INFO)
                     .verbosity(LoggingFeature.Verbosity.HEADERS_ONLY)
                     .redactHeaders(List.of("Authorization", 
"Proxy-Authorization", "Cookie", "Set-Cookie", "Refresh-Token"))
                     .build());
         }
-        registerDSLResources();
-        EncodingFilter.enableFor(this, GZipEncoder.class);
-        EncodingFilter.enableFor(this, DeflateEncoder.class);
+        registerDSLResources(config);
+        EncodingFilter.enableFor(config, GZipEncoder.class);
+        EncodingFilter.enableFor(config, DeflateEncoder.class);
+        return config;
     }
 
     /**
@@ -100,12 +106,12 @@ public class OFBizApiConfig extends ResourceConfig {
         return MICRO_APIS;
     }
 
-    private void registerDSLResources() {
+    private static void registerDSLResources(ResourceConfig config) {
         loadApiDefinitions();
-        traverseAndRegisterApiDefinitions();
+        traverseAndRegisterApiDefinitions(config);
     }
 
-    private void loadApiDefinitions() {
+    private static void loadApiDefinitions() {
         Collection<ComponentConfig> components = 
ComponentConfig.getAllComponents();
         for (ComponentConfig component : components) {
             String componentName = component.getComponentName();
@@ -135,7 +141,7 @@ public class OFBizApiConfig extends ResourceConfig {
         }
     }
 
-    private void traverseAndRegisterApiDefinitions() {
+    private static void traverseAndRegisterApiDefinitions(ResourceConfig 
config) {
         if (UtilValidate.isEmpty(MICRO_APIS)) {
             Debug.logInfo("No API definitions to process", MODULE);
             return;
@@ -148,12 +154,12 @@ public class OFBizApiConfig extends ResourceConfig {
                         + " in group: " + groupPath, MODULE);
                 for (ModelResource resource : modelApi.getResources()) {
                     String resourcePath = buildCleanPath(groupPath, 
resource.getPath());
-                    registerModelResource(resource, resourcePath, 
registeredSignatures, modelApi.getName());
+                    registerModelResource(config, resource, resourcePath, 
registeredSignatures, modelApi.getName());
                 }
             }
         });
     }
-    private void registerModelResource(ModelResource modelResource, String 
basePath,
+    private static void registerModelResource(ResourceConfig config, 
ModelResource modelResource, String basePath,
             Set<String> registeredSignatures, String owningApiName) {
         if (!modelResource.isPublish()) return;
 
@@ -196,17 +202,17 @@ public class OFBizApiConfig extends ResourceConfig {
         }
 
         // Register the current resource
-        registerResources(resourceBuilder.build());
+        config.registerResources(resourceBuilder.build());
 
         // Recursively process nested sub-resources
         if (UtilValidate.isNotEmpty(modelResource.getSubResources())) {
             for (ModelResource sub : modelResource.getSubResources()) {
                 String subPath = buildCleanPath(basePath, sub.getPath());
-                registerModelResource(sub, subPath, registeredSignatures, 
owningApiName);
+                registerModelResource(config, sub, subPath, 
registeredSignatures, owningApiName);
             }
         }
     }
-    private String buildCleanPath(String... parts) {
+    private static String buildCleanPath(String... parts) {
         StringBuilder pathBuilder = new StringBuilder();
         for (String part : parts) {
             if (part == null || part.trim().isEmpty()) continue;
diff --git 
a/framework/webtools/src/main/java/org/apache/ofbiz/webtools/artifactinfo/ArtifactInfoBase.java
 
b/framework/webtools/src/main/java/org/apache/ofbiz/webtools/artifactinfo/ArtifactInfoBase.java
index 4dd7d39e70..85d198a325 100644
--- 
a/framework/webtools/src/main/java/org/apache/ofbiz/webtools/artifactinfo/ArtifactInfoBase.java
+++ 
b/framework/webtools/src/main/java/org/apache/ofbiz/webtools/artifactinfo/ArtifactInfoBase.java
@@ -26,7 +26,7 @@ import java.net.URL;
  */
 public abstract class ArtifactInfoBase implements Comparable<ArtifactInfoBase> 
{
 
-    private ArtifactInfoFactory aif;
+    private final ArtifactInfoFactory aif;
 
     /**
      * Gets aif.
diff --git 
a/framework/webtools/src/main/java/org/apache/ofbiz/webtools/artifactinfo/EntityArtifactInfo.java
 
b/framework/webtools/src/main/java/org/apache/ofbiz/webtools/artifactinfo/EntityArtifactInfo.java
index f4d0058b83..26bc02abdb 100644
--- 
a/framework/webtools/src/main/java/org/apache/ofbiz/webtools/artifactinfo/EntityArtifactInfo.java
+++ 
b/framework/webtools/src/main/java/org/apache/ofbiz/webtools/artifactinfo/EntityArtifactInfo.java
@@ -42,7 +42,7 @@ public class EntityArtifactInfo extends ArtifactInfoBase {
 
     public EntityArtifactInfo(String entityName, ArtifactInfoFactory aif) 
throws GenericEntityException {
         super(aif);
-        this.modelEntity = this.getAif().getModelEntity(entityName);
+        this.modelEntity = aif.getModelEntity(entityName);
     }
 
     /**
diff --git 
a/framework/webtools/src/main/java/org/apache/ofbiz/webtools/artifactinfo/ServiceArtifactInfo.java
 
b/framework/webtools/src/main/java/org/apache/ofbiz/webtools/artifactinfo/ServiceArtifactInfo.java
index 2516c35c29..24aaa012df 100644
--- 
a/framework/webtools/src/main/java/org/apache/ofbiz/webtools/artifactinfo/ServiceArtifactInfo.java
+++ 
b/framework/webtools/src/main/java/org/apache/ofbiz/webtools/artifactinfo/ServiceArtifactInfo.java
@@ -65,7 +65,7 @@ public class ServiceArtifactInfo extends ArtifactInfoBase {
 
     public ServiceArtifactInfo(String serviceName, ArtifactInfoFactory aif) 
throws GeneralException {
         super(aif);
-        this.modelService = this.getAif().getModelService(serviceName);
+        this.modelService = aif.getModelService(serviceName);
     }
 
     /**
diff --git 
a/framework/webtools/src/main/java/org/apache/ofbiz/webtools/labelmanager/LabelInfo.java
 
b/framework/webtools/src/main/java/org/apache/ofbiz/webtools/labelmanager/LabelInfo.java
index aea0407ac6..0a2fe38a0c 100644
--- 
a/framework/webtools/src/main/java/org/apache/ofbiz/webtools/labelmanager/LabelInfo.java
+++ 
b/framework/webtools/src/main/java/org/apache/ofbiz/webtools/labelmanager/LabelInfo.java
@@ -28,16 +28,18 @@ public class LabelInfo {
 
     private static final String MODULE = LabelInfo.class.getName();
 
-    private String labelKey = "";
-    private String labelKeyComment = "";
-    private String fileName = "";
-    private Map<String, LabelValue> labelValues = new LinkedHashMap<>();
+    private final String labelKey;
+    private String labelKeyComment;
+    private final String fileName;
+    private final Map<String, LabelValue> labelValues = new LinkedHashMap<>();
 
     public LabelInfo(String labelKey, String labelKeyComment, String fileName, 
String localeStr, String labelValue, String labelComment) {
         this.labelKey = labelKey;
         this.labelKeyComment = labelKeyComment;
         this.fileName = fileName;
-        setLabelValue(localeStr, labelValue, labelComment, false);
+        if (UtilValidate.isNotEmpty(labelValue)) {
+            labelValues.put(localeStr, new LabelValue(labelValue, 
labelComment));
+        }
     }
 
     /**

Reply via email to