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 0fc76c035a Remove this-escape warnings in the Artifact Info factory
and controller views
0fc76c035a is described below
commit 0fc76c035a78c3e6b5badaecc1004e2c55ce2dba
Author: Mridul Pathak <[email protected]>
AuthorDate: Fri Oct 30 15:38:47 2026 +0530
Remove this-escape warnings in the Artifact Info factory and controller
views
ArtifactInfoFactory built the whole artifact graph from its constructor
through the public prepareAll method, and ControllerViewArtifactInfo resolved
its screen and added itself to the factory's reverse references from its
constructor, before the factory had registered it. A view reached again through
its own screen while it was still being constructed was then created a second
time.
ArtifactInfoFactory is now final with a private constructor that only
assigns its fields; getArtifactInfoFactory builds the graph with the now
private prepareAll before publishing the factory. ControllerViewArtifactInfo
links itself in a new populateAll method that the factory calls once the view
is registered, as it already does for the other artifact types.
---
.../webtools/artifactinfo/ArtifactInfoFactory.java | 20 +++++++++-----------
.../artifactinfo/ControllerViewArtifactInfo.java | 13 +++++++++----
2 files changed, 18 insertions(+), 15 deletions(-)
diff --git
a/framework/webtools/src/main/java/org/apache/ofbiz/webtools/artifactinfo/ArtifactInfoFactory.java
b/framework/webtools/src/main/java/org/apache/ofbiz/webtools/artifactinfo/ArtifactInfoFactory.java
index bf31859aec..2d18298bb7 100644
---
a/framework/webtools/src/main/java/org/apache/ofbiz/webtools/artifactinfo/ArtifactInfoFactory.java
+++
b/framework/webtools/src/main/java/org/apache/ofbiz/webtools/artifactinfo/ArtifactInfoFactory.java
@@ -64,7 +64,7 @@ import org.xml.sax.SAXException;
/**
* The type Artifact info factory.
*/
-public class ArtifactInfoFactory {
+public final class ArtifactInfoFactory {
private static final String MODULE = ArtifactInfoFactory.class.getName();
@@ -275,12 +275,15 @@ public class ArtifactInfoFactory {
ArtifactInfoFactory aif =
ARTIFACT_INFO_FACTORY_CACHE.get(delegatorName);
if (aif == null) {
- aif = ARTIFACT_INFO_FACTORY_CACHE.putIfAbsentAndGet(delegatorName,
new ArtifactInfoFactory(delegatorName));
+ ArtifactInfoFactory newAif = new
ArtifactInfoFactory(delegatorName);
+ // build the whole artifact graph before the factory is published
+ newAif.prepareAll();
+ aif = ARTIFACT_INFO_FACTORY_CACHE.putIfAbsentAndGet(delegatorName,
newAif);
}
return aif;
}
- protected ArtifactInfoFactory(String delegatorName) throws
GeneralException {
+ private ArtifactInfoFactory(String delegatorName) throws GeneralException {
this.entityModelReader = ModelReader.getModelReader(delegatorName);
DelegatorElement delegatorInfo =
EntityConfig.getInstance().getDelegator(delegatorName);
String modelName;
@@ -292,15 +295,9 @@ public class ArtifactInfoFactory {
// since we do not associate a dispatcher to this DispatchContext, it
is important to set a name of an existing entity model reader:
// in this way it will be possible to retrieve the service models from
the cache
this.dispatchContext = new DispatchContext(modelName,
this.getClass().getClassLoader(), null);
-
- this.prepareAll();
}
- /**
- * Prepare all.
- * @throws GeneralException the general exception
- */
- public void prepareAll() throws GeneralException {
+ private void prepareAll() throws GeneralException {
Debug.logInfo("Loading artifact info objects...", MODULE);
List<Future<Void>> futures = new ArrayList<>();
Set<String> entityNames = this.getEntityModelReader().getEntityNames();
@@ -587,10 +584,11 @@ public class ArtifactInfoFactory {
ControllerViewArtifactInfo curInfo =
this.allControllerViewInfos.get(controllerXmlUrl.toExternalForm() + "#" +
viewUri);
if (curInfo == null) {
ControllerViewArtifactInfo newInfo = new
ControllerViewArtifactInfo(controllerXmlUrl, viewUri, this);
- // if another thread registered the same view meanwhile, use that
one
+ // if another thread registered the same artifact meanwhile, use
that one and leave its population to that thread
curInfo =
this.allControllerViewInfos.putIfAbsent(newInfo.getUniqueId(), newInfo);
if (curInfo == null) {
curInfo = newInfo;
+ curInfo.populateAll();
}
}
return curInfo;
diff --git
a/framework/webtools/src/main/java/org/apache/ofbiz/webtools/artifactinfo/ControllerViewArtifactInfo.java
b/framework/webtools/src/main/java/org/apache/ofbiz/webtools/artifactinfo/ControllerViewArtifactInfo.java
index 872761db23..3857b23386 100644
---
a/framework/webtools/src/main/java/org/apache/ofbiz/webtools/artifactinfo/ControllerViewArtifactInfo.java
+++
b/framework/webtools/src/main/java/org/apache/ofbiz/webtools/artifactinfo/ControllerViewArtifactInfo.java
@@ -32,9 +32,9 @@ import org.apache.ofbiz.webapp.control.ConfigXMLReader;
*
*/
public class ControllerViewArtifactInfo extends ArtifactInfoBase {
- private URL controllerXmlUrl;
- private String viewUri;
- private ConfigXMLReader.ViewMap viewInfoMap;
+ private final URL controllerXmlUrl;
+ private final String viewUri;
+ private final ConfigXMLReader.ViewMap viewInfoMap;
private ScreenWidgetArtifactInfo screenCalledByThisView = null;
public ControllerViewArtifactInfo(URL controllerXmlUrl, String viewUri,
ArtifactInfoFactory aif) throws GeneralException {
@@ -51,6 +51,11 @@ public class ControllerViewArtifactInfo extends
ArtifactInfoBase {
if (this.viewInfoMap == null) {
throw new GeneralException("Controller view with name [" + viewUri
+ "] is not defined in controller file [" + controllerXmlUrl + "].");
}
+ }
+
+ /** note this is mean to be called after the object is created and added
to the ArtifactInfoFactory.allControllerViewInfos in
+ * ArtifactInfoFactory.getControllerViewArtifactInfo */
+ public void populateAll() throws GeneralException {
// populate screenCalledByThisView and reverse in
aif.allViewInfosReferringToScreen
if ("screen".equals(this.viewInfoMap.getType()) ||
"screenfop".equals(this.viewInfoMap.getType())
|| "screentext".equals(this.viewInfoMap.getType()) ||
"screenxml".equals(this.viewInfoMap.getType())) {
@@ -61,7 +66,7 @@ public class ControllerViewArtifactInfo extends
ArtifactInfoBase {
fullScreenName.substring(0, poundIndex));
if (this.screenCalledByThisView != null) {
// add the reverse association
- addToSortedSetInMap(this,
aif.getAllViewInfosReferringToScreen(),
this.screenCalledByThisView.getUniqueId());
+ addToSortedSetInMap(this,
this.getAif().getAllViewInfosReferringToScreen(),
this.screenCalledByThisView.getUniqueId());
}
}
}