English 中文(简体)
一种可分性的行为,从可接受的Child()方法来看,导致客户代码无效
原标题:JTable strange behavior from getAccessibleChild() method resulting in null pointer in client code

I ve encountered a strange behavior from JTable (JDK 1.5_22):
After a selection change in the table and under some unknown particular circumstances, the JTable will call the cell renderer with null for the value parameter.
This will eventually lead to a nice Null Pointer Exception on a custom renderer code that is not ready for such a rude call.

这里是有罪的方法(JTable.java, 第5319条):

public Accessible getAccessibleChild(int i) {
            if (i < 0 || i >= getAccessibleChildrenCount()) {
                return null;
            } else {
                // children increase across, and then down, for tables
                // (arbitrary decision)
                int column = getAccessibleColumnAtIndex(i);
                int row = getAccessibleRowAtIndex(i);

                TableColumn aColumn = getColumnModel().getColumn(column);
                TableCellRenderer renderer = aColumn.getCellRenderer();
                if (renderer == null) {
                    Class<?> columnClass = getColumnClass(column);
                    renderer = getDefaultRenderer(columnClass);
                }
                Component component = renderer.getTableCellRendererComponent(
                                  JTable.this, null, false, false,
                                  row, column);
                return new AccessibleJTableCell(JTable.this, row, column,
                      getAccessibleIndexAt(row, column));
            }
        }

这里的重点是错误陈述:

Component component = renderer.getTableCellRendererComponent(
                                  JTable.this, null, false, false,
                                  row, column);

引诱“JTable have AccessibleChild 5334”是令人感兴趣的: 我不单靠自己面对这一特点。 但没有答案。

大部分精心设计的问题在于 官方太阳论坛

是否有人知道这一点?

最佳回答

这不是一个同步问题,也不是自动解决。 <代码>JTable 明确打上getTableCellRendererComponent,其价值无效。

归还的价值从未使用过,因此,表面上看上去像旧的gg缩法。 然而,我怀疑,在进入囚室之前,没有打断预期的<条码>。

此前曾要求过Sun,他们的答复是,APIC没有保证<条码> 值/代码>为非年价,因此,<条码>可衡量的CellRendererComponent在被叫作无效时,不得轻视。

问题回答




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签