| Summary: | [search] newNotPresentException on BinaryField.getTypeSignature for inner member fields | ||||||||
|---|---|---|---|---|---|---|---|---|---|
| Product: | [Eclipse Project] JDT | Reporter: | Andrey Loskutov <loskutov> | ||||||
| Component: | Core | Assignee: | JDT-Core-Inbox <jdt-core-inbox> | ||||||
| Status: | CLOSED WONTFIX | QA Contact: | |||||||
| Severity: | normal | ||||||||
| Priority: | P3 | CC: | frederic_fusier | ||||||
| Version: | 3.4 | ||||||||
| Target Milestone: | --- | ||||||||
| Hardware: | PC | ||||||||
| OS: | All | ||||||||
| Whiteboard: | stalebug | ||||||||
| Attachments: |
|
||||||||
It looks like search is returning an invalid Java element (i.e. the parent of the field should be ZipFile$1 instead of ZipFile) Sorry, it took me a long time before commenting this bug, but I was busy on other fronts last year at that time and after, this bug got forgotten in the depth of my inbox... :-(
Saying that, I cannot reproduce using 3.4.0...
I got the following correct match while searching for 'eof' field in the JDK 1.6 library:
Parsing ZipFile$1.class [in java.util.zip [in C:\JDKs\sun\6.0\jre\lib\rt.jar]]
Report matching:
- node set: accurate=1, possible=0
- must resolve: false (locator: false, nodeSet: false)
- fine grain flags=none
Reporting match
Resource: P/b237200
Positions: [offset=8129, length=3]
Java element: eof [in <anonymous> [in ZipFile$1.class [in java.util.zip [in C:\JDKs\sun\6.0\jre\lib\rt.jar]]]]
Accuracy: EXACT_MATCH
Rule: EXACT
Raw: false
If you still encounter this problem, then please provide a complete test case to help me to reproduce, thanks
Created attachment 127779 [details] Sample plugin and data projects Hi, I still see this issue (running with both 3.4.2 and 3.5M5). 1) Please import the attached plugin project "Bug237200" into the workspace 2) launch Eclipse in debuger. 3) In the second Eclipse, please import the attached data project "Bug237200_data" 4) Right click on the ContainsZipFileField.java from Bug237200_data in Package Explorer 5) Run "Search Fields" action 6) It will run the search for all the fields in given java class and then for each field declared in each Java type found by the first search. 7) In the console you will see search status and also error stack traces while trying to resolve type signatures for *some* fields. (In reply to comment #3) > Ok, I got it thanks for the test case. The problem comes from the scope you chose to perform the search: searchScope = createSearchScope(fieldType); When searching for fields declaration of ZipFile, you restrict the search only to the binary type. That means that matches found in local types of this type should not be reported. Currently there's a bug while locating the match which tries to report some of them but with an invalid element type, hence the Java Model Exception you got... Note that I'm thinking about a fix which will remove these invalid matches, but when it will be released, you still miss the fields declaration of the local types due to the restrictive scope you set for your search request... Sorry for offtopic, how I can include type "A" AND it's local/member types (not accessible without the "A" context) to the search? (In reply to comment #5) > Sorry for offtopic, how I can include type "A" AND it's local/member types (not > accessible without the "A" context) to the search? > It's easy for member types: just get them from the IType using getTypes() and add them to the scope. The problem is for local or anonymous types, you can't get them without parsing the source, so I would say there's no real solution for them... But do you really want to get fields declaration of anonymous or local types? Created attachment 127797 [details]
Data Hierarchy Plugin
Ok, let's explain why I've started this:
my goal was to answer a "simple" question by statically inspecting given Java type:
which references to which objects *can* hang around in memory after I create an instance of given type? More specific: if there are static fields in a type, which memory *can* never be released if these fields would be assigned?
This mean: creating a tree of types by searching recursively all the related types referenced by fields of given type. Of course such search will never give a *complete* answer (if you have Collection<?> fields you can have references to any number of types which can't be analysed statically, or if the field has an interface/not the most specific type). But it helps to quick review the code and to understand the "data hierarhy" of a given type.
Please try attached plugin (work in progress) which I've written to better understand where we can have memory leaks in FindBugs :-)
So doing this I guess I have also look into the local/anonymous types. There is a high probability that they can be stored internally to fields and keep some additional references to additional types.
(In reply to comment #7) > Created an attachment (id=127797) [details] > Data Hierarchy Plugin > > Ok, let's explain why I've started this: > > my goal was to answer a "simple" question by statically inspecting given Java > type: > > which references to which objects *can* hang around in memory after I create an > instance of given type? More specific: if there are static fields in a type, > which memory *can* never be released if these fields would be assigned? > >... > So doing this I guess I have also look into the local/anonymous types. There is > a high probability that they can be stored internally to fields and keep some > additional references to additional types. > I would say no, as local or anonymous types cannot declare static fields... This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet. As such, we're closing this bug. If you have further information on the current state of the bug, please add it and reopen this bug. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant. -- The automated Eclipse Genie. |
Build ID: 3.4.0 (RC3) Build id: I20080530-1730, JDK 1.6 Steps To Reproduce: I'm writing code which iterates through all the fields found by java search: SearchPattern searchPattern = SearchPattern.createPattern("*", IJavaSearchConstants.FIELD, IJavaSearchConstants.DECLARATIONS, SearchPattern.R_PATTERN_MATCH); SearchEngine searchEngine = new SearchEngine(); IJavaSearchScope searchScope = SearchEngine.createJavaSearchScope( new IJavaElement[] { myIType }, IJavaSearchScope.SOURCES); in a given IType element and resolving the fields signature by calling IField.getTypeSignature(). If iterating over matches reported for java.util.zip.ZipFile type, I see Java Model Exceptions during the call to BinaryField.getTypeSignature() for each field defined in the inner member classes, like for the "eof" field: Java Model Exception: Java Model Status [eof [in ZipFile [in ZipFile.class [in java.util.zip [in F:\java\jdk1.6.0\jre\lib\rt.jar]]]] does not exist] The "eof" toString representation in debugger is: eof (not open) [in ZipFile [in ZipFile.class [in java.util.zip [in F:\java\jdk1.6.0\jre\lib\rt.jar]]]] Obviously the hierarchy eof field "[eof [in ZipFile" is broken: it should be "[eof [in ZipFile$1 [in ZipFile". I would expect that IField.getTypeSignature() would not throw Java Model Exception for *existing* fields, doesn't matter if they are defined in anonymous classes or not... Stack: Java Model Exception: Java Model Status [eof [in ZipFile [in ZipFile.class [in java.util.zip [in F:\java\jdk1.6.0\jre\lib\rt.jar]]]] does not exist] at org.eclipse.jdt.internal.core.JavaElement.newNotPresentException(JavaElement.java:491) at org.eclipse.jdt.internal.core.JavaElement.openWhenClosed(JavaElement.java:525) at org.eclipse.jdt.internal.core.JavaElement.getElementInfo(JavaElement.java:251) at org.eclipse.jdt.internal.core.JavaElement.getElementInfo(JavaElement.java:237) at org.eclipse.jdt.internal.core.BinaryField.getTypeSignature(BinaryField.java:78) at de.loskutov.bfields.search.FieldReferencesRequestor.isTypeAccepted(FieldReferencesRequestor.java:113) at de.loskutov.bfields.search.FieldReferencesRequestor.acceptSearchMatch(FieldReferencesRequestor.java:99) at org.eclipse.jdt.internal.core.search.matching.MatchLocator.report(MatchLocator.java:1745) at org.eclipse.jdt.internal.core.search.matching.MatchLocator.reportMatching(MatchLocator.java:2345) at org.eclipse.jdt.internal.core.search.matching.MatchLocator.reportMatching(MatchLocator.java:2580) at org.eclipse.jdt.internal.core.search.matching.MemberDeclarationVisitor.visit(MemberDeclarationVisitor.java:259) at org.eclipse.jdt.internal.compiler.ast.TypeDeclaration.traverse(TypeDeclaration.java:1253) at org.eclipse.jdt.internal.compiler.ast.QualifiedAllocationExpression.traverse(QualifiedAllocationExpression.java:478) at org.eclipse.jdt.internal.compiler.ast.ReturnStatement.traverse(ReturnStatement.java:262) at org.eclipse.jdt.internal.compiler.ast.SwitchStatement.traverse(SwitchStatement.java:380) at org.eclipse.jdt.internal.compiler.ast.MethodDeclaration.traverse(MethodDeclaration.java:239) at org.eclipse.jdt.internal.core.search.matching.MatchLocator.reportMatching(MatchLocator.java:2098) at org.eclipse.jdt.internal.core.search.matching.MatchLocator.reportMatching(MatchLocator.java:2593) at org.eclipse.jdt.internal.core.search.matching.MatchLocator.reportMatching(MatchLocator.java:2322) at org.eclipse.jdt.internal.core.search.matching.MatchLocator.process(MatchLocator.java:1614) at org.eclipse.jdt.internal.core.search.matching.MatchLocator.locateMatches(MatchLocator.java:997) at org.eclipse.jdt.internal.core.search.matching.MatchLocator.locateMatches(MatchLocator.java:1081) at org.eclipse.jdt.internal.core.search.matching.MatchLocator.locateMatches(MatchLocator.java:1213) at org.eclipse.jdt.internal.core.search.JavaSearchParticipant.locateMatches(JavaSearchParticipant.java:94) at org.eclipse.jdt.internal.core.search.BasicSearchEngine.findMatches(BasicSearchEngine.java:223) at org.eclipse.jdt.internal.core.search.BasicSearchEngine.search(BasicSearchEngine.java:506) at org.eclipse.jdt.core.search.SearchEngine.search(SearchEngine.java:551)