Skip to content

Commit 3445e96

Browse files
authored
Merge pull request pc2ccs#934 from johnbrvc/i_933_server_npe_on_runstable
i933 Explicitly check for server when initializing for RunsTables
2 parents f07f25c + 5019ed3 commit 3445e96

File tree

1 file changed

+35
-20
lines changed

1 file changed

+35
-20
lines changed

src/edu/csus/ecs/pc2/ui/SelectJudgementFrame.java

Lines changed: 35 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
// Copyright (C) 1989-2019 PC2 Development Team: John Clevenger, Douglas Lane, Samir Ashoo, and Troy Boudreau.
1+
// Copyright (C) 1989-2024 PC2 Development Team: John Clevenger, Douglas Lane, Samir Ashoo, and Troy Boudreau.
22
package edu.csus.ecs.pc2.ui;
33

4+
import java.awt.Dimension;
45
import java.io.File;
56

67
import javax.swing.JFrame;
@@ -11,18 +12,19 @@
1112
import edu.csus.ecs.pc2.core.Utilities;
1213
import edu.csus.ecs.pc2.core.execute.Executable;
1314
import edu.csus.ecs.pc2.core.log.Log;
15+
import edu.csus.ecs.pc2.core.model.ClientId;
16+
import edu.csus.ecs.pc2.core.model.ClientType;
1417
import edu.csus.ecs.pc2.core.model.IInternalContest;
1518
import edu.csus.ecs.pc2.core.model.IRunListener;
1619
import edu.csus.ecs.pc2.core.model.Run;
1720
import edu.csus.ecs.pc2.core.model.RunEvent;
1821
import edu.csus.ecs.pc2.core.model.RunEvent.Action;
1922
import edu.csus.ecs.pc2.core.security.Permission;
2023
import edu.csus.ecs.pc2.ui.judge.JudgeView;
21-
import java.awt.Dimension;
2224

