Skip to main content

[patch] minor bugs

3 replies [Last post]
Anonymous

One fix to JRadioGroup to deal with nothing being selected,
and one fix to AbstractBinding so I get a better error message (than NullPointerException) when I bind to a field that
does not exist.

Index: swingx/src/java/org/jdesktop/swing/JXRadioGroup.java
===================================================================
RCS file: /cvs/jdnc/swingx/src/java/org/jdesktop/swing/JXRadioGroup.java,v
retrieving revision 1.1
diff -u -r1.1 JXRadioGroup.java
--- swingx/src/java/org/jdesktop/swing/JXRadioGroup.java 28 Jul 2004 21:21:11 -0000 1.1
+++ swingx/src/java/org/jdesktop/swing/JXRadioGroup.java 4 Mar 2005 14:15:46 -0000
@@ -94,6 +94,9 @@

public Object getSelectedValue() {
int index = getSelectedIndex();
+ if (index==-1) {
+ return null;
+ }
return values.get(index);
}

Index: swingx/src/java/org/jdesktop/swing/binding/AbstractBinding.java
===================================================================
RCS file: /cvs/jdnc/swingx/src/java/org/jdesktop/swing/binding/AbstractBinding.java,v
retrieving revision 1.7
diff -u -r1.7 AbstractBinding.java
--- swingx/src/java/org/jdesktop/swing/binding/AbstractBinding.java 28 Feb 2005 21:10:33 -0000 1.7
+++ swingx/src/java/org/jdesktop/swing/binding/AbstractBinding.java 4 Mar 2005 14:15:47 -0000
@@ -380,6 +380,7 @@
this.dataModel = dataModel;
this.fieldName = fieldName;
metaData = dataModel.getMetaData(fieldName);
+ checkNull(metaData, "Field " + fieldName + " does not exist in metadata");
installDataModelListener();
installMetaDataListener();
}

NOTICE: Please note that this email, and the contents thereof,
are subject to the standard Peralex email disclaimer, which may
be found at: http://www.peralex.com/disclaimer.html

If you cannot access the disclaimer through the URL attached
and you wish to receive a copy thereof please send
an email to email@peralex.com

---------------------------------------------------------------------
To unsubscribe, e-mail: jdnc-unsubscribe@jdnc.dev.java.net
For additional commands, e-mail: jdnc-help@jdnc.dev.java.net

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Noel Grandin

>
> As for the second, I need to think about it a little bit more. Are there any situations where a null meta data at this stage is ok? Should checks be added to other places to handle the null pointer?
>
If metadeta is null, the call on the next line to installMetaDataListener() is going to NPE.

NOTICE: Please note that this email, and the contents thereof,
are subject to the standard Peralex email disclaimer, which may
be found at: http://www.peralex.com/disclaimer.html

If you cannot access the disclaimer through the URL attached
and you wish to receive a copy thereof please send
an email to email@peralex.com

---------------------------------------------------------------------
To unsubscribe, e-mail: jdnc-unsubscribe@jdnc.dev.java.net
For additional commands, e-mail: jdnc-help@jdnc.dev.java.net

rbair
Offline
Joined: 2003-07-08

Hey Noel,

The first patch looks great. I will actually expand it a little to do general range checking (make sure the index isn't too big either).

As for the second, I need to think about it a little bit more. Are there any situations where a null meta data at this stage is ok? Should checks be added to other places to handle the null pointer?

Richard

Kleopatra

>
> As for the second, I need to think about it a little bit more.
> Are there any situations where a null meta data at this stage is ok?
> Should checks be added to other places to handle the null pointer?
>

Strictly speaking, null metadata are never ok But they happen where
we are (over-) stretching Binding's contract, f.i. in
DirectTableBinding. In those contexts it's up to the mis-behaving
classes to hack around their self-created problems.

Besides that, are there situations when the metaData "is not yet"
available, like when loading data from somewhere? I remember seeing a
comment somewhere in the incubator - maybe that's outdated?

In an ideal world, DataModel (in its role as MetaDataProvider) should
throw an Exception if clients try to access the metaData of an unknown
field.

Jeanette

---------------------------------------------------------------------
To unsubscribe, e-mail: jdnc-unsubscribe@jdnc.dev.java.net
For additional commands, e-mail: jdnc-help@jdnc.dev.java.net