GNOME Bugzilla – Bug 319555
FileChooserBut.setFilename doesn't handle null values
Last modified: 2009-08-15 18:40:50 UTC
FileChooserButton.setFilename(null) causes the JVM to crash.
Created attachment 53804 [details] [review] A patch to prevent the JVM crash This patch will replace a null fileName with the empty string.
The current behaviour is definitely not acceptable, but I am not sure if the proposed behaviour is the right way to go. How about the possibility of throwing an exception?
At first I was thinking of throwing a runtime exception, but then I took a look at Entry.setText() as a reference and I noticed that it was changing the input parameter. Therefore, I did the same assuming that it will be the right thing. I agree that modifying the input parameters can be tricky, in this case changing from null to the empty string can be understood but in other cases it may not be as trivial. Personally I will prefer the API to be consistent. Either all methods validate their input and throw a runtime exception (possibly the same) or have them modify the input value in order to correct it, as it is done by Entry.setText(). I am open to all suggestions as long we can prevent the JVM from crashing and that the errors can be trapped or prevented by java code.
Unfortunately, the bindings are not very consistent. I am of the opinion that setter methods should throw an IllegalArgumentException if they are passed null in cases where null is not an acceptable value. In the case of Entry#setText, the documentation does not mention if null values are acceptable, but I wonder if people are relying on that behaviour already...
Do you mind then updating the code of FileChooserButton#setFilename with a runtime exception or should I resubmit another patch?
I can do it. Also the correct way to do this is to have the check in FileChooserHelper so that the various FileChooser implementations can benefit from the check. I first wanted to know if the RuntimeException was satisfactory to you, however.
The runtime exception works for me and modifying FileChooserHelper is a great idea.
Thanks for reporting this. Fixed all FileChooser implementations (FileChooserDialog, FileChooserButton, FileChooserWidget) in CVS HEAD.