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
if (codeAssist == null)
			codeAssist= fCurrentViewInput.getAncestor(IJavaElement.CLASS_FILE);
		if (codeAssist instanceof ICodeAssist) {
			IJavaElement[] elements= null;
			try {
				ISourceRange range= ((ISourceReference)fCurrentViewInput).getSourceRange();
				elements= ((ICodeAssist)codeAssist).codeSelect(range.getOffset() + getOffsetInUnclippedDocument(textSelection), textSelection.getLength());
			} catch (JavaModelException e) {
				return StructuredSelection.EMPTY;
			}
			if (elements != null && elements.length > 0) {
				return new StructuredSelection(elements[0]);
			} else
				return StructuredSelection.EMPTY;
		}
		return StructuredSelection.EMPTY;
	}
	/**
	 * Computes and returns the offset in the unclipped document
	 * based on the given text selection from the clipped
	 * document.
	 * 
	 * @param textSelection
	 * @return the offest in the unclipped document or <code>-1</code> if the offset cannot be computed
	 */
	private int getOffsetInUnclippedDocument(ITextSelection textSelection) {
		IDocument unclippedDocument= null;
		try {
			unclippedDocument= new Document(((ISourceReference)fCurrentViewInput).getSource());
		} catch (JavaModelException e) {