Skip to content

Commit 495efa4

Browse files
committed
Make window event listener more robust
1 parent 6de3239 commit 495efa4

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

tmc-plugin/src/fi/helsinki/cs/tmc/spyware/eventsources/WindowStatechangesEventSource.java

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,17 @@ private void reactToEvent(String action, WindowEvent event) {
9595
.add("new_state", event.getNewState())
9696
.add("old_state", event.getOldState())
9797
.toString();
98-
Course course = courseDb.getCurrentCourse();
99-
if (course == null) {
100-
receiver.receiveEvent(
101-
new LoggableEvent(course, action, data.getBytes(Charset.forName("UTF-8"))));
98+
if (courseDb != null) {
99+
Course course = courseDb.getCurrentCourse();
100+
if (course != null) {
101+
receiver.receiveEvent(
102+
new LoggableEvent(course, action, data.getBytes(Charset.forName("UTF-8"))));
103+
} else {
104+
receiver.receiveEvent(
105+
new LoggableEvent(action, data.getBytes(Charset.forName("UTF-8"))));
106+
}
102107
} else {
103-
receiver.receiveEvent(
104-
new LoggableEvent(action, data.getBytes(Charset.forName("UTF-8"))));
108+
log.log(Level.WARNING, "Coursedb is null");
105109
}
106110
}
107111

@@ -165,7 +169,8 @@ private String underscorify(String string) {
165169
}
166170

167171
/**
168-
* Returns {@link FileObject} representing the last active file for each event.
172+
* Returns {@link FileObject} representing the last active file for each
173+
* event.
169174
*/
170175
private FileObject getChangedFile() {
171176
JTextComponent jtc = EditorRegistry.lastFocusedComponent();

0 commit comments

Comments
 (0)