Bug 288698

Summary: Cannot create type hierarchy for abstract types when they have inline descendants and *.class* in project name
Product: [Eclipse Project] JDT Reporter: Ivan <divacnd>
Component: CoreAssignee: Olivier Thomann <Olivier_Thomann>
Status: VERIFIED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: markus.kell.r, Olivier_Thomann, stephan.herrmann, vijay.rajonline
Version: 3.6   
Target Milestone: 3.6 M2   
Hardware: PC   
OS: Windows XP   
Whiteboard:
Attachments:
Description Flags
example project
none
error log
none
proposed patch with test
john.arthorne: iplog+
example project with a simple speed test none

Description Ivan CLA 2009-09-05 13:04:29 EDT
User-Agent:       Opera/9.80 (Windows NT 5.1; U; ru) Presto/2.2.15 Version/10.00
Build Identifier: M20090211-1700

Can’t create type hierarchy for abstract types when they have inline descendants and *.class* in project name.

Reproducible: Always

Steps to Reproduce:
1.Create project with name containing the following pattern *.class* (e.g.  bug.class_test)
2.Create simple abstract class;
3.Create class that extends abstract class
4.Try to see type  hierarchy for abstract class  -- everything should work fine
5.Create simple class with any method where you create an inline instance of abstract class;
6.Save it. Now you are not able to see hierarchy for abstract class. See error log




As we can't create type hierarchy, java code analysis functionality may not work correctly

found in 3.4.2 but exists in 3.5 too
Comment 1 Ivan CLA 2009-09-05 13:09:41 EDT
Created attachment 146555 [details]
example project

example plugin with buggy classes
Comment 2 Ivan CLA 2009-09-05 13:12:34 EDT
Created attachment 146556 [details]
error log
Comment 3 Stephan Herrmann CLA 2009-09-05 17:56:04 EDT
Oops (looking at IndexBasedHierarchyBuilder.searchAllPossibleSubTypes()):

int suffix = documentPath.toLowerCase().lastIndexOf(SUFFIX_STRING_class);

if this matches in the middle of a string, I wouldn't call it a suffix ;-)
further down substring(lastSlash+1, suffix) tries to create a substring
with negative length since suffix is smaller than lastSlash.

how about:

if (documentPath.toLowerCase().endsWith(SUFFIX_STRING_class)) {
    int suffix = documentPath.length()-SUFFIX_STRING_class.lenght();

?
Comment 4 Ivan CLA 2009-09-06 04:10:44 EDT
looks good :) . Should work :)
Comment 5 Stephan Herrmann CLA 2009-09-06 11:31:56 EDT
Created attachment 146576 [details]
proposed patch with test

Here you go!
Now we only need a committer to accept the patch.

2 notes:
 - I changed the example to use a source folder with ".class" in its name, 
   rather than a project. Fits easier into existing test infrastructure.
 - I made a search for other occurrences of String.lastIndexOf(String),
   but none looked suspecious to me. However, many places use this
   method with a one char String. Would it matter for performance to
   change it to using lastIndexOf(char)??
Comment 6 Ivan CLA 2009-09-06 13:02:32 EDT
about perfomance: an idea came to me

  int suffix = documentPath.length() - SUFFIX_STRING_class.length();
  if (documentPath.substring(suffix).toLowerCase().equals(SUFFIX_STRING_class)) {
 will work more quickly, especially with long pathes
Comment 7 Stephan Herrmann CLA 2009-09-06 14:14:08 EDT
(In reply to comment #6)
> about perfomance: an idea came to me
> 
>   int suffix = documentPath.length() - SUFFIX_STRING_class.length();
>   if (documentPath.substring(suffix).toLowerCase().equals(SUFFIX_STRING_class))
> {
>  will work more quickly, especially with long pathes

Why do you think so?
endsWith looks pretty efficient, plus it avoids to create another
string as substring does.
Comment 8 Ivan CLA 2009-09-07 01:20:22 EDT
Created attachment 146585 [details]
example project with a simple speed test

a simple speed test look at SpeedTest.java
Comment 9 Olivier Thomann CLA 2009-09-07 20:28:23 EDT
Let's review this.
Thanks Stephan!
Comment 10 Olivier Thomann CLA 2009-09-09 12:04:21 EDT
Patch looks good.
Thanks for the patch.
Released for 3.6M2.
Regression test added in:
org.eclipse.jdt.core.tests.model.TypeHierarchyTests#testBug288698
Comment 11 Kent Johnson CLA 2009-09-15 11:48:42 EDT
Verified for 3.6M2
Comment 12 Olivier Thomann CLA 2009-11-16 09:51:02 EST
*** Bug 295206 has been marked as a duplicate of this bug. ***