add exception handling when loading default resource

Daniel Gultsch created

Change summary

src/main/java/eu/siacs/conversations/services/XmppConnectionService.java | 12 
1 file changed, 10 insertions(+), 2 deletions(-)

Detailed changes

src/main/java/eu/siacs/conversations/services/XmppConnectionService.java 🔗

@@ -997,8 +997,16 @@ public class XmppConnectionService extends Service {
 
 	public XmppConnection createConnection(final Account account) {
 		final SharedPreferences sharedPref = getPreferences();
-		account.setResource(sharedPref.getString("resource", getString(R.string.default_resource))
-				.toLowerCase(Locale.getDefault()));
+		String resource;
+		try {
+			resource = sharedPref.getString("resource", getString(R.string.default_resource)).toLowerCase(Locale.ENGLISH);
+			if (resource.trim().isEmpty()) {
+				throw new Exception();
+			}
+		} catch (Exception e) {
+			resource = "conversations";
+		}
+		account.setResource(resource);
 		final XmppConnection connection = new XmppConnection(account, this);
 		connection.setOnMessagePacketReceivedListener(this.mMessageParser);
 		connection.setOnStatusChangedListener(this.statusListener);