Skip to content

Commit

Permalink
fix NPEs in UI code during commit validation tests.
Browse files Browse the repository at this point in the history
example:
 java.lang.NullPointerException: Cannot invoke
   "java.awt.Component.getBackground()" because the return value of
   "javax.swing.JViewport.getView()" is null
  • Loading branch information
mbien committed Jul 2, 2022
1 parent 5d1dd0f commit 95f0e57
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import javax.swing.JPanel;
import javax.swing.LayoutStyle;
import javax.swing.SwingConstants;
import javax.swing.UIManager;
import org.netbeans.api.project.FileOwnerQuery;
import org.netbeans.api.project.Project;
import org.netbeans.modules.css.lib.api.CssParserResult;
Expand All @@ -54,7 +55,6 @@
import org.netbeans.modules.web.inspect.PageInspectorImpl;
import org.netbeans.modules.web.inspect.PageModel;
import org.netbeans.spi.project.ActionProvider;
import org.openide.explorer.view.BeanTreeView;
import org.openide.filesystems.FileObject;
import org.openide.loaders.DataObject;
import org.openide.loaders.DataObjectNotFoundException;
Expand Down Expand Up @@ -139,7 +139,7 @@ private void initNoStylesLabel() {
noStylesLabel.setHorizontalAlignment(SwingConstants.CENTER);
noStylesLabel.setVerticalAlignment(SwingConstants.CENTER);
noStylesLabel.setEnabled(false);
noStylesLabel.setBackground(new BeanTreeView().getViewport().getView().getBackground());
noStylesLabel.setBackground(UIManager.getColor("Tree.background"));
noStylesLabel.setOpaque(true);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ private void initNoDOMLabel() {
noDomLabel.setHorizontalAlignment(SwingConstants.CENTER);
noDomLabel.setVerticalAlignment(SwingConstants.CENTER);
noDomLabel.setEnabled(false);
noDomLabel.setBackground(treeView.getViewport().getView().getBackground());
noDomLabel.setBackground(UIManager.getColor("Tree.background"));
noDomLabel.setOpaque(true);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
<Container class="javax.swing.JPanel" name="findPanel">
<Properties>
<Property name="background" type="java.awt.Color" editor="org.netbeans.modules.form.RADConnectionPropertyEditor">
<Connection code="treeView.getViewport().getView().getBackground()" type="code"/>
<Connection code="UIManager.getColor(&quot;Tree.background&quot;)" type="code"/>
</Property>
</Properties>

Expand Down Expand Up @@ -124,7 +124,7 @@
<Component class="javax.swing.JLabel" name="messageLabel">
<Properties>
<Property name="background" type="java.awt.Color" editor="org.netbeans.modules.form.RADConnectionPropertyEditor">
<Connection code="treeView.getViewport().getView().getBackground()" type="code"/>
<Connection code="UIManager.getColor(&quot;Tree.background&quot;)" type="code"/>
</Property>
<Property name="horizontalAlignment" type="int" value="0"/>
<Property name="enabled" type="boolean" value="false"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JComponent;
import javax.swing.UIManager;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
Expand Down Expand Up @@ -326,7 +327,7 @@ private void initComponents() {
refreshButton = new javax.swing.JButton();
messageLabel = new javax.swing.JLabel();

findPanel.setBackground(treeView.getViewport().getView().getBackground());
findPanel.setBackground(UIManager.getColor("Tree.background"));

org.openide.awt.Mnemonics.setLocalizedText(findButton, org.openide.util.NbBundle.getMessage(UnusedBindingsPanel.class, "UnusedBindingsPanel.findButton.text")); // NOI18N
findButton.addActionListener(new java.awt.event.ActionListener() {
Expand Down Expand Up @@ -386,7 +387,7 @@ public void actionPerformed(java.awt.event.ActionEvent evt) {

dataPanel.add(refreshPanel, java.awt.BorderLayout.PAGE_END);

messageLabel.setBackground(treeView.getViewport().getView().getBackground());
messageLabel.setBackground(UIManager.getColor("Tree.background"));
messageLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
messageLabel.setEnabled(false);
messageLabel.setOpaque(true);
Expand Down

0 comments on commit 95f0e57

Please sign in to comment.