Skip to content

Commit

Permalink
Fix IllegalArgumentException for File properties which allow null value
Browse files Browse the repository at this point in the history
  • Loading branch information
Mingun committed Sep 17, 2018
1 parent 3f38f81 commit 33d461f
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/core/org/apache/jmeter/testbeans/gui/FieldStringEditor.java
Expand Up @@ -27,7 +27,7 @@


/**
* This class implements a property editor for non-null String properties that
* This class implements a property editor for possible null String properties that
* supports custom editing (i.e.: provides a GUI component) based on a text
* field.
* <p>
Expand All @@ -47,14 +47,15 @@ class FieldStringEditor extends PropertyEditorSupport implements ActionListener,
* Value on which we started the editing. Used to avoid firing
* PropertyChanged events when there's not been such change.
*/
private String initialValue = "";
private String initialValue;

protected FieldStringEditor() {
super();

textField = new JTextField();
textField.addActionListener(this);
textField.addFocusListener(this);
initialValue = textField.getText();
}

@Override
Expand All @@ -75,10 +76,11 @@ public Object getValue() {

@Override
public void setValue(Object value) {
if (value instanceof String) {
// null value always fail instanceof check therefore we process it separately
if (value == null || value instanceof String) {
setAsText((String) value);
} else {
throw new IllegalArgumentException();
throw new IllegalArgumentException("Expected String but got "+value.getClass()+", value="+value);
}
}

Expand All @@ -99,7 +101,9 @@ public Component getCustomEditor() {
public void firePropertyChange() {
String newValue = getAsText();

if (initialValue.equals(newValue)) {
if (initialValue != null && initialValue.equals(newValue)
|| initialValue == null && newValue == null
) {
return;
}
initialValue = newValue;
Expand Down

0 comments on commit 33d461f

Please sign in to comment.