From 082a40f9870803a0e7df759d196e840d7a93b593 Mon Sep 17 00:00:00 2001 From: Victor Rubezhny Date: Fri, 16 Jun 2023 03:06:40 +0200 Subject: [PATCH] [GenericEditor] An NPE occurs in IndentFoldingStrategy.reconcile #228 Fixes: #228 Signed-off-by: Victor Rubezhny --- .../folding/IndentFoldingStrategy.java | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/org.eclipse.ui.genericeditor/src/org/eclipse/ui/internal/genericeditor/folding/IndentFoldingStrategy.java b/org.eclipse.ui.genericeditor/src/org/eclipse/ui/internal/genericeditor/folding/IndentFoldingStrategy.java index af9e55613b6..8f85f1e6bfe 100644 --- a/org.eclipse.ui.genericeditor/src/org/eclipse/ui/internal/genericeditor/folding/IndentFoldingStrategy.java +++ b/org.eclipse.ui.genericeditor/src/org/eclipse/ui/internal/genericeditor/folding/IndentFoldingStrategy.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009, 2018 IBM Corporation and others. + * Copyright (c) 2009, 2023 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -223,6 +223,11 @@ public void reconcile(DirtyRegion dirtyRegion, IRegion subRegion) { int tabSize = 1; int minimumRangeSize = 1; try { + var thisDocument = document; + if (thisDocument == null) { + // Exit as soon as possible if uninstalled + return; + } // Today we recompute annotation from the whole document each // time. @@ -231,7 +236,7 @@ public void reconcile(DirtyRegion dirtyRegion, IRegion subRegion) { // int offset = dirtyRegion.getOffset(); // int length = dirtyRegion.getLength(); // int startLine = 0; //document.getLineOfOffset(offset); - int endLine = document.getNumberOfLines() - 1; // startLine + + int endLine = thisDocument.getNumberOfLines() - 1; // startLine + // document.getNumberOfLines(offset, // length) - 1; @@ -242,11 +247,11 @@ public void reconcile(DirtyRegion dirtyRegion, IRegion subRegion) { int lineEmptyCount = 0; Integer lastLineForKeyword = null; int line = endLine; - for (line = endLine; line >= 0; line--) { - int lineOffset = document.getLineOffset(line); - String delim = document.getLineDelimiter(line); - int lineLength = document.getLineLength(line) - (delim != null ? delim.length() : 0); - String lineContent = document.get(lineOffset, lineLength); + for (line = endLine; line >= 0 && this.document != null; line--) { + int lineOffset = thisDocument.getLineOffset(line); + String delim = thisDocument.getLineDelimiter(line); + int lineLength = thisDocument.getLineLength(line) - (delim != null ? delim.length() : 0); + String lineContent = thisDocument.get(lineOffset, lineLength); LineState state = getLineState(lineContent, lastLineForKeyword); switch (state) {