Skip to content

Commit 8e76fb8

Browse files
author
Federico Fissore
committed
An empty string could still be returned when a non empty string is required. Related to #3381
1 parent a49f1b2 commit 8e76fb8

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

arduino-core/src/processing/app/PreferencesData.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,11 @@ static public String get(String attribute, String defaultValue) {
146146
return (value == null) ? defaultValue : value;
147147
}
148148

149+
static public String getNonEmpty(String attribute, String defaultValue) {
150+
String value = get(attribute, defaultValue);
151+
return ("".equals(value)) ? defaultValue : value;
152+
}
153+
149154
public static boolean has(String key) {
150155
return prefs.containsKey(key);
151156
}

arduino-core/src/processing/app/Serial.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,27 +50,27 @@ public class Serial implements SerialPortEventListener {
5050
public Serial() throws SerialException {
5151
this(PreferencesData.get("serial.port"),
5252
PreferencesData.getInteger("serial.debug_rate", 9600),
53-
PreferencesData.get("serial.parity", "N").charAt(0),
53+
PreferencesData.getNonEmpty("serial.parity", "N").charAt(0),
5454
PreferencesData.getInteger("serial.databits", 8),
5555
PreferencesData.getFloat("serial.stopbits", 1));
5656
}
5757

5858
public Serial(int irate) throws SerialException {
5959
this(PreferencesData.get("serial.port"), irate,
60-
PreferencesData.get("serial.parity", "N").charAt(0),
60+
PreferencesData.getNonEmpty("serial.parity", "N").charAt(0),
6161
PreferencesData.getInteger("serial.databits", 8),
6262
PreferencesData.getFloat("serial.stopbits", 1));
6363
}
6464

6565
public Serial(String iname, int irate) throws SerialException {
66-
this(iname, irate, PreferencesData.get("serial.parity", "N").charAt(0),
66+
this(iname, irate, PreferencesData.getNonEmpty("serial.parity", "N").charAt(0),
6767
PreferencesData.getInteger("serial.databits", 8),
6868
PreferencesData.getFloat("serial.stopbits", 1));
6969
}
7070

7171
public Serial(String iname) throws SerialException {
7272
this(iname, PreferencesData.getInteger("serial.debug_rate", 9600),
73-
PreferencesData.get("serial.parity", "N").charAt(0),
73+
PreferencesData.getNonEmpty("serial.parity", "N").charAt(0),
7474
PreferencesData.getInteger("serial.databits", 8),
7575
PreferencesData.getFloat("serial.stopbits", 1));
7676
}

0 commit comments

Comments
 (0)