Bug 39779 - End position of IType exceeds the size of CompilationUnit
Summary: End position of IType exceeds the size of CompilationUnit
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 2.1   Edit
Hardware: All Windows 2000
: P3 major (vote)
Target Milestone: 3.0 M2   Edit
Assignee: David Audel CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2003-07-08 17:50 EDT by Srimanth CLA
Modified: 2003-07-16 04:13 EDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Srimanth CLA 2003-07-08 17:50:39 EDT
A "String index out of range" exception is thrown, when calling getSource() on
specific IType's. These IType's are ones which do not have a '\r\n' at their end
i.e., the ICompilationUnit ends exactly where the IType ends, AND which have
been modified specifically using a working copy. The end result is that the end
of the IType is greater than the length of the CompilationUnit, hence resulting
in an exception being thrown.

Recreate procedure:
Create a new Java class using the wizard, and using the Java editor remove the
'\r\n' at the end of the file. Save the file and close it. Using any convenient
approach, run the following code on the saved CompilationUnit.

==============================================================

  ICompilation cu = getMyNewlyCreatedCU();
  ICompilationUnit wcu = (ICompilationUnit) cu.getWorkingCopy();
  String source = wcu.getSource();
  wcu.getBuffer().replace(source.length(), 0, "//Hello");
  wcu.commit(true, null);
  wcu.destroy();
  System.out.println("-------CU Source---------");
  System.out.println(cu.getSource());
  System.out.println("-------Type(0) Source---------");
  System.out.println(cu.getTypes()[0].getSource());  // << Exception thrown here
  System.out.println("----------------");

==============================================================

The getSource() call on the IType throws an exception because the end of the
IType exceeds the size of file by one character.
Comment 1 David Audel CLA 2003-07-09 07:59:04 EDT
Scanner does not compute correctly the end of comment when eof is reached.

Fixed.
Comment 2 David Audel CLA 2003-07-16 04:13:26 EDT
Verified.