Bug 36032 - [plan] JavaProject.findType() fails to find second type in source file
Summary: [plan] JavaProject.findType() fails to find second type in source file
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 2.0.2   Edit
Hardware: PC Windows 2000
: P3 normal with 3 votes (vote)
Target Milestone: 3.2 M4   Edit
Assignee: Frederic Fusier CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 22883 32505 37897 38088 39191 45830 51029 51943 53597 55907 58418 72179 81744 86613 87063 95396 96400 98505 103139 105183 108088 115639 130926 (view as bug list)
Depends on:
Blocks: 108030 118789
  Show dependency tree
 
Reported: 2003-04-03 13:22 EST by Sam Robb CLA
Modified: 2019-09-30 15:13 EDT (History)
32 users (show)

See Also:


Attachments
Patch to fix this issue (4.49 KB, patch)
2005-08-04 07:59 EDT, Frederic Fusier CLA
no flags Details | Diff
Test cases added to ClassNameTests (9.33 KB, patch)
2005-08-04 08:02 EDT, Frederic Fusier CLA
no flags Details | Diff
Regression tests updated (9.46 KB, patch)
2005-08-04 10:21 EDT, Olivier Thomann CLA
no flags Details | Diff
Tests to verify that there's no impact on performances (20.93 KB, patch)
2005-08-05 11:29 EDT, Frederic Fusier CLA
no flags Details | Diff
Patch to (definitely) fix this issue (93.21 KB, patch)
2005-11-25 11:08 EST, Frederic Fusier CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Sam Robb CLA 2003-04-03 13:22:07 EST
Given a file with two classes, the findType() method is apparently unable to
locate the secondary type in a source file.  For example: given the following,
findType() will be able to find Foo, but not Bar.

// Foo.java
public class Foo {
}
class Bar {
}
Comment 1 Philipe Mulet CLA 2003-04-04 02:22:42 EST
This utility is defined in UI land
Comment 2 Philipe Mulet CLA 2003-04-04 02:23:24 EST
Ignore my previous comment (wrong PR)
Comment 3 Philipe Mulet CLA 2003-04-11 04:39:26 EDT
We always said that we shouldn't find secondary types in Java model, but it 
would be interesting to support in the end. Mostly since it is inconsistent 
with the builder result (you get errors in editor but nothing in the task list).

Comment 4 Philipe Mulet CLA 2003-04-11 04:40:29 EDT
This searchable environment limitation has a few duplicate PRs, need to find 
them (under Later).
Comment 5 Philipe Mulet CLA 2003-04-15 10:05:03 EDT
See SearchableEnvironment#findTypes(char[] prefix, final ISearchRequestor 
storage)
Comment 6 Philipe Mulet CLA 2003-05-21 05:26:16 EDT
*** Bug 37897 has been marked as a duplicate of this bug. ***
Comment 7 Philipe Mulet CLA 2003-05-27 05:00:05 EDT
*** Bug 38088 has been marked as a duplicate of this bug. ***
Comment 8 Philipe Mulet CLA 2003-06-23 05:30:23 EDT
*** Bug 39191 has been marked as a duplicate of this bug. ***
Comment 9 Philipe Mulet CLA 2003-10-31 15:40:13 EST
*** Bug 45830 has been marked as a duplicate of this bug. ***
Comment 10 Jerome Lanneluc CLA 2004-02-04 07:26:45 EST
*** Bug 51029 has been marked as a duplicate of this bug. ***
Comment 11 Philipe Mulet CLA 2004-02-13 07:48:21 EST
*** Bug 51943 has been marked as a duplicate of this bug. ***
Comment 12 Jerome Lanneluc CLA 2004-03-04 05:56:01 EST
*** Bug 53597 has been marked as a duplicate of this bug. ***
Comment 13 Philipe Mulet CLA 2004-03-24 12:13:14 EST
*** Bug 55907 has been marked as a duplicate of this bug. ***
Comment 14 Philipe Mulet CLA 2004-03-25 06:40:58 EST
Will reconsider post 3.0
Comment 15 Philipe Mulet CLA 2004-05-10 05:11:52 EDT
*** Bug 58418 has been marked as a duplicate of this bug. ***
Comment 16 Steven Wasleski CLA 2004-08-06 10:27:26 EDT
Philippe, by post 3.0 could you mean 3.0.1 or 3.1?  This sounds like it could 
be an invasive change that would not be appropriate for 3.0.1, but it has been 
a while since I last rooted around deep in the Java Model so maybe I am wrong 
on this.  I was wondering because there is a good bit of interest in this bug.
Comment 17 Mike Wilson CLA 2004-08-10 10:17:40 EDT
Kent indicates that this can not happen for R3.0.1. Should be considered (at least) for 
R3.1
Comment 18 Kent Johnson CLA 2004-08-18 13:13:15 EDT
*** Bug 72179 has been marked as a duplicate of this bug. ***
Comment 19 Jan Schäfer CLA 2005-02-22 09:57:56 EST
Bug is still in 3.1 M4, will it be fixed in 3.1? 
Comment 20 Kent Johnson CLA 2005-02-25 14:14:11 EST
*** Bug 86613 has been marked as a duplicate of this bug. ***
Comment 21 Philipe Mulet CLA 2005-05-17 06:05:31 EDT
*** Bug 95396 has been marked as a duplicate of this bug. ***
Comment 22 Philipe Mulet CLA 2005-05-24 04:37:14 EDT
*** Bug 96400 has been marked as a duplicate of this bug. ***
Comment 23 Philipe Mulet CLA 2005-07-11 05:51:35 EDT
*** Bug 103139 has been marked as a duplicate of this bug. ***
Comment 24 Kent Johnson CLA 2005-07-27 10:58:54 EDT
*** Bug 105183 has been marked as a duplicate of this bug. ***
Comment 25 Frederic Fusier CLA 2005-08-04 07:59:44 EDT
Created attachment 25662 [details]
Patch to fix this issue

