From 26d970154a350eafa285ab63e7997d546207d56f Mon Sep 17 00:00:00 2001 From: Elsa Zacharia Date: Fri, 10 Apr 2026 18:38:07 +0530 Subject: [PATCH] Fix possible NPE in StyledText The content might go null in certain cases so adding a null check as safeguard Fixes: https://github.com/eclipse-platform/eclipse.platform.swt/issues/658 --- .../common/org/eclipse/swt/custom/StyledText.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledText.java b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledText.java index 8fd3e1637d9..9d107a84951 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledText.java +++ b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledText.java @@ -8290,8 +8290,10 @@ public void setBackground(Color color) { customBackground = color != null && !this.insideSetEnableCall && !backgroundDisabled; background = color; super.setBackground(color); - resetCache(0, content.getLineCount()); - setCaretLocations(); + if (content != null) { + resetCache(0, content.getLineCount()); + setCaretLocations(); + } super.redraw(); } /** @@ -8885,8 +8887,10 @@ public void setForeground(Color color) { customForeground = color != null && !this.insideSetEnableCall && !foregroundDisabled; foreground = color; super.setForeground(color); - resetCache(0, content.getLineCount()); - setCaretLocations(); + if (content != null) { + resetCache(0, content.getLineCount()); + setCaretLocations(); + } super.redraw(); } /**