intellij-community
intellij-community copied to clipboard
[bug] check empty before trimming the string to avoid NPE
This is a straightforward change. Before this change, we have to return the empty String explicitly in TextComponentAccessor::getText().
private static class MyTextComponentAccessor implements TextComponentAccessor<JComboBox> {
@Override
public String getText(JComboBox comboBox) {
Object selectedItem = comboBox.getModel().getSelectedItem();
if (selectedItem != null) {
return selectedItem.toString();
}
return "";
}
}
After this change, we could write it as below:
private static class MyTextComponentAccessor implements TextComponentAccessor<JComboBox> {
@Override
public String getText(JComboBox comboBox) {
Object selectedItem = comboBox.getModel().getSelectedItem();
return selectedItem;
}
}
And the original code in platform/platform-api/src/com/intellij/openapi/ui/BrowseFolderRunnable.java did has flaws when trimming the text.