Skip to content

Commit

Permalink
Merge pull request #4216 from pdudits/payara-4131
Browse files Browse the repository at this point in the history
PAYARA-4131: Fix race conditions in resource class generation
  • Loading branch information
pdudits committed Sep 12, 2019
2 parents 73b8139 + a319736 commit 473b0bf
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
Expand Up @@ -192,12 +192,14 @@ private void registerExtendedWadlConfig(Set<Class<?>> classes,

private void generateASM(ServiceLocator habitat) {
try {
Domain entity = habitat.getService(Domain.class);
Dom dom = Dom.unwrap(entity);
synchronized (RestManagementResourceProvider.class) {
Domain entity = habitat.getService(Domain.class);
Dom dom = Dom.unwrap(entity);

ResourcesGenerator resourcesGenerator = new ASMResourcesGenerator(habitat);
resourcesGenerator.generateSingle(dom.document.getRoot().model, dom.document);
resourcesGenerator.endGeneration();
ResourcesGenerator resourcesGenerator = new ASMResourcesGenerator(habitat);
resourcesGenerator.generateSingle(dom.document.getRoot().model, dom.document);
resourcesGenerator.endGeneration();
}
} catch (Exception ex) {
RestLogging.restLogger.log(Level.SEVERE, null, ex);
}
Expand Down
Expand Up @@ -62,7 +62,7 @@
*/
public abstract class ResourcesGeneratorBase implements ResourcesGenerator {

private static Set<String> alreadyGenerated = new HashSet<String>();
private static Set<String> alreadyGenerated = Collections.synchronizedSet(new HashSet<String>());
ServiceLocator habitat;

public ResourcesGeneratorBase(ServiceLocator habitat) {
Expand Down Expand Up @@ -144,6 +144,7 @@ public void generateSingle(ConfigModel model, DomDocument domDocument) {

classWriter.done();
}
alreadyGenerated.add(className);
}

public void generateList(ConfigModel model, DomDocument domDocument) {
Expand Down Expand Up @@ -376,12 +377,7 @@ private void generateCommandResourceClass(String parentBeanName, CommandResource
* @return true if the given className is already generated. false otherwise.
*/
protected boolean alreadyGenerated(String className) {
boolean retVal = true;
if (!alreadyGenerated.contains(className)) {
alreadyGenerated.add(className);
retVal = false;
}
return retVal;
return alreadyGenerated.contains(className);
}

/**
Expand Down

0 comments on commit 473b0bf

Please sign in to comment.