Просмотр исходного кода

Fixes issue 3515: Twitter parser NPEs in the ctor if you dont give it a user

Change-Id: I754c511f161c0ba4ef1b1cba36e0c8a6d9e9e717
Reviewed-on: http://gerrit.dmdirc.com/743
Automatic-Compile: DMDirc Local Commits <dmdirc@googlemail.com>
Reviewed-by: Chris Smith <chris@dmdirc.com>
tags/0.6.3
Gregory Holmes 14 лет назад
Родитель
Сommit
16b869a995
1 измененных файлов: 13 добавлений и 2 удалений
  1. 13
    2
      src/com/dmdirc/addons/parser_twitter/Twitter.java

+ 13
- 2
src/com/dmdirc/addons/parser_twitter/Twitter.java Просмотреть файл

@@ -176,8 +176,13 @@ public class Twitter implements Parser, TwitterErrorHandler, TwitterRawHandler,
176 176
      * @param myPlugin Plugin that created this parser
177 177
      */
178 178
     protected Twitter(final MyInfo myInfo, final URI address, final TwitterPlugin myPlugin) {
179
-        final String[] bits = address.getUserInfo().split(":");
180
-        this.myUsername = bits[0];
179
+        final String[] bits;
180
+        if (address.getUserInfo() == null) {
181
+            bits = new String[]{};
182
+        } else {
183
+            bits = address.getUserInfo().split(":");
184
+        }
185
+        this.myUsername = bits.length == 0 ? "" : bits[0];
181 186
         this.myPassword = (bits.length > 1) ? bits[1] : "";
182 187
 
183 188
         this.myPlugin = myPlugin;
@@ -872,6 +877,12 @@ public class Twitter implements Parser, TwitterErrorHandler, TwitterRawHandler,
872 877
     public void run() {
873 878
         resetState();
874 879
 
880
+        if (myUsername.isEmpty()) {
881
+            sendPrivateNotice("Unable to connect to "+myServerName+" without a username. Disconnecting.");
882
+            getCallbackManager().getCallbackType(SocketCloseListener.class).call();
883
+            return;
884
+        }
885
+
875 886
         // Get the consumerKey and consumerSecret for this server if known
876 887
         // else default to our twitter key and secret
877 888
         final String consumerKey;

Загрузка…
Отмена
Сохранить