2325
/**
2426
* Judge can chose judgement and execute run.
25-
*
27+
*
2628
2729
* @version $Id$
2830
*/
@@ -31,7 +33,7 @@
3133
public class SelectJudgementFrame extends JFrame implements UIPlugin {
3234

3335
/**
34-
*
36+
*
3537
*/
3638
private static final long serialVersionUID = 6532349396307812235L;
3739

@@ -45,10 +47,10 @@ public class SelectJudgementFrame extends JFrame implements UIPlugin {
4547

4648
private Log log = null;
4749

48-
50+
4951
/**
5052
* This method initializes
51-
*
53+
*
5254
*/
5355
public SelectJudgementFrame() {
5456
super();
@@ -57,7 +59,7 @@ public SelectJudgementFrame() {
5759

5860
/**
5961
* This method initializes this
60-
*
62+
*
6163
*/
6264
private void initialize() {
6365
this.setContentPane(getSelectJudgementPane());
@@ -67,6 +69,7 @@ private void initialize() {
6769
this.setTitle("Select Run Judgement");
6870

6971
this.addWindowListener(new java.awt.event.WindowAdapter() {
72+
@Override
7073
public void windowClosing(java.awt.event.WindowEvent e) {
7174
getSelectJudgementPane().handleCancelButton();
7275
}
@@ -75,33 +78,39 @@ public void windowClosing(java.awt.event.WindowEvent e) {
7578

7679
}
7780

81+
@Override
7882
public void setContestAndController(IInternalContest inContest, IInternalController inController) {
7983
this.contest = inContest;
8084
this.controller = inController;
8185

82-
if (!inContest.getAccount(inContest.getClientId()).getPermissionList().isAllowed(Permission.Type.JUDGE_RUN)) {
86+
ClientId clientId = inContest.getClientId();
87+
88+
// SERVER client can do anything, but we have to check it explicitly since there is no server in the account list
89+
if (clientId == null ||
90+
(!clientId.getClientType().equals(ClientType.Type.SERVER) &&
91+
!inContest.getAccount(clientId).getPermissionList().isAllowed(Permission.Type.JUDGE_RUN))) {
8392
throw new SecurityException("SelectJudgementFame requires JUDGE_RUN permission");
8493
}
8594
getSelectJudgementPane().setContestAndController(contest, controller);
8695
getSelectJudgementPane().setParentFrame(this);
8796

8897
contest.addRunListener(new RunListenerImplementation());
89-
98+
9099
log = controller.getLog();
91100
}
92-
101+
93102
public void setRun(Run theRun, boolean rejudgeRun) {
94103
Executable tempEexecutable = new Executable(contest, controller, theRun, null, null);
95104
// clear as soon as we start this run, so View Outputs does not show old info
96-
105+
97106
String temporaryExecuteableDirectory = tempEexecutable.getExecuteDirectoryName();
98-
107+
99108
if (! new File(temporaryExecuteableDirectory).isDirectory()){
100109
// create directory if not present, needed for cleardirectory
101110
log.info("Creating directory "+temporaryExecuteableDirectory);
102111
Utilities.insureDir(temporaryExecuteableDirectory);
103112
}
104-
113+
105114
tempEexecutable.clearDirectory(temporaryExecuteableDirectory);
106115

107116
getSelectJudgementPane().setRun(theRun);
@@ -119,33 +128,37 @@ public void setRun(Run theRun, boolean rejudgeRun) {
119128
}
120129
}
121130

131+
@Override
122132
public String getPluginTitle() {
123133
return "Edit Run Frame";
124134
}
125135

126136
/**
127137
* Run Listener for SelectJudgementFrame.
128-
*
138+
*
129139
130140
* @version $Id$
131141
*/
132142

133143
// $HeadURL$
134144
public class RunListenerImplementation implements IRunListener {
135145

146+
@Override
136147
public void runAdded(RunEvent event) {
137148
// System.out.println("sjf: : "+event.getAction()+" "+event.getSentToClientId()+" "+event.getRun());
138149
// ignore
139150
}
140-
151+
152+
@Override
141153
public void refreshRuns(RunEvent event) {
142154
// ignore
143155
}
144156

157+
@Override
145158
public void runChanged(RunEvent event) {
146-
159+
147160
// System.out.println("sjf: : "+event.getAction()+" "+event.getSentToClientId()+" "+event.getWhoModifiedRun()+" "+event.getRun());
148-
161+
149162
if (run != null) {
150163
if (event.getRun().getElementId().equals(run.getElementId())) {
151164
// RUN_NOT_AVAILABLE is undirected (sentToClient is null)
@@ -155,6 +168,7 @@ public void runChanged(RunEvent event) {
155168
JOptionPane.showMessageDialog(null, "Run " + run.getNumber() + " (Site " + run.getSiteNumber() + ") is not available.");
156169

157170
SwingUtilities.invokeLater(new Runnable() {
171+
@Override
158172
public void run() {
159173
getSelectJudgementPane().enableUpdateButtons(false);
160174
}
@@ -163,9 +177,9 @@ public void run() {
163177
setVisible(false);
164178
} else {
165179
if (event.getSentToClientId() != null && event.getSentToClientId().equals(contest.getClientId())) {
166-
180+
167181
getSelectJudgementPane().setRunAndFiles(event.getRun(), event.getRunFiles(), event.getRunResultFiles());
168-
// stop processing once we get it
182+
// stop processing once we get it
169183
// stops both the duplicate checkedout_run and the run_not_available going to other judges
170184
run = null;
171185
}
@@ -174,14 +188,15 @@ public void run() {
174188
}
175189
}
176190

191+
@Override
177192
public void runRemoved(RunEvent event) {
178193
// TODO Auto-generated method stub
179194
}
180195
}
181196

182197
/**
183198
* This method initializes selectJudgementPane
184-
*
199+
*
185200
* @return edu.csus.ecs.pc2.ui.SelectJudgementPane
186201
*/
187202
private SelectJudgementPaneNew getSelectJudgementPane() {

0 commit comments

Comments
 (0)