From f2e2bac89b4e48754bf6458119c8de79a4aa65ab Mon Sep 17 00:00:00 2001 From: Manukumar V S Date: Tue, 8 Mar 2022 15:34:42 +0530 Subject: [PATCH 1/5] 8282548: Create a regression test for JDK-4330998 --- .../4330998/JEditorPaneSetTextNullTest.java | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 test/jdk/javax/swing/JEditorPane/4330998/JEditorPaneSetTextNullTest.java diff --git a/test/jdk/javax/swing/JEditorPane/4330998/JEditorPaneSetTextNullTest.java b/test/jdk/javax/swing/JEditorPane/4330998/JEditorPaneSetTextNullTest.java new file mode 100644 index 0000000000000..f3a287ada1c0c --- /dev/null +++ b/test/jdk/javax/swing/JEditorPane/4330998/JEditorPaneSetTextNullTest.java @@ -0,0 +1,55 @@ + /* + * Copyright (c) 2013, 2022, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + + import javax.swing.JEditorPane; + import javax.swing.JPanel; + import javax.swing.SwingUtilities; + + /* + * @test + * @bug 4330998 + * @summary Verifies that JEditorPane.setText(null) doesn't throw NullPointerException. + * @run main JEditorPaneSetTextNullTest + */ + public class JEditorPaneSetTextNullTest { + private static JEditorPane editorPane; + + public static void main(String[] s) throws Exception { + SwingUtilities.invokeAndWait(() -> createUI()); + + try { + SwingUtilities.invokeAndWait(() -> editorPane.setText(null)); + System.out.println("Test passed"); + } catch (Exception e) { + throw new RuntimeException("Test failed, caught Exception " + e + + " when calling JEditorPane.setText(null)"); + } + } + + private static void createUI() { + JPanel panel = new JPanel(); + editorPane = new JEditorPane(); + panel.add(editorPane); + } + + } From 990b6720115405d430d687f7c7a615aa7e944b5c Mon Sep 17 00:00:00 2001 From: Manukumar V S Date: Wed, 16 Mar 2022 22:06:01 +0530 Subject: [PATCH 2/5] Review comments fixed: Simplified the test, removed unwanted method --- .../4330998/JEditorPaneSetTextNullTest.java | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/test/jdk/javax/swing/JEditorPane/4330998/JEditorPaneSetTextNullTest.java b/test/jdk/javax/swing/JEditorPane/4330998/JEditorPaneSetTextNullTest.java index f3a287ada1c0c..beb53a8904386 100644 --- a/test/jdk/javax/swing/JEditorPane/4330998/JEditorPaneSetTextNullTest.java +++ b/test/jdk/javax/swing/JEditorPane/4330998/JEditorPaneSetTextNullTest.java @@ -22,7 +22,6 @@ */ import javax.swing.JEditorPane; - import javax.swing.JPanel; import javax.swing.SwingUtilities; /* @@ -32,13 +31,10 @@ * @run main JEditorPaneSetTextNullTest */ public class JEditorPaneSetTextNullTest { - private static JEditorPane editorPane; - + public static void main(String[] s) throws Exception { - SwingUtilities.invokeAndWait(() -> createUI()); - try { - SwingUtilities.invokeAndWait(() -> editorPane.setText(null)); + SwingUtilities.invokeAndWait(() -> new JEditorPane().setText(null)); System.out.println("Test passed"); } catch (Exception e) { throw new RuntimeException("Test failed, caught Exception " + e @@ -46,10 +42,4 @@ public static void main(String[] s) throws Exception { } } - private static void createUI() { - JPanel panel = new JPanel(); - editorPane = new JEditorPane(); - panel.add(editorPane); - } - } From 9291aa4e5022b75cfa82f4103b6870b543912dee Mon Sep 17 00:00:00 2001 From: Manukumar V S Date: Wed, 16 Mar 2022 22:13:46 +0530 Subject: [PATCH 3/5] Fixed jcheck whitespace error --- .../swing/JEditorPane/4330998/JEditorPaneSetTextNullTest.java | 1 - 1 file changed, 1 deletion(-) diff --git a/test/jdk/javax/swing/JEditorPane/4330998/JEditorPaneSetTextNullTest.java b/test/jdk/javax/swing/JEditorPane/4330998/JEditorPaneSetTextNullTest.java index beb53a8904386..15fb75f355d85 100644 --- a/test/jdk/javax/swing/JEditorPane/4330998/JEditorPaneSetTextNullTest.java +++ b/test/jdk/javax/swing/JEditorPane/4330998/JEditorPaneSetTextNullTest.java @@ -31,7 +31,6 @@ * @run main JEditorPaneSetTextNullTest */ public class JEditorPaneSetTextNullTest { - public static void main(String[] s) throws Exception { try { SwingUtilities.invokeAndWait(() -> new JEditorPane().setText(null)); From 03d7475a31c1b6dc171bfc5b2a617d1b158aaedf Mon Sep 17 00:00:00 2001 From: Manukumar V S Date: Wed, 16 Mar 2022 22:29:18 +0530 Subject: [PATCH 4/5] Renamed mains() parameter to args --- .../swing/JEditorPane/4330998/JEditorPaneSetTextNullTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/jdk/javax/swing/JEditorPane/4330998/JEditorPaneSetTextNullTest.java b/test/jdk/javax/swing/JEditorPane/4330998/JEditorPaneSetTextNullTest.java index 15fb75f355d85..8bf6a35479b4d 100644 --- a/test/jdk/javax/swing/JEditorPane/4330998/JEditorPaneSetTextNullTest.java +++ b/test/jdk/javax/swing/JEditorPane/4330998/JEditorPaneSetTextNullTest.java @@ -31,7 +31,7 @@ * @run main JEditorPaneSetTextNullTest */ public class JEditorPaneSetTextNullTest { - public static void main(String[] s) throws Exception { + public static void main(String[] args) throws Exception { try { SwingUtilities.invokeAndWait(() -> new JEditorPane().setText(null)); System.out.println("Test passed"); From 954e8f0acffa6e56bebc13659bd2c47ca3029604 Mon Sep 17 00:00:00 2001 From: Manukumar V S Date: Thu, 17 Mar 2022 22:06:00 +0530 Subject: [PATCH 5/5] Added a blank line before main() --- .../swing/JEditorPane/4330998/JEditorPaneSetTextNullTest.java | 1 + 1 file changed, 1 insertion(+) diff --git a/test/jdk/javax/swing/JEditorPane/4330998/JEditorPaneSetTextNullTest.java b/test/jdk/javax/swing/JEditorPane/4330998/JEditorPaneSetTextNullTest.java index 8bf6a35479b4d..5b543894ef6c6 100644 --- a/test/jdk/javax/swing/JEditorPane/4330998/JEditorPaneSetTextNullTest.java +++ b/test/jdk/javax/swing/JEditorPane/4330998/JEditorPaneSetTextNullTest.java @@ -31,6 +31,7 @@ * @run main JEditorPaneSetTextNullTest */ public class JEditorPaneSetTextNullTest { + public static void main(String[] args) throws Exception { try { SwingUtilities.invokeAndWait(() -> new JEditorPane().setText(null));