RFR: 6429812: NPE after calling JTable.updateUI() when using a header renderer + XP L&F [v9]

Alexey Ivanov aivanov at openjdk.java.net
Wed Jun 8 10:26:40 UTC 2022


On Wed, 8 Jun 2022 07:01:08 GMT, Tejesh R <tr at openjdk.org> wrote:

>> _Header_ object not initialized/set when paint() method of `WindowTableHeaderUI` class is executed. The paint() event is executed through explicit call of `JTable.updateUI()` in the regression test. In order to set the _header_ to the _called_ JTable, it is set in the `getTableCellRendererComponent()` method, which in turn makes the _header_ object available during paint event without causing NPE.
>
> Tejesh R has updated the pull request incrementally with one additional commit since the last revision:
> 
>   Updated for multiple LookAndFeel

Changes requested by aivanov (Reviewer).

test/jdk/javax/swing/JTableHeader/TableHeaderRendererTest.java line 52:

> 50:         for (UIManager.LookAndFeelInfo look : lookAndFeel) {
> 51:             // initialize should not throw NullPointerException
> 52:             LnFName = look.getName();

Why not declare it here? It does not need to be a field, moreover you don't need it even as a local variable.

test/jdk/javax/swing/JTableHeader/TableHeaderRendererTest.java line 54:

> 52:             LnFName = look.getName();
> 53:             System.out.println(LnFName+ " LookAndFeel Set");
> 54:             setLookAndFeel(look.getClassName());

Setting L&F should rather be done on EDT as well, so I propose creating a `runTest` method which will encapsulate the logic of the test:


    public static void main(String[] args) throws Exception {
        SwingUtilities.invokeAndWait(TableHeaderRendererTest::runTest);
        System.out.println("Test Passed");
    }

    private static void runTest() {
        UIManager.LookAndFeelInfo[] lookAndFeel = UIManager.getInstalledLookAndFeels();
        for (UIManager.LookAndFeelInfo look : lookAndFeel) {
            System.out.println(look.getName() + " LookAndFeel Set");
            setLookAndFeel(look.getClassName());
            // initialize should not throw NullPointerException
            initialize();
        }
    }

test/jdk/javax/swing/JTableHeader/TableHeaderRendererTest.java line 114:

> 112:         }
> 113:     }
> 114:     private static void setLookAndFeel(String laf) {

Please add a blank line before the new method declaration.

-------------

PR: https://git.openjdk.java.net/jdk/pull/8830



More information about the client-libs-dev mailing list