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 5aea1fb  [NETBEANS-4177] Add another check for valid parameter list 
position to avoid exception if sourcecode is incorrect
     new 976501a  Merge pull request #2082 from graben/NETBEANS-4177
5aea1fb is described below

commit 5aea1fb3704f48abac571b04eb153507e39b59d3
Author: Benjamin Graf <[email protected]>
AuthorDate: Wed Apr 15 20:27:44 2020 +0200

    [NETBEANS-4177] Add another check for valid parameter list position to 
avoid exception if sourcecode is incorrect
---
 .../base/semantic/SemanticHighlighterBase.java       | 20 +++++++++++---------
 .../java/editor/base/semantic/DetectorTest.java      | 18 ++++++++++++++++++
 2 files changed, 29 insertions(+), 9 deletions(-)

diff --git 
a/java/java.editor.base/src/org/netbeans/modules/java/editor/base/semantic/SemanticHighlighterBase.java
 
b/java/java.editor.base/src/org/netbeans/modules/java/editor/base/semantic/SemanticHighlighterBase.java
index 51bf0a4..00d3687 100644
--- 
a/java/java.editor.base/src/org/netbeans/modules/java/editor/base/semantic/SemanticHighlighterBase.java
+++ 
b/java/java.editor.base/src/org/netbeans/modules/java/editor/base/semantic/SemanticHighlighterBase.java
@@ -1230,15 +1230,17 @@ public abstract class SemanticHighlighterBase extends 
JavaParserResultTask {
                         long end = start + 1;
                         ExecutableElement invokedMethod = (ExecutableElement) 
invoked;
                         pos = Math.min(pos, 
invokedMethod.getParameters().size() - 1);
-                        boolean shouldBeAdded = true;
-                        if (tree.getKind() == Kind.IDENTIFIER &&
-                                
invokedMethod.getParameters().get(pos).getSimpleName().equals(
-                                        
IdentifierTree.class.cast(tree).getName())) {
-                            shouldBeAdded = false;
-                        }
-                        if (shouldBeAdded) {
-                            preText.put(new int[] {(int) start, (int) end},
-                                        
invokedMethod.getParameters().get(pos).getSimpleName() + ":");
+                        if (pos != (-1)) {
+                            boolean shouldBeAdded = true;
+                            if (tree.getKind() == Kind.IDENTIFIER &&
+                                    
invokedMethod.getParameters().get(pos).getSimpleName().equals(
+                                            
IdentifierTree.class.cast(tree).getName())) {
+                                shouldBeAdded = false;
+                            }
+                            if (shouldBeAdded) {
+                                preText.put(new int[] {(int) start, (int) end},
+                                            
invokedMethod.getParameters().get(pos).getSimpleName() + ":");
+                            }
                         }
                     }
                 }
diff --git 
a/java/java.editor.base/test/unit/src/org/netbeans/modules/java/editor/base/semantic/DetectorTest.java
 
b/java/java.editor.base/test/unit/src/org/netbeans/modules/java/editor/base/semantic/DetectorTest.java
index 52d3538..03cd5e6 100644
--- 
a/java/java.editor.base/test/unit/src/org/netbeans/modules/java/editor/base/semantic/DetectorTest.java
+++ 
b/java/java.editor.base/test/unit/src/org/netbeans/modules/java/editor/base/semantic/DetectorTest.java
@@ -646,6 +646,24 @@ public class DetectorTest extends TestBase {
                     "[PUBLIC, METHOD], 2:46-2:53");
     }
 
+    public void testInvalidParameterList() throws Exception {
+        setShowPrependedText(true);
+        performTest("Test.java",
+                    "public class BugSemanticHighlighterBase {\n" +
+                    "    private Object testMethod(final String arg1 final 
String arg2) {\n" +
+                    "        return new String(\"\");\n" +
+                    "    }\n" +
+                    "}\n",
+                    "[PUBLIC, CLASS, DECLARATION], 0:13-0:39",
+                    "[PUBLIC, CLASS], 1:12-1:18",
+                    "[PRIVATE, METHOD, UNUSED, DECLARATION], 1:19-1:29",
+                    "[PUBLIC, CLASS], 1:36-1:42",
+                    "[PARAMETER, UNUSED, DECLARATION], 1:43-1:47",
+                    "[PUBLIC, CLASS], 1:54-1:60",
+                    "[PACKAGE_PRIVATE, FIELD, DECLARATION], 1:61-1:65",
+                    "[PACKAGE_PRIVATE, CONSTRUCTOR], 2:19-2:25");
+    }
+
     private void performTest(String fileName) throws Exception {
         performTest(fileName, new Performer() {
             public void compute(CompilationController parameter, Document doc, 
final ErrorDescriptionSetter setter) {


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