You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@netbeans.apache.org by sk...@apache.org on 2020/02/03 10:39:22 UTC

[netbeans] branch master updated: [NETBEANS-3286] Naive fix for CME in Call Hierarchy

This is an automated email from the ASF dual-hosted git repository.

skygo pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/netbeans.git


The following commit(s) were added to refs/heads/master by this push:
     new f87166e  [NETBEANS-3286] Naive fix for CME in Call Hierarchy
     new 30be81a  Merge pull request #1909 from lkishalmi/NETBEANS-3286
f87166e is described below

commit f87166e51d19391ec8f2d18b4b6776b2b9d3e30b
Author: Laszlo Kishalmi <la...@gmail.com>
AuthorDate: Fri Jan 31 10:31:32 2020 -0800

    [NETBEANS-3286] Naive fix for CME in Call Hierarchy
---
 .../source/parsing/ParameterNameProviderImpl.java  | 71 +++++++++++++---------
 1 file changed, 41 insertions(+), 30 deletions(-)

diff --git a/java/java.source.base/src/org/netbeans/modules/java/source/parsing/ParameterNameProviderImpl.java b/java/java.source.base/src/org/netbeans/modules/java/source/parsing/ParameterNameProviderImpl.java
index 2f22002..9839a43 100644
--- a/java/java.source.base/src/org/netbeans/modules/java/source/parsing/ParameterNameProviderImpl.java
+++ b/java/java.source.base/src/org/netbeans/modules/java/source/parsing/ParameterNameProviderImpl.java
@@ -42,6 +42,7 @@ import java.lang.reflect.Proxy;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collections;
+import java.util.ConcurrentModificationException;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Iterator;
@@ -117,42 +118,50 @@ public class ParameterNameProviderImpl {
     public CharSequence getParameterName(VariableElement parameter) {
         Element method = parameter.getEnclosingElement();
         String methodKey = computeKey(method);
-        List<String> names;
+        List<String> names = null;
 
         //from sources:
         {
-        Element topLevel = parameter;
-        while (topLevel.getEnclosingElement().getKind() != ElementKind.PACKAGE) {
-            topLevel = topLevel.getEnclosingElement();
-        }
-        ElementHandle<?> topLevelHandle = ElementHandle.create(topLevel);
-
-        names = source_toplevelClass2method2Parameters.computeIfAbsent(computeKey(topLevel), d -> {
-            Map<String, List<String>> parametersInClass = new HashMap<>();
-            FileObject source = SourceUtils.getFile(topLevelHandle, cpInfo);
-            JavaSource javaSource = source != null ? JavaSource.forFileObject(source) : null;
-            if (javaSource != null) {
-                try {
-                    javaSource.runUserActionTask(cc -> {
-                        cc.toPhase(JavaSource.Phase.ELEMENTS_RESOLVED);
-                        new TreePathScanner<Void, Void>() {
-                            public Void visitMethod(MethodTree mt, Void v) {
-                                Element el = cc.getTrees().getElement(getCurrentPath());
-                                if (el != null && el.getKind() == ElementKind.METHOD) {
-                                    parametersInClass.put(computeKey(el), ((ExecutableElement) el).getParameters().stream().map(p -> p.getSimpleName().toString()).collect(Collectors.toList()));
-                                }
-                                return super.visitMethod(mt, v);
-                            }
-                        }.scan(cc.getCompilationUnit(), null);
-                    }, true);
-                } catch (IOException ex) {
-                    //ignore
+            Element topLevel = parameter;
+            while (topLevel.getEnclosingElement().getKind() != ElementKind.PACKAGE) {
+                topLevel = topLevel.getEnclosingElement();
+            }
+            ElementHandle<?> topLevelHandle = ElementHandle.create(topLevel);
+
+            String topLevelKey = computeKey(topLevel);
+            try {
+                names = source_toplevelClass2method2Parameters.computeIfAbsent(topLevelKey, d -> {
+                    Map<String, List<String>> parametersInClass = new HashMap<>();
+                    FileObject source = SourceUtils.getFile(topLevelHandle, cpInfo);
+                    JavaSource javaSource = source != null ? JavaSource.forFileObject(source) : null;
+                    if (javaSource != null) {
+                        try {
+                            javaSource.runUserActionTask(cc -> {
+                                cc.toPhase(JavaSource.Phase.ELEMENTS_RESOLVED);
+                                new TreePathScanner<Void, Void>() {
+                                    public Void visitMethod(MethodTree mt, Void v) {
+                                        Element el = cc.getTrees().getElement(getCurrentPath());
+                                        if (el != null && el.getKind() == ElementKind.METHOD) {
+                                            parametersInClass.put(computeKey(el), ((ExecutableElement) el).getParameters().stream().map(p -> p.getSimpleName().toString()).collect(Collectors.toList()));
+                                        }
+                                        return super.visitMethod(mt, v);
+                                    }
+                                }.scan(cc.getCompilationUnit(), null);
+                            }, true);
+                        } catch (IOException ex) {
+                            //ignore
+                        }
+                    }
+                    return parametersInClass;
+                }).get(methodKey);
+            } catch(ConcurrentModificationException ex) {
+                // Naive fix for CME, we assume that some other thread computed
+                // the required results. NETBEANS-3286
+                if (source_toplevelClass2method2Parameters.containsKey(topLevelKey)) {
+                    names = source_toplevelClass2method2Parameters.get(topLevelKey).get(methodKey);
                 }
             }
-            return parametersInClass;
-        }).get(methodKey);
         }
-
         if (names == null) {
             Element clazzCandidate = method.getEnclosingElement();
             if (clazzCandidate != null && (clazzCandidate.getKind().isClass() || clazzCandidate.getKind().isInterface())) {
@@ -186,6 +195,8 @@ public class ParameterNameProviderImpl {
         return idx != (-1) && idx < names.size() ? names.get(idx) : null;
     }
 
+
+
     private static String computeKey(Element el) {
         return Arrays.stream(SourceUtils.getJVMSignature(ElementHandle.create(el))).collect(Collectors.joining(":"));
     }


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@netbeans.apache.org
For additional commands, e-mail: commits-help@netbeans.apache.org

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