Community
Participate
Working Groups
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.
Scanner does not compute correctly the end of comment when eof is reached. Fixed.
Verified.