Skip to content

Commit

Permalink
[GenericEditor] An NPE occurs in IndentFoldingStrategy.reconcile ecli…
Browse files Browse the repository at this point in the history
…pse-platform#228

Fixes: eclipse-platform#228

Signed-off-by: Victor Rubezhny <vrubezhny@redhat.com>
  • Loading branch information
vrubezhny authored and mickaelistria committed Jun 17, 2023
1 parent f2065bd commit 082a40f
Showing 1 changed file with 12 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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.
Expand All @@ -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;

Expand All @@ -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) {
Expand Down

0 comments on commit 082a40f

Please sign in to comment.