tmysik commented on a change in pull request #2241:
URL: https://github.com/apache/netbeans/pull/2241#discussion_r450757749



##########
File path: 
php/php.editor/src/org/netbeans/modules/php/editor/model/VariableScopeFinder.java
##########
@@ -45,10 +51,22 @@ public VariableScope find(final Scope scope, final int 
offset, final ScopeRangeA
     }
 
     public VariableScope find(final List<? extends ModelElement> elements, 
final int offset, final ScopeRangeAcceptor scopeRangeAcceptor) {
-        return findWrapper(elements, offset, 
scopeRangeAcceptor).getVariableScope();
+        AtomicBoolean isLazilyScanned = new AtomicBoolean(false);
+        VariableScope variableScope = findWrapper(elements, offset, 
scopeRangeAcceptor, isLazilyScanned).getVariableScope();
+        if (isLazilyScanned.get()) {
+            // some scopes may be added new elements when LazyBuild elements 
are scanned.
+            // so, find again.
+            // e.g. Source instances are cached as weak references.
+            // so, ParserResult may not be the same instance even if the 
FileObject is the same.
+            // it means that new Model and new ModelVisitor are created again. 
in such case, LazyBuild elements may not be scanned yet.
+            LOGGER.log(Level.FINE, "(LazyBuild)Scope is scanned."); // NOI18N
+            isLazilyScanned.set(false);

Review comment:
       If it is running in only one thread (as here I guess, in the _parsing_ 
thread) then `AtomicBoolean` is just a holder for a boolean. So, using 
`compareAndSet()` is IMHO not necessary.
   




----------------------------------------------------------------
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.

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