This patch is based on HEAD stream (ie. 3.2 dvpt code).
It just activates sleeping code as secondary type indexing seems to have been
implemented
Comment 26 Frederic Fusier CLA 2005-08-04 08:02:03 EDT
Created attachment 25663 [details]
Test cases added to ClassNameTests

I've also modified test356 in ASTConverterTest and ASTConverterAST3Test which
use secondary type.
Comment 27 Olivier Thomann CLA 2005-08-04 10:21:47 EDT
Created attachment 25676 [details]
Regression tests updated
Comment 28 Frederic Fusier CLA 2005-08-04 10:41:34 EDT
Philippe, perhaps a good candidate for 3.1.1?
Comment 29 Frederic Fusier CLA 2005-08-05 11:29:35 EDT
Created attachment 25752 [details]
Tests to verify that there's no impact on performances

Unfortunately, these tests show that previous patch strongly impact findType
performances when searched type is unknown.

Here are result without patch:
Scenario 'FullSourceWorkspaceModelTests#testProjectFindType':
	- CPU Time: n=10, s=1090, av=109.0, dev=7.0
	- Elapsed process: n=10, s=1182, av=118.0, dev=5.422176684690384
------------------------------------------------------------------------
Scenario 'FullSourceWorkspaceModelTests#testProjectFindUnknownType':
	- CPU Time: n=10, s=1440, av=144.0, dev=12.806248474865697
	- Elapsed process: n=10, s=4048, av=404.0, dev=46.04128582044598
------------------------------------------------------------------------
Scenario 'FullSourceWorkspaceModelTests#testPerfSeekPackageFragments':
	- CPU Time: n=10, s=660, av=66.0, dev=11.135528725660043
	- Elapsed process: n=10, s=759, av=75.0, dev=3.0166206257996713

and here are those with patch:
Scenario 'FullSourceWorkspaceModelTests#testProjectFindType':
	- CPU Time: n=10, s=1030, av=103.0, dev=11.0
	- Elapsed process: n=10, s=1173, av=117.0, dev=4.347413023856832
------------------------------------------------------------------------
Scenario 'FullSourceWorkspaceModelTests#testProjectFindUnknownType':
	- CPU Time: n=10, s=1970, av=197.0, dev=25.317977802344327
	- Elapsed process: n=10, s=5394, av=539.0, dev=87.23302127061747
