From c6d8778bfaa7f0914641d1dc53b2883fff10af1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Caol=C3=A1n=20McNamara?= Date: Sun, 7 Apr 2024 14:54:52 +0100 Subject: [PATCH] cid#1596251 Dereference null return value MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit and cid#1596249 Dereference null return value Change-Id: I2d50e8be5ec20001527c20ccd46a9a0336792d8e Reviewed-on: https://gerrit.libreoffice.org/c/core/+/165871 Tested-by: Jenkins Reviewed-by: Caolán McNamara --- .../provider/beanshell/ScriptEditorForBeanShell.java | 11 ++++++++--- .../provider/beanshell/ScriptSourceModel.java | 5 +++-- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/scripting/java/com/sun/star/script/framework/provider/beanshell/ScriptEditorForBeanShell.java b/scripting/java/com/sun/star/script/framework/provider/beanshell/ScriptEditorForBeanShell.java index 0ab265ecc799..5abb761ba954 100644 --- a/scripting/java/com/sun/star/script/framework/provider/beanshell/ScriptEditorForBeanShell.java +++ b/scripting/java/com/sun/star/script/framework/provider/beanshell/ScriptEditorForBeanShell.java @@ -342,11 +342,16 @@ public class ScriptEditorForBeanShell extends ScriptEditorBase implements Action String s = view.getText(); fos = scriptURL.openConnection().getOutputStream(); - if (fos != null) { + if (fos != null && s != null) { fos.write(s.getBytes()); } else { - showErrorMessage( - "Error saving script: Could not open stream for file"); + if (fos == null) { + showErrorMessage( + "Error saving script: Could not open stream for file"); + } else { + showErrorMessage( + "Error saving script: Could not get script text"); + } result = false; } diff --git a/scripting/java/com/sun/star/script/framework/provider/beanshell/ScriptSourceModel.java b/scripting/java/com/sun/star/script/framework/provider/beanshell/ScriptSourceModel.java index 165f00844d70..ff94d16d8ca0 100644 --- a/scripting/java/com/sun/star/script/framework/provider/beanshell/ScriptSourceModel.java +++ b/scripting/java/com/sun/star/script/framework/provider/beanshell/ScriptSourceModel.java @@ -109,7 +109,8 @@ public class ScriptSourceModel { Object result; if (view.isModified()) { - result = interpreter.eval(view.getText()); + String s = view.getText(); + result = interpreter.eval(s != null ? s : ""); } else { result = interpreter.eval(getText()); } @@ -122,4 +123,4 @@ public class ScriptSourceModel { currentPosition = lineNum - 1; view.update(); } -} \ No newline at end of file +}