Bug 18997 - Refactor / Extract Method produces Exception "string index out of range"
Summary: Refactor / Extract Method produces Exception "string index out of range"
Status: RESOLVED WONTFIX
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 2.0   Edit
Hardware: PC Windows 2000
: P3 major (vote)
Target Milestone: ---   Edit
Assignee: JDT-Core-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 19335 (view as bug list)
Depends on:
Blocks:
 
Reported: 2002-06-04 07:25 EDT by Andreas Krüger CLA
Modified: 2009-08-30 02:22 EDT (History)
2 users (show)

See Also:


Attachments
Screenshot after producing the bug. (17.96 KB, image/png)
2002-06-04 07:26 EDT, Andreas Krüger CLA
no flags Details
Relevant part of file .log from .metadata directory. (51.70 KB, text/plain)
2002-06-05 05:03 EDT, Andreas Krüger CLA
no flags Details
Eclipse project that's rather small and reproduces the problem (see comment in file Make.java). (48.31 KB, application/zip)
2002-06-06 06:07 EDT, Andreas Krüger CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Andreas Krüger CLA 2002-06-04 07:25:47 EDT
I'm trying to extract a piece of code into a method.
When the Refactoring Wizard pops up, I enter the method name as usual.

First weirdness:  I hit "next", there is a bit of activity, but then what I see
does not change.  I'm still on the initial wizard screen that asks me to type in
the method name.

If I hit next again, this time nothing happens, not even activity.

When I hit "Finish", I get an exception.  I'll enclose a screen shot.

The problem seems to be reproducable, even after I shut down eclipse and start
it back up again. I'll save the workspace when I'm done with this bug report,
feel free to ask more questions.
Comment 1 Andreas Krüger CLA 2002-06-04 07:26:55 EDT
Created attachment 1212 [details]
Screenshot after producing the bug.
Comment 2 Andreas Krüger CLA 2002-06-04 07:42:20 EDT
Both F1 and F2.  The screenshot above was produced with build 20020602, but the
same bug is reproducable with build 20020521 as well.
Comment 3 DJ Houghton CLA 2002-06-04 18:20:34 EDT
Is there any information in your .log file? (located in the .metadata 
directory for your workspace)

Moving to JDT/Core for comment. (sorry if this should be JDT/UI)
Comment 4 Andreas Krüger CLA 2002-06-05 05:03:26 EDT
Created attachment 1251 [details]
Relevant part of file .log from .metadata directory.
Comment 5 Dirk Baeumer CLA 2002-06-06 05:23:10 EDT
This bug is related to 19335 but could be caused by different code in the 
formatter. That's why I keep them separate. 

The formatter somehow jumbles up the positions. As a result the value of 
positions[1] is -5 which is definitly not inside the formatted code. Added 
guard and fixup code to protect code against this. 

Andreas can you provide example code that caused this exception. It would be 
really helpful to reproduce the problem in the formatter.
Comment 6 Andreas Krüger CLA 2002-06-06 06:07:20 EDT
Created attachment 1286 [details]
Eclipse project that's rather small and reproduces the problem (see comment in file Make.java).
Comment 7 Andreas Krüger CLA 2002-06-06 06:11:37 EDT
Remarks on my attachment:

The file is a .zip - Archive, but when I downloaded it just to make sure, it
arrived here with the name of "showattachment.cgi".  Probably a Bugzilla bug. 
Simply rename to something.zip.

When I tried to come up with a small example, I tried to get rid of the function
call at the start of where the refactoring is.  That made the bug go away.
Comment 8 Dirk Baeumer CLA 2002-06-06 06:49:33 EDT
Andreas, thank you for providing the code. Helped me to verify that this is a 
formatter bug.

The problem is the same as in 19335. The length of the formatted code is 176, 
the mapped positions are [176, 179] which are outside the string. Calling 
formattedCode.substring(179 + 1) result in an index out of bounds exception of 
(-4).

Added fixed up code covers this problem as well
Comment 9 Dirk Baeumer CLA 2002-06-06 08:18:48 EDT
Moving to JDT/Core since it is a formatter bug.
Comment 10 Olivier Thomann CLA 2002-06-06 14:42:19 EDT
It is too risky to fix that now.
Comment 11 Olivier Thomann CLA 2002-06-07 15:31:51 EDT
*** Bug 19335 has been marked as a duplicate of this bug. ***
Comment 12 Philipe Mulet CLA 2002-06-10 09:37:00 EDT
Deferring, too risky, and refactoring is protecting itself.
Comment 13 Denis Roy CLA 2009-08-30 02:22:51 EDT
As of now 'LATER' and 'REMIND' resolutions are no longer supported.
Please reopen this bug if it is still valid for you.