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 2143490964 Remove this-escape warnings in ConfigXMLReader, 
FlexibleServletAccessor and RecordIterator
2143490964 is described below

commit 21434909647565ac38abdf7da2e44ecd11e32290
Author: Mridul Pathak <[email protected]>
AuthorDate: Fri Oct 30 11:34:24 2026 +0530

    Remove this-escape warnings in ConfigXMLReader, FlexibleServletAccessor and 
RecordIterator
    
    The constructors of ControllerConfig, FlexibleServletAccessor and 
RecordIterator called overridable methods, so javac reports a possible 
this-escape for each of them. ControllerConfig.loadIncludes, which nothing 
outside the class calls, is now private. FlexibleServletAccessor assigns its 
fields directly in the constructor and makes them final, and its protected init 
method is removed; the two-argument constructor delegates to the one-argument 
one. RecordIterator assigns its reader, mo [...]
---
 .../util/collections/FlexibleServletAccessor.java  | 30 +++++------------
 .../org/apache/ofbiz/datafile/RecordIterator.java  | 38 ++++++++++++++--------
 .../ofbiz/webapp/control/ConfigXMLReader.java      |  2 +-
 3 files changed, 34 insertions(+), 36 deletions(-)

diff --git 
a/framework/base/src/main/java/org/apache/ofbiz/base/util/collections/FlexibleServletAccessor.java
 
