diff --git a/arduino-core/src/processing/app/PreferencesData.java b/arduino-core/src/processing/app/PreferencesData.java index 41f3cf6c0..a273221a3 100644 --- a/arduino-core/src/processing/app/PreferencesData.java +++ b/arduino-core/src/processing/app/PreferencesData.java @@ -146,6 +146,11 @@ public class PreferencesData { return (value == null) ? defaultValue : value; } + static public String getNonEmpty(String attribute, String defaultValue) { + String value = get(attribute, defaultValue); + return ("".equals(value)) ? defaultValue : value; + } + public static boolean has(String key) { return prefs.containsKey(key); } diff --git a/arduino-core/src/processing/app/Serial.java b/arduino-core/src/processing/app/Serial.java index f3988f867..c411d2594 100644 --- a/arduino-core/src/processing/app/Serial.java +++ b/arduino-core/src/processing/app/Serial.java @@ -50,27 +50,27 @@ public class Serial implements SerialPortEventListener { public Serial() throws SerialException { this(PreferencesData.get("serial.port"), PreferencesData.getInteger("serial.debug_rate", 9600), - PreferencesData.get("serial.parity", "N").charAt(0), + PreferencesData.getNonEmpty("serial.parity", "N").charAt(0), PreferencesData.getInteger("serial.databits", 8), PreferencesData.getFloat("serial.stopbits", 1)); } public Serial(int irate) throws SerialException { this(PreferencesData.get("serial.port"), irate, - PreferencesData.get("serial.parity", "N").charAt(0), + PreferencesData.getNonEmpty("serial.parity", "N").charAt(0), PreferencesData.getInteger("serial.databits", 8), PreferencesData.getFloat("serial.stopbits", 1)); } public Serial(String iname, int irate) throws SerialException { - this(iname, irate, PreferencesData.get("serial.parity", "N").charAt(0), + this(iname, irate, PreferencesData.getNonEmpty("serial.parity", "N").charAt(0), PreferencesData.getInteger("serial.databits", 8), PreferencesData.getFloat("serial.stopbits", 1)); } public Serial(String iname) throws SerialException { this(iname, PreferencesData.getInteger("serial.debug_rate", 9600), - PreferencesData.get("serial.parity", "N").charAt(0), + PreferencesData.getNonEmpty("serial.parity", "N").charAt(0), PreferencesData.getInteger("serial.databits", 8), PreferencesData.getFloat("serial.stopbits", 1)); }