Bug 235658 - Valid identifier unrecognized.
Summary: Valid identifier unrecognized.
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.4   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.6 M6   Edit
Assignee: Ayushman Jain CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-06-04 13:46 EDT by Brian Miller CLA
Modified: 2017-09-06 10:04 EDT (History)
4 users (show)

See Also:
Olivier_Thomann: review+


Attachments
proposed fix v1.0 + regression tests (4.34 KB, patch)
2010-03-05 03:59 EST, Ayushman Jain CLA
Olivier_Thomann: iplog+
Details | Diff
Proposed fix + regression test (4.85 KB, patch)
2010-03-05 17:21 EST, Olivier Thomann CLA
no flags Details | Diff
Proposed fix + regression test (4.65 KB, patch)
2010-03-05 17:24 EST, Olivier Thomann CLA
no flags Details | Diff
Proposed fix + regression test (4.66 KB, patch)
2010-03-08 11:09 EST, Olivier Thomann CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Brian Miller CLA 2008-06-04 13:46:47 EDT
Build ID: I20080330-1350

Steps To Reproduce:
1. Select the identifier Proto on LINE 4.
2. Pick the "Navigate>>Open Declaration" menu item.  The request fails.  See in the status bar this complaint:

    "Current text selection cannot be opened in an editor"

------------ Foo.java -----------------
import bug.Bug;
import bug.Bug.*;
class Foo extends Bug implements
Proto //LINE 4
{}

--------------- bug/Bug.java ---------
package bug;
public class Bug{
        protected interface Proto{};
}
Comment 1 Martin Aeschlimann CLA 2008-06-05 04:06:34 EDT
ICompilationUnit.codeSelect returns an empty array here.
Comment 2 Srikanth Sankaran CLA 2010-03-01 06:33:09 EST
Ayush, please take a look.
Comment 3 Ayushman Jain CLA 2010-03-05 03:59:09 EST
Created attachment 161089 [details]
proposed fix v1.0 + regression tests

This happens because in Scope#findDirectMemberType(char[], ReferenceBinding) (called from CompilationUnitScope) , we try to find the "enclosingReceiverType" which is returned as null, and so when we check for visibility of Proto via ReferenceBinding#canBeSeenBy , we only check the current package for it. Had we called Scope#findDirectMemberType(char[], ReferenceBinding) via the ClassScope of the extending class, we'd have correctly found the enclosingReceiverType, but in this case we are in a CompilationUnitScope.

We need to consult the types in the CompilationUnitScope, and in case any of them extends the class which contains the protected interface, we need to call ReferenceBinding#canBeSeenBy and check for visibility. This is what the above fix does.
Comment 4 Olivier Thomann CLA 2010-03-05 17:21:09 EST
Slightly modified patch.
Comment 5 Olivier Thomann CLA 2010-03-05 17:21:35 EST
Created attachment 161200 [details]
Proposed fix + regression test
Comment 6 Olivier Thomann CLA 2010-03-05 17:22:29 EST
Ayushman, if you agree, I'll release for M6.
Comment 7 Olivier Thomann CLA 2010-03-05 17:24:46 EST
Created attachment 161201 [details]
Proposed fix + regression test

Same patch with a small change in the ResolveTests suite.
Comment 8 Ayushman Jain CLA 2010-03-06 02:42:28 EST
Yup, looks good.
Comment 9 Olivier Thomann CLA 2010-03-08 11:09:48 EST
Created attachment 161314 [details]
Proposed fix + regression test

Minor change in the for loop.
Comment 10 Olivier Thomann CLA 2010-03-08 11:10:37 EST
Released for 3.6M6.
Regression test added in:
org.eclipse.jdt.core.tests.model.ResolveTests#testInterfaceX
Comment 11 Ayushman Jain CLA 2010-03-09 02:29:02 EST
Just curious... I was wondering what's the motivation behind taking a separate local variable to hold types.length?
Comment 12 Srikanth Sankaran CLA 2010-03-09 03:08:58 EST
(In reply to comment #11)
> Just curious... I was wondering what's the motivation behind taking a separate
> local variable to hold types.length?

To hoist the loop invariant code to outside the loop.
Comment 13 Olivier Thomann CLA 2010-03-09 09:19:38 EST
(In reply to comment #12)
> (In reply to comment #11)
> > Just curious... I was wondering what's the motivation behind taking a separate
> > local variable to hold types.length?
> To hoist the loop invariant code to outside the loop.
It is a coding style I am using a lot. When the size of the array/collection doesn't change during the iteration, I prefer to extract it right away to prevent the size to be retrieved at each iteration.
Initializers are run only once, but the increment is run for each iteration.
Just a matter of taste.
Comment 14 Olivier Thomann CLA 2010-03-09 15:51:25 EST
Verified for 3.6M6 using I20100309-0809
Comment 15 Jay Arthanareeswaran CLA 2017-09-06 10:04:11 EDT
Part of the change made via this bug has been reverted via bug 520874. An alternate fix has been provided, which is explained in bug 520874, comment #5.