7001118: DOC: javax.swing.border.StrokeBorder.paintBorder() doesn't throw NPE in all specified cases
authormalenkov
Mon, 31 Jan 2011 21:31:39 +0300
changeset 8141 cdf18fc88266
parent 8140 f38be08fdcb4
child 8142 df12f485c6bd
7001118: DOC: javax.swing.border.StrokeBorder.paintBorder() doesn't throw NPE in all specified cases Reviewed-by: alexp
jdk/src/share/classes/javax/swing/border/StrokeBorder.java
--- a/jdk/src/share/classes/javax/swing/border/StrokeBorder.java	Mon Jan 31 21:22:42 2011 +0300
+++ b/jdk/src/share/classes/javax/swing/border/StrokeBorder.java	Mon Jan 31 21:31:39 2011 +0300
@@ -88,6 +88,10 @@
     /**
      * Paints the border for the specified component
      * with the specified position and size.
+     * If the border was not specified with a {@link Paint} object,
+     * the component's foreground color will be used to render the border.
+     * If the component's foreground color is not available,
+     * the default color of the {@link Graphics} object will be used.
      *
      * @param c       the component for which this border is being painted
      * @param g       the paint graphics
@@ -96,7 +100,7 @@
      * @param width   the width of the painted border
      * @param height  the height of the painted border
      *
-     * @throws NullPointerException if the specified {@code c} or {@code g} are {@code null}
+     * @throws NullPointerException if the specified {@code g} is {@code null}
      */
     @Override
     public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
@@ -106,7 +110,7 @@
             if (g instanceof Graphics2D) {
                 Graphics2D g2d = (Graphics2D) g;
                 g2d.setStroke(this.stroke);
-                g2d.setPaint(this.paint != null ? this.paint : c.getForeground());
+                g2d.setPaint(this.paint != null ? this.paint : c == null ? null : c.getForeground());
                 g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                                      RenderingHints.VALUE_ANTIALIAS_ON);
                 g2d.draw(new Rectangle2D.Float(x + size / 2, y + size / 2, width - size, height - size));