8153532: Add @throws NPE javadoc to UIManager.setLookAndFeel(String) method description
authorpbansal
Mon, 16 Apr 2018 15:22:56 +0530
changeset 49990 6cd19862c742
parent 49989 ecc7b10a1cca
child 49991 033f3118dc67
8153532: Add @throws NPE javadoc to UIManager.setLookAndFeel(String) method description Reviewed-by: prr, serb, kaddepalli
src/java.desktop/share/classes/javax/swing/UIManager.java
test/jdk/javax/swing/UIManager/UIManagerSetLookAndFeelNPETest.java
--- a/src/java.desktop/share/classes/javax/swing/UIManager.java	Mon Apr 16 10:35:22 2018 +0530
+++ b/src/java.desktop/share/classes/javax/swing/UIManager.java	Mon Apr 16 15:22:56 2018 +0530
@@ -606,15 +606,16 @@
      *
      * @param className  a string specifying the name of the class that implements
      *        the look and feel
-     * @exception ClassNotFoundException if the <code>LookAndFeel</code>
+     * @throws ClassNotFoundException if the <code>LookAndFeel</code>
      *           class could not be found
-     * @exception InstantiationException if a new instance of the class
+     * @throws InstantiationException if a new instance of the class
      *          couldn't be created
-     * @exception IllegalAccessException if the class or initializer isn't accessible
-     * @exception UnsupportedLookAndFeelException if
+     * @throws IllegalAccessException if the class or initializer isn't accessible
+     * @throws UnsupportedLookAndFeelException if
      *          <code>lnf.isSupportedLookAndFeel()</code> is false
      * @throws ClassCastException if {@code className} does not identify
      *         a class that extends {@code LookAndFeel}
+     * @throws NullPointerException if {@code className} is {@code null}
      */
     @SuppressWarnings("deprecation")
     public static void setLookAndFeel(String className)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/javax/swing/UIManager/UIManagerSetLookAndFeelNPETest.java	Mon Apr 16 15:22:56 2018 +0530
@@ -0,0 +1,52 @@
+/*
+ * Copyright (c) 2018, 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.
+ */
+
+/*
+ * @test
+ * @bug 8153532
+ * @summary Verifies that SetLookAndFeel(String) throws NPE when className is
+ *           null
+ * @run main UIManagerSetLookAndFeelNPETest
+ */
+
+import javax.swing.UIManager;
+import javax.swing.UnsupportedLookAndFeelException;
+
+public class UIManagerSetLookAndFeelNPETest {
+    public static void main(String[] args)
+            throws ClassNotFoundException, UnsupportedLookAndFeelException,
+            InstantiationException, IllegalAccessException
+    {
+        boolean NPEThrown = false;
+        try {
+            UIManager.setLookAndFeel((String)null);
+        } catch (NullPointerException e) {
+            NPEThrown = true;
+        }
+
+        if (!NPEThrown) {
+            throw new RuntimeException("A NullPointerException is expected " +
+                    "from setLookAndFeel(String), if the className is null");
+        }
+    }
+}