Skip to main content

JRE 6u12 b3 - isValid() being called on JPanel Construction

3 replies [Last post]
csanfeb
Offline
Joined: 2008-10-17

The following code works in previous JREs but fails in 6u12 b3. Does anyone know why the null pointer occurs? I realize that this example is trivial but in general, is it unsafe to override the isValid method on Component as of JRE 6u12? Just wondering if anyone knew anything about this. It seems wrong that the isValid method would be getting called before construction is complete...

Regards.

Ben

import javax.swing.JPanel;

public class TestJPanel extends JPanel{

String validationString;

public TestJPanel() {
method1();
}

public void method1() {
validationString = "defaultValue";
}

@Override
public boolean isValid() {
System.out.println("isValid");
return !validationString.isEmpty();
}

public static void main(String[] args) {
TestJPanel tjp = new TestJPanel();

System.exit(0);

}
}

Message was edited by: csanfeb

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
trembovetski
Offline
Joined: 2003-12-31

This is a regression from this fix:
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4811096
introduced in b01.

Whether or not it's a bug is not clear, but I filed one for tracking just in case (will appear on bug parade tomorrow):
6793340: Regression: Component.isValid() is called during component initialization

Dmitri

csanfeb
Offline
Joined: 2008-10-17

Thanks Dmitri.

Sun claims this isn't a defect after all:
http://bugs.sun.com/view_bug.do?bug_id=6793340

Does anyone know - is it possible to find the source code for 12b3? I know I can download the JRE here: http://download.java.net/jdk6/6u12/promoted/latest/

but I haven't been able to find the source code link. I'm just curious to see what has changed in the Component class. In build 11, it seems that this problem was known to exist:
[i]From Component in 6u11[/i]
[i]public void revalidate() {
if (getParent() == null) {
// Note: We don't bother invalidating here as once added
// to a valid parent invalidate will be invoked (addImpl
// invokes addNotify which will invoke invalidate on the
// new Component). Also, if we do add a check to isValid
// here it can potentially be called before the constructor
// which was causing some people grief.
return;
}

...// some more code[/i]

but apparently the bug fix for 4811096 couldn't be done without undoing this. I'm just curious to look at the source and read the comments...

Ben

trembovetski
Offline
Joined: 2003-12-31

Isn't source for java.awt.* in the JDK's src.zip? You can get the JDK from the same page as the JRE.

Dmitri