b/framework/base/src/main/java/org/apache/ofbiz/base/util/collections/FlexibleServletAccessor.java
index 8e951c43ed..b92db44174 100644
--- 
a/framework/base/src/main/java/org/apache/ofbiz/base/util/collections/FlexibleServletAccessor.java
+++ 
b/framework/base/src/main/java/org/apache/ofbiz/base/util/collections/FlexibleServletAccessor.java
@@ -39,29 +39,13 @@ import 
org.apache.ofbiz.base.util.string.FlexibleStringExpander;
 @SuppressWarnings("serial")
 public class FlexibleServletAccessor<T> implements Serializable {
 
-    private String name;
-    private String attributeName;
-    private FlexibleMapAccessor<T> fma;
-    private boolean needsExpand;
-    private boolean empty;
+    private final String name;
+    private final String attributeName;
+    private final FlexibleMapAccessor<T> fma;
+    private final boolean needsExpand;
+    private final boolean empty;
 
     public FlexibleServletAccessor(String name) {
-        init(name);
-    }
-
-    public FlexibleServletAccessor(String name, String defaultName) {
-        if (UtilValidate.isEmpty(name)) {
-            init(defaultName);
-        } else {
-            init(name);
-        }
-    }
-
-    /**
-     * Init.
-     * @param name the name
-     */
-    protected void init(String name) {
         this.name = name;
         if (UtilValidate.isEmpty(name)) {
             empty = true;
@@ -90,6 +74,10 @@ public class FlexibleServletAccessor<T> implements 
Serializable {
         }
     }
 
+    public FlexibleServletAccessor(String name, String defaultName) {
+        this(UtilValidate.isEmpty(name) ? defaultName : name);
+    }
+
     /**
      * Is empty boolean.
      * @return the boolean
diff --git 
a/framework/datafile/src/main/java/org/apache/ofbiz/datafile/RecordIterator.java
 
b/framework/datafile/src/main/java/org/apache/ofbiz/datafile/RecordIterator.java
index 8ec4cacae9..f568660485 100644
--- 
a/framework/datafile/src/main/java/org/apache/ofbiz/datafile/RecordIterator.java
+++ 
b/framework/datafile/src/main/java/org/apache/ofbiz/datafile/RecordIterator.java
@@ -34,10 +34,10 @@ import java.util.Stack;
  */
 public class RecordIterator {
 
-    private BufferedReader br;
-    private ModelDataFile modelDataFile;
+    private final BufferedReader br;
+    private final ModelDataFile modelDataFile;
     private boolean closed = false;
-    private String locationInfo;
+    private final String locationInfo;
 
     private int nextLineNum = 0;
     private String curLine = null;
@@ -49,6 +49,7 @@ public class RecordIterator {
 
     public RecordIterator(URL fileUrl, ModelDataFile modelDataFile) throws 
DataFileException {
         this.modelDataFile = modelDataFile;
+        this.locationInfo = fileUrl.toString();
 
         InputStream urlStream = null;
         try {
@@ -65,7 +66,9 @@ public class RecordIterator {
             throw new DataFileException("Error open URL: " + 
fileUrl.toString(), e);
         }
         try {
-            this.setupStream(urlStream, fileUrl.toString());
+            this.br = openReader(urlStream, modelDataFile);
+            // get the line seeded
+            this.getNextLine();
         } catch (DataFileException | RuntimeException e) {
             // the stream was opened here, so close it when the iterator 
cannot be created
             try {
@@ -79,33 +82,36 @@ public class RecordIterator {
 
     public RecordIterator(InputStream dataFileStream, ModelDataFile 
modelDataFile, String locationInfo) throws DataFileException {
         this.modelDataFile = modelDataFile;
-        this.setupStream(dataFileStream, locationInfo);
+        this.locationInfo = locationInfo;
+        this.br = openReader(dataFileStream, modelDataFile);
+        // get the line seeded
+        this.getNextLine();
     }
 
     /**
-     * Sets stream.
+     * Opens a reader on the data file stream, positioned at the start line of 
the data file.
      * @param dataFileStream the data file stream
-     * @param locationInfo   the location info
+     * @param modelDataFile  the model of the data file
+     * @return the reader
      * @throws DataFileException the data file exception
      */
-    protected void setupStream(InputStream dataFileStream, String 
locationInfo) throws DataFileException {
-        this.locationInfo = locationInfo;
+    private static BufferedReader openReader(InputStream dataFileStream, 
ModelDataFile modelDataFile) throws DataFileException {
         String charsetStr = modelDataFile.getEncodingType();
+        BufferedReader reader;
         try {
-            this.br = new BufferedReader(new InputStreamReader(dataFileStream, 
Charset.forName(charsetStr)));
+            reader = new BufferedReader(new InputStreamReader(dataFileStream, 
Charset.forName(charsetStr)));
         } catch (Exception e) {
             throw new DataFileException(charsetStr + " is not supported", e);
         }
         //move the cursor to the good start line
         try {
             for (int i = 0; i < modelDataFile.getStartLine(); i++) {
-                br.readLine();
+                reader.readLine();
             }
         } catch (IOException e) {
             throw new DataFileException("Impossible to read the buffer", e);
         }
-        // get the line seeded
-        this.getNextLine();
+        return reader;
     }
 
     /**
@@ -155,7 +161,7 @@ public class RecordIterator {
             }
             return true;
         } else {
-            this.close();
+            this.closeReader();
             return false;
         }
     }
@@ -248,6 +254,10 @@ public class RecordIterator {
      * @throws DataFileException the data file exception
      */
     public void close() throws DataFileException {
+        closeReader();
+    }
+
+    private void closeReader() throws DataFileException {
         if (this.closed) {
             return;
         }
diff --git 
a/framework/webapp/src/main/java/org/apache/ofbiz/webapp/control/ConfigXMLReader.java
 
b/framework/webapp/src/main/java/org/apache/ofbiz/webapp/control/ConfigXMLReader.java
index 17c2f6f2cd..e340157fee 100644
--- 
a/framework/webapp/src/main/java/org/apache/ofbiz/webapp/control/ConfigXMLReader.java
+++ 
b/framework/webapp/src/main/java/org/apache/ofbiz/webapp/control/ConfigXMLReader.java
@@ -535,7 +535,7 @@ public final class ConfigXMLReader {
          * @param rootElement the root element
          * @throws WebAppConfigurationException the web app configuration 
exception
          */
-        protected void loadIncludes(Element rootElement) throws 
WebAppConfigurationException {
+        private void loadIncludes(Element rootElement) throws 
WebAppConfigurationException {
             for (Element includeElement : 
UtilXml.childElementList(rootElement, "include")) {
                 String includeLocation = 
includeElement.getAttribute("location");
                 if (!includeLocation.isEmpty()) {

Reply via email to