diff --git a/recaf-core/src/main/java/software/coley/recaf/services/source/AstRangeMapper.java b/recaf-core/src/main/java/software/coley/recaf/services/source/AstRangeMapper.java index 76c397d04..372c83573 100644 --- a/recaf-core/src/main/java/software/coley/recaf/services/source/AstRangeMapper.java +++ b/recaf-core/src/main/java/software/coley/recaf/services/source/AstRangeMapper.java @@ -12,6 +12,7 @@ import org.openrewrite.java.tree.Space; import org.openrewrite.marker.Marker; import org.openrewrite.marker.Range; +import software.coley.collections.Unchecked; import software.coley.recaf.analytics.logging.DebuggingLogger; import software.coley.recaf.analytics.logging.Logging; import software.coley.recaf.util.StringDiff; @@ -62,7 +63,7 @@ public static SortedMap computeRangeToTreeMapping(@Nonnull Tree tre } return cmp; }); - DiffHelper helper = backingText == null ? null : new DiffHelper(backingText, tree); + DiffHelper helper = backingText == null ? null : Unchecked.getOr(() -> new DiffHelper(backingText, tree), null); PositionPrintOutputCapture ppoc = new PositionPrintOutputCapture(helper); JavaPrinter printer = new JavaPrinter<>() { final JavaPrinter spacePrinter = new JavaPrinter<>(); @@ -80,7 +81,10 @@ public J visit(@Nullable Tree tree, @Nonnull PrintOutputCapturesuper.visit(tree, outputCapture), null); + if (t == null) { + return null; + } Range.Position endPosition = new Range.Position(ppoc.posInBacking, ppoc.line, ppoc.column); Range range = new Range(randomId(), startPosition, endPosition); rangeMap.put(range, t);