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

jleroux 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 33fc03fa10 Fixed: Fix some bugs SpotBugs reports (OFBIZ-12386)
33fc03fa10 is described below

commit 33fc03fa10734455e96ff51936d30ad4c8961d2d
Author: Jacques Le Roux <jacques.le.r...@les7arts.com>
AuthorDate: Thu Jul 4 18:12:17 2024 +0200

    Fixed: Fix some bugs SpotBugs reports (OFBIZ-12386)
    
    After updating SpotBugs plugin to 4.8.6.r202406180231-6cf7b2c
    in Eclipse 2023-03 (4.27.0) it reported:
    
    <<Bug: Class (org.apache.ofbiz.webapp.WebAppCache) using singleton design 
pattern
    has non-private constructor.
    
    This class is using singleton design pattern and has non-private constructor
    (please note that a default constructor might exist which is not private).
    Given that, it is possible to create a copy of the object, thus violating 
the
    singleton pattern.  The easier solution would be making the constructor 
private.
    >>
    
    As it's also used by WebAppCacheTest class I made it package. That's safer 
but
    not enough so I also put it in exclude.xml
    Also Chekstyle wants it to be final
---
 .../webapp/src/main/java/org/apache/ofbiz/webapp/WebAppCache.java   | 4 ++--
 spotbugs/exclude.xml                                                | 6 ++++++
 2 files changed, 8 insertions(+), 2 deletions(-)

diff --git 
a/framework/webapp/src/main/java/org/apache/ofbiz/webapp/WebAppCache.java 
b/framework/webapp/src/main/java/org/apache/ofbiz/webapp/WebAppCache.java
index dd5f543b53..8095538d6a 100644
--- a/framework/webapp/src/main/java/org/apache/ofbiz/webapp/WebAppCache.java
+++ b/framework/webapp/src/main/java/org/apache/ofbiz/webapp/WebAppCache.java
@@ -45,7 +45,7 @@ import org.apache.ofbiz.base.util.UtilValidate;
  *
  * @see <a href="https://en.wikipedia.org/wiki/Memoization";>Memoization</a>
  */
-public class WebAppCache {
+public final class WebAppCache {
     // Synchronized map storing web applications.
     // The LinkedHashMap is used to maintain insertion order (which client 
code depends on).
     // There is no concurrent implementation of LinkedHashMap, so we are using 
manual synchronization instead.
@@ -57,7 +57,7 @@ public class WebAppCache {
      * Constructs an empty web application cache.
      * @param supplier the source from which components configurations are 
retrieved
      */
-    public WebAppCache(Supplier<Collection<ComponentConfig>> supplier) {
+    WebAppCache(Supplier<Collection<ComponentConfig>> supplier) {
         ccs = supplier;
         serverWebApps = new LinkedHashMap<>();
     }
diff --git a/spotbugs/exclude.xml b/spotbugs/exclude.xml
index a338b4c823..ec37597473 100644
--- a/spotbugs/exclude.xml
+++ b/spotbugs/exclude.xml
@@ -192,4 +192,10 @@ under the License.
     <Method name="equals" />
     <Bug pattern="EQ_CHECK_FOR_OPERAND_NOT_COMPATIBLE_WITH_THIS" />
   </Match><!-- ^ ^ not a problem, false positives -->
+  <Match>
+    <!-- As it's also used by WebAppCacheTest class I made it package. That's 
safer but not enough so it's also here -->
+    <Class name="org.apache.ofbiz.webapp.WebAppCache" />
+    <Method name="WebAppCache" />
+    <Bug pattern="SING_SINGLETON_HAS_NONPRIVATE_CONSTRUCTOR " />
+  </Match>
 </FindBugsFilter>

Reply via email to