From c8212aef89a848ea8fd922b66a6c350036b36978 Mon Sep 17 00:00:00 2001 From: tsszh Date: Tue, 22 Mar 2016 18:41:49 +0800 Subject: [PATCH] Fix the bug of initial setup For the first time, load() will five null, which would cause the NullPointerException --- JenkinsPlugin/src/main/java/jenkins/plugins/slack/SlackBot.java | 1 + .../src/main/java/jenkins/plugins/slack/SlackBotServer.java | 2 ++ 2 files changed, 3 insertions(+) diff --git a/JenkinsPlugin/src/main/java/jenkins/plugins/slack/SlackBot.java b/JenkinsPlugin/src/main/java/jenkins/plugins/slack/SlackBot.java index 20dc1c2..7c7cbdf 100644 --- a/JenkinsPlugin/src/main/java/jenkins/plugins/slack/SlackBot.java +++ b/JenkinsPlugin/src/main/java/jenkins/plugins/slack/SlackBot.java @@ -113,6 +113,7 @@ void setSlackBot(String slackToken, String userID) { void connectToSlack(String token) { this.session = SlackSessionFactory.createWebSocketSlackSession(token); this.session.addMessagePostedListener(postedHangdler); + logger.info("Connecting to Slack Server ("+token+")...");; try { this.session.connect(); logger.info("Connection to SLack: Success - "+token); diff --git a/JenkinsPlugin/src/main/java/jenkins/plugins/slack/SlackBotServer.java b/JenkinsPlugin/src/main/java/jenkins/plugins/slack/SlackBotServer.java index fd8b5ab..8bd343d 100644 --- a/JenkinsPlugin/src/main/java/jenkins/plugins/slack/SlackBotServer.java +++ b/JenkinsPlugin/src/main/java/jenkins/plugins/slack/SlackBotServer.java @@ -42,6 +42,8 @@ public void start() throws Exception { bot = new SlackBot(); // Create the slackbot (new Thread(bot)).start(); // Thread for slack bot server load(); // Loads token & userID of this instance from the persisted storage. + if ( this.token == null ) this.token = ""; + if ( this.userID == null ) this.userID = ""; resetSlackBot(); } /**