Repository: jabref/jabref
Issue: Deleting an entry causes NPE exception

Delete an entry in the current master 64c774b 

```
SEVERE: Exception thrown by subscriber method listen(org.jabref.model.database.event.EntryRemovedEvent) on subscriber org.jabref.gui.BasePanel$EntryRemovedListener@600cdad9 when dispatching event: org.jabref.model.database.event.EntryRemovedEvent@3850ee8f
java.lang.NullPointerException
	at org.jabref.gui.BasePanel$EntryRemovedListener.listen(BasePanel.java:2092)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at com.google.common.eventbus.Subscriber.invokeSubscriberMethod(Subscriber.java:87)
	at com.google.common.eventbus.Subscriber$SynchronizedSubscriber.invokeSubscriberMethod(Subscriber.java:144)
	at com.google.common.eventbus.Subscriber$1.run(Subscriber.java:72)
	at com.google.common.util.concurrent.MoreExecutors$DirectExecutor.execute(MoreExecutors.java:398)
	at com.google.common.eventbus.Subscriber.dispatchEvent(Subscriber.java:67)
	at com.google.common.eventbus.Dispatcher$PerThreadQueuedDispatcher.dispatch(Dispatcher.java:108)
	at com.google.common.eventbus.EventBus.post(EventBus.java:212)
	at org.jabref.model.database.BibDatabase.removeEntry(BibDatabase.java:252)
	at org.jabref.model.database.BibDatabase.removeEntry(BibDatabase.java:236)
	at org.jabref.gui.BasePanel.delete(BasePanel.java:803)
	at org.jabref.gui.BasePanel.lambda$7(BasePanel.java:369)
```

Changed files:
src/main/java/org/jabref/gui/BasePanel.java

diff --git a/src/main/java/org/jabref/gui/BasePanel.java b/src/main/java/org/jabref/gui/BasePanel.java
index 806020c9bf..965675e5d2 100644
--- a/src/main/java/org/jabref/gui/BasePanel.java
+++ b/src/main/java/org/jabref/gui/BasePanel.java
@@ -221,6 +221,10 @@ public class BasePanel extends JPanel implements ClipboardOwner {
         citationStyleCache = new CitationStyleCache(bibDatabaseContext);
         annotationCache = new FileAnnotationCache(bibDatabaseContext);
 
+        this.preview = new PreviewPanel(this, getBibDatabaseContext());
+        DefaultTaskExecutor.runInJavaFXThread(() -> frame().getGlobalSearchBar().getSearchQueryHighlightObservable().addSearchListener(preview));
+        this.previewContainer = CustomJFXPanel.wrap(new Scene(preview));
+
         setupMainPanel();
 
         setupActions();
@@ -249,9 +253,6 @@ public class BasePanel extends JPanel implements ClipboardOwner {
         entryEditor = new EntryEditor(this);
         entryEditorContainer = setupEntryEditor(entryEditor);
 
-        this.preview = new PreviewPanel(this, getBibDatabaseContext());
-        DefaultTaskExecutor.runInJavaFXThread(() -> frame().getGlobalSearchBar().getSearchQueryHighlightObservable().addSearchListener(preview));
-        this.previewContainer = CustomJFXPanel.wrap(new Scene(preview));
     }
 
     private static JFXPanel setupEntryEditor(EntryEditor entryEditor) {
@@ -2060,7 +2061,7 @@ public class BasePanel extends JPanel implements ClipboardOwner {
         @Subscribe
         public void listen(EntryRemovedEvent entryRemovedEvent) {
             // if the entry that is displayed in the current entry editor is removed, close the entry editor
-            if (mode == BasePanelMode.SHOWING_EDITOR && entryEditor.getEntry().equals(entryRemovedEvent.getBibEntry())) {
+            if ((mode == BasePanelMode.SHOWING_EDITOR) && entryEditor.getEntry().equals(entryRemovedEvent.getBibEntry())) {
                 entryEditor.close();
             }