Bug 45259 Bug in DocumentAdapter2.validateLineDelimiters
Version: 3.0.0 Build id: 200310150800 When I try to replace part of text in IBuffer and if this text contains new line delimiter, for example under Linux I open file with \r\n and convert it in \n, I see two exceptions, first about new line delimiter and second as result of bug. Look in inner loop, you have loop by 'k', but access to character using 'i'. Can you please fix this and allow plugins to replace parts of text with new delimiters without additional exceptions in log? for (int i= 0; i < lines; i++) { try { String curr= tracker.getLineDelimiter(i); if (curr != null && !fLegalLineDelimiters.contains(curr)) { StringBuffer buf= new StringBuffer("New line delimiter added to new code: "); //$NON-NLS-1$ for (int k= 0; k < curr.length(); k++) { buf.append(String.valueOf((int) curr.charAt(i))); } JavaPlugin.log(new Exception(buf.toString())); } } catch (BadLocationException e) { JavaPlugin.log(e); } } java.lang.Exception: New line delimiter added to new code: 10 at org.eclipse.jdt.internal.ui.javaeditor.filebuffers.DocumentAdapter2.validateLineDelimiters(DocumentAdapter2.java:430) at org.eclipse.jdt.internal.ui.javaeditor.filebuffers.DocumentAdapter2.setContents(DocumentAdapter2.java:383) at com.swtdesigner.gef.DesignerEditor.handleActivate(DesignerEditor.java:259) at com.swtdesigner.editors.MultiPageEditor.showDesignEditor(MultiPageEditor.java:82) at com.swtdesigner.editors.MultiPageEditor$1.widgetSelected(MultiPageEditor.java:30) at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:89) at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:82) at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:847) at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:871) at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:856) at org.eclipse.swt.widgets.Widget.notifyListeners(Widget.java:664) at org.eclipse.swt.custom.CTabFolder.setSelection(CTabFolder.java:1739) at org.eclipse.swt.custom.CTabFolder.onMouseDown(CTabFolder.java:1927) at org.eclipse.swt.custom.CTabFolder.access$4(CTabFolder.java:1919) at org.eclipse.swt.custom.CTabFolder$1.handleEvent(CTabFolder.java:201) at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:82) at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:847) at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:2173) at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:1863) at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2361) at org.eclipse.ui.internal.Workbench.run(Workbench.java:2344) at org.eclipse.core.internal.boot.InternalBootLoader.run(InternalBootLoader.java:858) at org.eclipse.core.boot.BootLoader.run(BootLoader.java:461) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:324) at org.eclipse.core.launcher.Main.basicRun(Main.java:299) at org.eclipse.core.launcher.Main.run(Main.java:765) at org.eclipse.core.launcher.Main.main(Main.java:599) java.lang.StringIndexOutOfBoundsException: String index out of range: 1 at java.lang.String.charAt(String.java:444) at org.eclipse.jdt.internal.ui.javaeditor.filebuffers.DocumentAdapter2.validateLineDelimiters(DocumentAdapter2.java:428) at org.eclipse.jdt.internal.ui.javaeditor.filebuffers.DocumentAdapter2.setContents(DocumentAdapter2.java:383) at com.swtdesigner.gef.DesignerEditor.handleActivate(DesignerEditor.java:259) at com.swtdesigner.editors.MultiPageEditor.showDesignEditor(MultiPageEditor.java:82) at com.swtdesigner.editors.MultiPageEditor$1.widgetSelected(MultiPageEditor.java:30) at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:89) at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:82) at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:847) at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:871) at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:856) at org.eclipse.swt.widgets.Widget.notifyListeners(Widget.java:664) at org.eclipse.swt.custom.CTabFolder.setSelection(CTabFolder.java:1739) at org.eclipse.swt.custom.CTabFolder.onMouseDown(CTabFolder.java:1927) at org.eclipse.swt.custom.CTabFolder.access$4(CTabFolder.java:1919) at org.eclipse.swt.custom.CTabFolder$1.handleEvent(CTabFolder.java:201) at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:82) at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:847) at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:2173) at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:1863) at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2361) at org.eclipse.ui.internal.Workbench.run(Workbench.java:2344) at org.eclipse.core.internal.boot.InternalBootLoader.run(InternalBootLoader.java:858) at org.eclipse.core.boot.BootLoader.run(BootLoader.java:461) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:324) at org.eclipse.core.launcher.Main.basicRun(Main.java:299) at org.eclipse.core.launcher.Main.run(Main.java:765) at org.eclipse.core.launcher.Main.main(Main.java:599)
org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/javaeditor/filebuffers/DocumentAdapter2.java
* @see IBuffer#append(String) 
	 */
	public void append(String text) {
		if (DEBUG_LINE_DELIMITERS) {
			validateLineDelimiters(text);
		}
		fReplaceCmd.replace(fDocument.getLength(), 0, text);
	}
	
	/*
	 * @see IBuffer#close()
	 */
	public void close() {
		
		if (isClosed())
			return;
			
		IDocument d= fDocument;
		fDocument= null;
		d.removePrenotifiedDocumentListener(this);
		
		if (fTextFileBuffer != null) {
			ITextFileBufferManager manager= FileBuffers.getTextFileBufferManager();
			try {
				manager.disconnect(fTextFileBuffer.getLocation(), new NullProgressMonitor());
			} catch (CoreException x) {
				
			}
			fTextFileBuffer= null;
		}