Bug 39779

Summary: End position of IType exceeds the size of CompilationUnit
Product: [Eclipse Project] JDT Reporter: Srimanth <sgunturi>
Component: CoreAssignee: David Audel <david_audel>
Status: VERIFIED FIXED QA Contact:
Severity: major    
Priority: P3 CC: gmendel
Version: 2.1   
Target Milestone: 3.0 M2   
Hardware: All   
OS: Windows 2000   
Whiteboard:

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.