Bug 574982 - [content assist] quick fix for java.util.Arrays not proposed in anonymous class
Summary: [content assist] quick fix for java.util.Arrays not proposed in anonymous class
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 4.20   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: 4.21 M2   Edit
Assignee: Snjezana Peco CLA
QA Contact: Stephan Herrmann CLA
URL:
Whiteboard:
Keywords: regression
Depends on:
Blocks: 574913
  Show dependency tree
 
Reported: 2021-07-22 14:32 EDT by Snjezana Peco CLA
Modified: 2021-08-19 07:47 EDT (History)
5 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Snjezana Peco CLA 2021-07-22 14:32:27 EDT
Steps to reproduce:

- open the following java file:

package test;
public class Test {
	private void test() {
		boolean equals = A|rrays.equals(new Object[0], new Object[0]); // CA works
		new Runnable() {
			@Override
			public void run() {
				boolean equals = A|rrays.equals(new Object[0], new Object[0]); // CA doesn't work
			}
		};
	}
}

- try CA at line 8. 

It doesn't work. The "Import Arrays (java.util)" quick fix is not shown.
Related issue - https://github.com/redhat-developer/vscode-java/issues/2034
The issue can't be reproduced in Eclipse 2020-09
Comment 1 Andrey Loskutov CLA 2021-07-22 14:43:51 EDT
Please check if that is still broken in latest 4.21 nightly build.
Comment 2 Snjezana Peco CLA 2021-07-22 15:22:25 EDT
(In reply to Andrey Loskutov from comment #1)
> Please check if that is still broken in latest 4.21 nightly build.

I can reproduce the issue in Eclipse I20210721-1800
Comment 3 Andrey Loskutov CLA 2021-07-22 15:28:14 EDT
(In reply to Snjezana Peco from comment #2)
> (In reply to Andrey Loskutov from comment #1)
> > Please check if that is still broken in latest 4.21 nightly build.
> 
> I can reproduce the issue in Eclipse I20210721-1800

Thanks. Sounds similar to bug 574978.
Comment 4 Snjezana Peco CLA 2021-07-22 16:22:44 EDT
(In reply to Andrey Loskutov from comment #3)
> (In reply to Snjezana Peco from comment #2)
> > (In reply to Andrey Loskutov from comment #1)
> > > Please check if that is still broken in latest 4.21 nightly build.
> > 
> > I can reproduce the issue in Eclipse I20210721-1800
> 
> Thanks. Sounds similar to bug 574978.

I can't reproduce the issue described in bug 574978 in Eclipse I20210721-1800.
Comment 5 Snjezana Peco CLA 2021-07-23 14:47:41 EDT
The following patch fixes the issue:

diff --git a/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/complete/CompletionParser.java b/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/complete/CompletionParser.java
index 6cb3d79bfc..740e864fa3 100644
--- a/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/complete/CompletionParser.java
+++ b/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/complete/CompletionParser.java
@@ -5405,7 +5405,7 @@ protected NameReference getUnspecifiedReference(boolean rejectTypeAnnotations) {
                char[] token = this.identifierStack[this.identifierPtr];
                long position = this.identifierPositionStack[this.identifierPtr--];
                int start = (int) (position >>> 32), end = (int) position;
-               if (this.assistNode == null && start < this.cursorLocation && end >= this.cursorLocation) {
+               if (this.assistNode == null && start <= this.cursorLocation && end >= this.cursorLocation) {
                        ref = new CompletionOnSingleNameReference(token, position, isInsideAttributeValue());
                        this.assistNode = ref;
                } else {
Comment 6 Andrey Loskutov CLA 2021-07-24 03:39:04 EDT
This is a regression in 4.20. In 4.19 I see that the quick fix to import java.util.Arrays is proposed on second Arrays.

(In reply to Snjezana Peco from comment #5)
> The following patch fixes the issue:

Can you please submit gerrit patch?
Comment 7 Eclipse Genie CLA 2021-07-24 10:13:22 EDT
New Gerrit change created: https://git.eclipse.org/r/c/jdt/eclipse.jdt.core/+/183339
Comment 8 Snjezana Peco CLA 2021-07-24 10:17:17 EDT
(In reply to Andrey Loskutov from comment #6)
> This is a regression in 4.20. In 4.19 I see that the quick fix to import
> java.util.Arrays is proposed on second Arrays.
> 
> (In reply to Snjezana Peco from comment #5)
> > The following patch fixes the issue:
> 
> Can you please submit gerrit patch?

I have created https://git.eclipse.org/r/c/jdt/eclipse.jdt.core/+/183339
Comment 10 Stephan Herrmann CLA 2021-07-24 16:02:27 EDT
(In reply to Eclipse Genie from comment #9)
> Gerrit change https://git.eclipse.org/r/c/jdt/eclipse.jdt.core/+/183339 was
> merged to [master].
> Commit:
> http://git.eclipse.org/c/jdt/eclipse.jdt.core.git/commit/
> ?id=8772e9b6f3b839164a752cc69ccd5e37939aa8f3

Released for 4.21 M2.

Thanks, Snjezana.
Comment 11 Sarika Sinha CLA 2021-08-19 07:47:34 EDT
Verified using I20210818-1800.