Skip to content

Commit

Permalink
Fix npe on disconnect when session is not inlitiazed
Browse files Browse the repository at this point in the history
  • Loading branch information
Siedlerchr committed Jul 15, 2017
1 parent 325f978 commit 05cace0
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 13 deletions.
11 changes: 7 additions & 4 deletions src/main/java/org/jabref/gui/JabRefFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,12 @@
import org.jabref.gui.actions.Actions;
import org.jabref.gui.actions.AutoLinkFilesAction;
import org.jabref.gui.actions.ConnectToSharedDatabaseAction;
import org.jabref.gui.actions.DisconnectFromSharelatexAction;
import org.jabref.gui.actions.ErrorConsoleAction;
import org.jabref.gui.actions.IntegrityCheckAction;
import org.jabref.gui.actions.LookupIdentifierAction;
import org.jabref.gui.actions.ManageKeywordsAction;
import org.jabref.gui.actions.ManageShareLatexAction;
import org.jabref.gui.actions.SynchronizeWithShareLatexAction;
import org.jabref.gui.actions.MassSetFieldAction;
import org.jabref.gui.actions.MnemonicAwareAction;
import org.jabref.gui.actions.NewDatabaseAction;
Expand Down Expand Up @@ -394,8 +395,9 @@ public void actionPerformed(ActionEvent e) {
Localization.lang("Unabbreviate journal names of the selected entries"),
Globals.getKeyPrefs().getKey(KeyBinding.UNABBREVIATE));
private final AbstractAction manageJournals = new ManageJournalsAction();
private final AbstractAction manageSharelatex = new ManageShareLatexAction();
private final AbstractAction synchronizeWithSharelatex = new SynchronizeWithShareLatexAction();
private final AbstractAction sendChangesToShareLatex = new SendChangesToShareLatexAction();
private final AbstractAction disconnectFromSharelatex = new DisconnectFromSharelatexAction();

private final AbstractAction databaseProperties = new DatabasePropertiesAction();
private final AbstractAction bibtexKeyPattern = new BibtexKeyPatternAction();
Expand Down Expand Up @@ -1060,8 +1062,9 @@ private void fillMenu() {
file.add(connectToSharedDatabaseAction);
file.add(pullChangesFromSharedDatabase);
file.addSeparator();
file.add(manageSharelatex);
file.add(synchronizeWithSharelatex);
file.add(sendChangesToShareLatex);
file.add(disconnectFromSharelatex);

file.addSeparator();
file.add(databaseProperties);
Expand Down Expand Up @@ -1338,7 +1341,7 @@ private void createToolBar() {
tlb.addAction(cleanupEntries);
tlb.addAction(mergeEntries);
tlb.addAction(pullChangesFromSharedDatabase);
tlb.addAction(manageSharelatex);
tlb.addAction(synchronizeWithSharelatex);
tlb.addAction(openConsole);

tlb.addSeparator();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package org.jabref.gui.actions;

import java.awt.event.ActionEvent;

import javax.swing.AbstractAction;
import javax.swing.Action;

import org.jabref.Globals;

public class DisconnectFromSharelatexAction extends AbstractAction {

public DisconnectFromSharelatexAction() {
super();
putValue(Action.NAME, "Disconnect from ShareLaTeX");

}

@Override
public void actionPerformed(ActionEvent e) {
Globals.shareLatexManager.disconnectAndCloseConnection();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public void actionPerformed(ActionEvent e) {

ShareLatexManager manager = Globals.shareLatexManager;
StateManager stateManager = Globals.stateManager;
manager.sendNewDataseContent(stateManager.getActiveDatabase().get());
manager.sendNewDatabaseContent(stateManager.getActiveDatabase().get());
System.out.println("Send changes");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
import org.jabref.gui.IconTheme;
import org.jabref.gui.sharelatex.ShareLatexLoginDialogView;

public class ManageShareLatexAction extends AbstractAction {
public class SynchronizeWithShareLatexAction extends AbstractAction {

public ManageShareLatexAction() {
public SynchronizeWithShareLatexAction() {
super();
putValue(Action.NAME, "Synchronize with ShareLaTeX");
putValue(Action.SMALL_ICON, IconTheme.getImage("sharelatex"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public void startWebSocketHandler(String projectID, BibDatabaseContext database,
});
}

public void sendNewDataseContent(BibDatabaseContext database) {
public void sendNewDatabaseContent(BibDatabaseContext database) {
try {
BibtexDatabaseWriter<StringSaveSession> databaseWriter = new BibtexDatabaseWriter<>(StringSaveSession::new);
SavePreferences preferences = new SavePreferences().withEncoding(StandardCharsets.UTF_8).withSaveInOriginalOrder(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ public void createAndConnect(URI webSocketchannelUri, String projectId, BibDatab
public boolean onConnectFailure(Exception exception) {
final int i = counter.incrementAndGet();
if (i <= 3) {
System.out.println(
"### Reconnecting... (reconnect count: " + i + ") " + exception.getMessage());
LOGGER.debug(
"### Reconnecting... (reconnect count: " + i + ")", exception);
return true;
} else {
messageLatch.countDown();
Expand Down Expand Up @@ -155,7 +155,9 @@ public void joinDoc(String documentId) throws IOException {
public void leaveDocument(String documentId) throws IOException {
incrementCommandCounter();
String text = "5:" + commandCounter + "+::{\"name\":\"leaveDoc\",\"args\":[\"" + documentId + "\"]}";
session.getBasicRemote().sendText(text);
if (session != null) {
session.getBasicRemote().sendText(text);
}

}

Expand Down Expand Up @@ -284,8 +286,9 @@ public void setDatabaseName(String bibFileName) {
public void leaveDocAndCloseConn() throws IOException {
leaveDocument(docId);
queue.clear();
session.close();

if (session != null) {
session.close();
}
}

public void setServerNameOrigin(String serverOrigin) {
Expand Down

0 comments on commit 05cace0

Please sign in to comment.