8210739: Calling JSpinner's setFont with null throws NullPointerException

Reviewed-by: psadhukhan
This commit is contained in:
Sergey Bylokhov 2018-10-16 15:47:53 -07:00
parent 0ed2c6c295
commit 518f32791a
4 changed files with 107 additions and 9 deletions

View file

@ -769,7 +769,7 @@ public class JSpinner extends JComponent implements Accessible
// the text field font was not set by the user
Font font = spinner.getFont();
if (!newfont.equals(font)) {
getTextField().setFont(new FontUIResource(font));
getTextField().setFont(font == null ? null : new FontUIResource(font));
}
}
}

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2000, 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
@ -216,7 +216,8 @@ public class BasicSpinnerUI extends SpinnerUI
JTextField tf = ((JSpinner.DefaultEditor) editor).getTextField();
if (tf != null) {
if (tf.getFont() instanceof UIResource) {
tf.setFont(new FontUIResource(spinner.getFont()));
Font font = spinner.getFont();
tf.setFont(font == null ? null : new FontUIResource(font));
}
}
}
@ -999,7 +1000,8 @@ public class BasicSpinnerUI extends SpinnerUI
((JSpinner.DefaultEditor)newEditor).getTextField();
if (tf != null) {
if (tf.getFont() instanceof UIResource) {
tf.setFont(new FontUIResource(spinner.getFont()));
Font font = spinner.getFont();
tf.setFont(font == null ? null : new FontUIResource(font));
}
tf.addFocusListener(nextButtonHandler);
tf.addFocusListener(previousButtonHandler);
@ -1017,7 +1019,8 @@ public class BasicSpinnerUI extends SpinnerUI
((JSpinner.DefaultEditor)editor).getTextField();
if (tf != null) {
if (tf.getFont() instanceof UIResource) {
tf.setFont(new FontUIResource(spinner.getFont()));
Font font = spinner.getFont();
tf.setFont(font == null ? null : new FontUIResource(font));
}
}
}