------------------------------------------------------------------------
Scenario 'FullSourceWorkspaceModelTests#testPerfSeekPackageFragments':
	- CPU Time: n=10, s=720, av=72.0, dev=7.483314773547883
	- Elapsed process: n=10, s=823, av=82.0, dev=4.207136793592526

I've run this test only once, but result while trying to find an unknown type
in project is too bad: 33% time increase for Elapsed process time (average goes
from 404s to 539s!).

So, it seems we have to find another better solution to fix this issue...
Comment 30 Frederic Fusier CLA 2005-08-26 08:51:01 EDT
*** Bug 108088 has been marked as a duplicate of this bug. ***
Comment 31 Jerome Lanneluc CLA 2005-09-29 09:30:30 EDT
*** Bug 22883 has been marked as a duplicate of this bug. ***
Comment 32 Frederic Fusier CLA 2005-11-09 11:56:19 EST
*** Bug 115639 has been marked as a duplicate of this bug. ***
Comment 33 Adam Kiezun CLA 2005-11-10 17:07:41 EST
Is performance in the case of searching for _unknown_ type really such an issue?
My (wild) guess is that people (or compiler) typically search for types that
_are_ there.
Comment 34 Philipe Mulet CLA 2005-11-11 03:45:55 EST
To clarify. The change being debated here only affects the compiler behavior
when performing against the source model, which occurs in operations like
reconcile, search, type hierarchies, codeassist, codeselect etc... all but build. 
The fix is located in the pluggable environment passed to the compiler, which
wrappers the JavaModel.

Adam - each new type is looked in many places before being found. We have to
ping in all places designated by the imports, and this for any new type.
Frederic identified a perf degradation of 2% which is too much by our standards.
Always the quest for the ultimate solution...
Comment 35 Frederic Fusier CLA 2005-11-25 11:08:00 EST
Created attachment 30620 [details]
Patch to (definitely) fix this issue

This is a specific eclipse patch which includes 3 projects:
 - org.eclipse.jdt.core
 - org.eclipse.jdt.core.tests.model
 - org.eclipse.jdt.core.tests.performance

This patch should be...no, IS the bug killer... All performance tests are good with it (e.g. either equals or sometimes better than with HEAD contents).

Reconcile operation is no longer downsized by this test and same as for completion tests.

Solution was to use a cache on JavaModelManager per project information. Secondary types are searched the first time using a specific BasicSearchEngine request and corresponding IType stored in the cache. Then, after the consumed time is only to look in maps to retrieve the key.

Cache size is currently not considered as a potential problem due to the fact that secondary types number should not be too big. Cache is reset each time a secondary type entry is added to the index and type is removed from cache each time its file is deleted.
Comment 36 Frederic Fusier CLA 2005-11-25 11:46:08 EST
Patch released in HEAD (commented code removed).
Comment 37 Jerome Lanneluc CLA 2005-12-13 09:32:25 EST
Verified for 3.2 M4 using build I20051213-0010
Comment 38 Olivier Thomann CLA 2006-03-14 11:02:53 EST
*** Bug 130926 has been marked as a duplicate of this bug. ***
Comment 39 Frederic Fusier CLA 2006-03-27 10:07:26 EST
*** Bug 87063 has been marked as a duplicate of this bug. ***
Comment 40 Frederic Fusier CLA 2006-03-27 10:08:30 EST
*** Bug 98505 has been marked as a duplicate of this bug. ***
Comment 41 Jerome Lanneluc CLA 2006-03-28 08:55:07 EST
*** Bug 81744 has been marked as a duplicate of this bug. ***
Comment 42 Frederic Fusier CLA 2007-04-02 07:18:38 EDT
*** Bug 32505 has been marked as a duplicate of this bug. ***
Comment 43 Trevin Beattie CLA 2008-01-03 18:30:00 EST
I'm seeing the same problem in Eclipse SDK 3.3.1.1 (JDT 3.3.1.r331_v20070629-7o7jE72EDlXAbqAcnbmyg1rf8RIL).  Curiously, it seems to only affect one particular non-public class; I have lots of other non-public classes in the same (default) package for which there are no complaints.  In what version is this bug fix supposed to be released?
Comment 44 Frederic Fusier CLA 2008-01-05 07:33:37 EST
(In reply to comment #43)
> I'm seeing the same problem in Eclipse SDK 3.3.1.1 (JDT
> 3.3.1.r331_v20070629-7o7jE72EDlXAbqAcnbmyg1rf8RIL).  Curiously, it seems to
> only affect one particular non-public class; I have lots of other non-public
> classes in the same (default) package for which there are no complaints.  In
> what version is this bug fix supposed to be released?
> 
3.2, so it should not longer occur. Please open a new bug with a small test case to reproduce your issue, thanks
Comment 45 Philippe Lhoste CLA 2012-10-19 07:31:32 EDT
Actually, I still see this bug in Eclipse Juno. Version after version of Eclipse, I hope to see it fixed, but it is still there.
It seems difficult to make a small project reproducing the problem, as it might appear only in a large project: the behavior appears mostly after having started a fresh Eclipse on such project, and going for the first time to these classes.
I will try and describe it (as it appears in our code base) as precisely as I can in the hope to give a hint about this issue.

