Skip to content

Commit

Permalink
Fixed: Fix some bugs SpotBugs reports (OFBIZ-12386)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
JacquesLeRoux committed Jul 5, 2024
1 parent b365f9d commit 33fc03f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
*
* @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.
Expand All @@ -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<>();
}
Expand Down
6 changes: 6 additions & 0 deletions spotbugs/exclude.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>

0 comments on commit 33fc03f

Please sign in to comment.