Bug 73579 Source view: StringOutOfBounds error after changing encoding
I got the following error after doing these steps: 1) create a new java class in the default package called dddd.java, open it 1b) open a second file in an editor 1c) switch back to dddd.java (i.e. make it the active editor) 2) change the encoding for that file to "UTF-16 (little-endian)" from the Edit > Encoding menu 3) click on the other file in the package explorer to cause the editor to activate 4) click back on dddd.java in the explorer and ... the follow exception is printed to the console java.lang.StringIndexOutOfBoundsException at java.lang.String.charAt(String.java:385) at org.eclipse.jdt.internal.ui.infoviews.SourceView.computeInput(Unknown Source) at org.eclipse.jdt.internal.ui.infoviews.AbstractInfoView$2.run(Unknown Source)
org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/infoviews/SourceView.java
}
		String[] sourceLines= Strings.convertIntoLines(source);
		String firstLine= sourceLines[0];
		if (!Character.isWhitespace(firstLine.charAt(0)))
			sourceLines[0]= ""; 
		Strings.trimIndentation(sourceLines, CodeFormatterUtil.getTabWidth());
		if (!Character.isWhitespace(firstLine.charAt(0)))
			sourceLines[0]= firstLine;
		source= Strings.concatenate(sourceLines, delim);
		IDocument doc= new Document(source);
		JavaPlugin.getDefault().getJavaTextTools().setupJavaDocumentPartitioner(doc);
		return doc;
	}
	/*
	 * @see AbstractInfoView#setInput(Object)
	 */
	protected void setInput(Object input) {
		fViewer.setInput(input);
	}
	/**
	 * Removes the leading comments from the given source.
	 * 
	 * @param source the string with the source
	 * @return the source without leading comments
	 */
	private String removeLeadingComments(String source) {
		JavaCodeReader reader= new JavaCodeReader();
		IDocument document= new Document(source);
		int i;
		try {