As I wrote, we have a rather large code base (around one million of lines of code).
In the cases where we see the bug, we have a public abstract base class, and several package protected small classes extending the base class.
We don't want to put each class in its own file, as it is convenient to have them grouped logically in the same file, and, well, Java allows it, the Eclipse compiler understands it, so why the editor cannot take it in account?

What we see: we open a class using such small package protected class, the used type is highlighted as unknown ("XxxXxx cannot be resolved to a type").
The quick fixes include: "Import 'XxxXxx' (package.where.we.are)"...
When we hit F3 on the class, it doesn't move.
I can open the class marked as missing with Ctrl+Shift+T (Open Type).
Back to the other class, it is still seen as unknown. I have to check out the file and edit it (just a new line is enough) to get the editor to kick in and finally remove the error mark...

I made a small project (trivial, as described above, I can join it if needed) trying to reproduce the conditions of the bug.
I closed the tab of the classes and restarted Juno. No problems.
I closed the project and restarted Juno. No problems.
I cleaned, then closed the project, and restarted Juno after marking the classes as read-only (like Perforce does when a file is versioned and not checked out). No problems either.
So trivial cases are correctly handled, the problem seems to appear only in complex projects, perhaps

We have this problem in at least two cases: in one, the abstract class is package protected, in the other it is public. In one, the package protected classes are final, in the other they are not.

Note that I would be happy with just an interactive solution, allowing to recognize the missing class without having to edit the file where it is used...
Comment 46 Markus Keller CLA 2012-10-19 11:56:48 EDT
Note that this fix was revised with bug 118789. To sum up: If you need secondary types, you have to use one of the JavaProject#findType(*, IProgressMonitor) methods.

(In reply to comment #45)
I'm not sure that's really this bug. Did you debug it and see that findType() returned a wrong result? Your description does sound like a bug, but I'm afraid we can't do much without steps to reproduce.
Comment 47 Philippe Lhoste CLA 2012-10-19 14:24:00 EDT
(In reply to comment #46)
> (In reply to comment #45)
> I'm not sure that's really this bug. Did you debug it and see that
> findType() returned a wrong result? Your description does sound like a bug,
> but I'm afraid we can't do much without steps to reproduce.

Honestly, I am not sure either. I went straight there from bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=38088 (top result of my search) which is marked as duplicate of this one. As are many other bugs, apparently...
I thought I should mention it here instead of in a sub-branch.

But I have no idea of what is JavaProject.findType(), I am just a user of the IDE, not a hacker of Eclipse.

Alas, I am aware that this bug is hard to reproduce, and thus even harder to fix. I just wanted to provide some additional information from our case.

For what it is worth (not much), my attempt to reproduce the bug is at http://bazaar.launchpad.net/~philho/+junk/Java/files/head:/Tests/src/org/philhosoft/tests/bugs/eclipse/package_protected/ but as said, the example is too simple to trigger the issue.
Comment 48 Srikanth Sankaran CLA 2013-12-01 09:00:40 EST
I fixed the inverse problem, that is deleted types still show up in some
circumstances : bug 421902