/*******************************************************************************
  * Copyright (c) 2000, 2004 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials 
+ * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Common Public License v1.0
  * which accompanies this distribution, and is available at
  * http://www.eclipse.org/legal/cpl-v10.html
- * 
+ *
  * Contributors:
  *     IBM Corporation - initial API and implementation
  *******************************************************************************/
 
 
 /**
- * A buffered document scanner. The buffer always contains a section 
+ * A buffered document scanner. The buffer always contains a section
  * of a fixed size of the document to be scanned.
  */
 
        /** The offset of the scanner within the buffer. */
        private int fOffset;
 
-       
+
        /**
         * Creates a new buffered document scanner.
         * The buffer size is set to the given number of characters.
-        * 
+        *
         * @param size the buffer size
         */
        public BufferedDocumentScanner(int size) {
        private final void updateBuffer(int offset) {
 
                fBufferOffset= offset;
-               
+
                if (fBufferOffset + fBuffer.length > fRangeOffset + fRangeLength)
                        fBufferLength= fRangeLength - (fBufferOffset - fRangeOffset);
                else
 
                try {
                        final String content= fDocument.get(fBufferOffset, fBufferLength);
-                       content.getChars(0, fBufferLength, fBuffer, 0);
+                       if (content!=null) {
+                         content.getChars(0, fBufferLength, fBuffer, 0);
+                       }
                } catch (BadLocationException e) {
                }
        }
                return fBuffer[fOffset++];
         } catch (ArrayIndexOutOfBoundsException e) {
           System.out.println("Offset:"+fOffset);
-          System.out.println("Buffer:"+fBuffer);
+          System.out.println("Buffer:"+fBuffer.toString());
           throw e;
         }
        }
                                updateBuffer(fBufferOffset - fBuffer.length);
                                fOffset= fBuffer.length - 1;
                        }
-               } else {                        
+               } else {
                        --fOffset;
                }
        }