216
217 // Variables declaration - do not modify
218 private JLabel heading;
219 private JPasswordField passText;220 private JTextField userText;
221
222 @Override
217 // Variables declaration - do not modify
218 private JLabel heading;
219 private JPasswordField passText;
220 private JTextField userText;221
222 @Override
223 public void actionPerformed(ActionEvent e) {
215
216
217 // Variables declaration - do not modify
218 private JLabel heading;219 private JPasswordField passText;
220 private JTextField userText;
221
This private field is never initialized before use. This may cause improper behavior at runtime, or even a NullPointerException
.
Check if the logic that uses the field is correct; add an initializer to the declaration or initialize the field at an appropriate point before use.
If a field is not explicitly initialized, Java will set the value of the field to a default value at runtime. This default value depends on the type:
0
(or the floating point equivalent)Object
, the default value is null
.Java does not check if a field is properly initialized in the way it checks local variables, and this can easily prevent one from immediately noticing that something is wrong.
// Never initialized, never assigned a value.
private String internalField;
String someMethod() {
someInternalCode(internalField); // `internalField` will be null!
}
Assign a valid default to the field, or initialize it wherever sensible.
private String internalField = "defaultValue";
// ...
This issue will not be reported for fields marked as being injected (marked with annotations such as @Inject
or @Autowired
).