sdedic commented on code in PR #5998:
URL: https://github.com/apache/netbeans/pull/5998#discussion_r1218304169


##########
java/maven/src/org/netbeans/modules/maven/problems/MavenModelProblemsProvider.java:
##########
@@ -144,59 +172,87 @@ Collection<? extends ProjectProblem> 
doGetProblems(boolean sync) {
                 
project.getLookup().lookup(NbMavenProject.class).addPropertyChangeListener(projectListener);
             
             }
-            
+            MavenProject o = analysedProject.get();
+            LOG.log(Level.FINER, "Called getProblems for {0}, analysed = {1}, 
current = {2}", 
+                    new Object[] { project, o == null ? 0 : 
System.identityHashCode(o), System.identityHashCode(updatedPrj) });
             //for non changed project models, no need to recalculate, always 
return the cached value
-            Object wasprocessed = 
prj.getContextValue(MavenModelProblemsProvider.class.getName());
-            if (wasprocessed != null) {
-                Collection<ProjectProblem> cached = problemsCache.get();
-                LOG.log(Level.FINER, "Project was processed, cached is: {0}", 
cached);
+            Object wasprocessed = 
updatedPrj.getContextValue(MavenModelProblemsProvider.class.getName());
+            if (o == updatedPrj && wasprocessed != null) {
+                Pair<Collection<ProjectProblem>, Boolean> cached = 
problemsCache.get();
+                LOG.log(Level.FINER, "getProblems: Project was processed, 
cached is: {0}", cached);
                 if (cached != null) {
                     return cached;
                 }
             } 
-            Callable<Collection<? extends ProjectProblem>> c = new 
Callable<Collection<? extends ProjectProblem>>() {
+            
+            SanityBuildAction sba = cachedSanityBuild.get();
+            if (sba != null && sba.getPendingResult() == null) {
+                cachedSanityBuild.clear();
+            }
+            c = new Callable<Pair<Collection<ProjectProblem>, Boolean>>() {
                 @Override
-                public Collection<? extends ProjectProblem> call() throws 
Exception {
-                    Object wasprocessed = 
prj.getContextValue(MavenModelProblemsProvider.class.getName());
-                    if (wasprocessed != null) {
-                        Collection<ProjectProblem> cached = 
problemsCache.get();
-                        LOG.log(Level.FINER, "Project was processed #2, cached 
is: {0}", cached);
+                public Pair<Collection<ProjectProblem>, Boolean> call() throws 
Exception {
+                    // double check, the project may be invalidated during the 
time.
+                    MavenProject prj = 
((NbMavenProjectImpl)project).getFreshOriginalMavenProject();
+                    Object wasprocessed = 
updatedPrj.getContextValue(MavenModelProblemsProvider.class.getName());
+                    if (o == updatedPrj && wasprocessed != null) {
+                        Pair<Collection<ProjectProblem>, Boolean> cached = 
problemsCache.get();
+                        LOG.log(Level.FINER, "getProblems: Project was 
processed #2, cached is: {0}", cached);
                         if (cached != null) {                            
                             return cached;
                         }
                     } 
-                    List<ProjectProblem> toRet = new ArrayList<>();
-                    MavenExecutionResult res = 
MavenProjectCache.getExecutionResult(prj);
-                    if (res != null && res.hasExceptions()) {
-                        toRet.addAll(reportExceptions(res));
+                    int round = 0;
+                    List<ProjectProblem> toRet = null;
+                    while (round < 3) {
+                        try {
+                            synchronized (MavenModelProblemsProvider.this) {
+                                sanityBuildStatus = false;
+                                toRet = new ArrayList<>();
+                                MavenExecutionResult res = 
MavenProjectCache.getExecutionResult(prj);
+                                if (res != null && res.hasExceptions()) {
+                                    toRet.addAll(reportExceptions(res));
+                                }
+                                //#217286 doArtifactChecks can call 
FileOwnerQuery and attempt to aquire the project mutex.
+                                toRet.addAll(doArtifactChecks(prj));
+                                //mark the project model as checked once and 
cached
+                                
prj.setContextValue(MavenModelProblemsProvider.class.getName(), new Object());
+                                synchronized(MavenModelProblemsProvider.this) {

Review Comment:
   Good catch ... in addition, the `firePropertyChange` should go outside.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists

Reply via email to