Skip to content

Commit

Permalink
log stack traces
Browse files Browse the repository at this point in the history
  • Loading branch information
milanvanzanten committed Jun 22, 2015
1 parent be8bf1f commit 7669b88
Show file tree
Hide file tree
Showing 12 changed files with 38 additions and 29 deletions.
8 changes: 4 additions & 4 deletions src/client/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@ public void runClient() {
*/
public void processMessages() {
while(getProtocolManager() == null) { // sometimes accessing getProtocolManager() throws a mysterious null pointer exception. Wait until it can't anymore
try { Thread.sleep(1); } catch (InterruptedException e) { e.printStackTrace(); } }
try { Thread.sleep(1); } catch (InterruptedException e) { logStackTrace(e); } }
while(getProtocolManager().getMessagesToProcess() == null) { // sometimes accessing getMessagesToProcess() throws a mysterious null pointer exception. Wait until it can't anymore
try { Thread.sleep(1); } catch (InterruptedException e) { e.printStackTrace(); } }
try { Thread.sleep(1); } catch (InterruptedException e) { logStackTrace(e); } }

while(getProtocolManager().getMessagesToProcess().size() > 0) {
SBProtocolMessage message = getProtocolManager().getNextMessageToProcessAndStoreIt();
Expand All @@ -97,9 +97,9 @@ public void processMessages() {
*/
public void processAnswers() {
while(getProtocolManager() == null) { // sometimes accessing getProtocolManager() throws a mysterious null pointer exception. Wait until it can't anymore
try { Thread.sleep(1); } catch (InterruptedException e) { e.printStackTrace(); } }
try { Thread.sleep(1); } catch (InterruptedException e) { logStackTrace(e); } }
while(getProtocolManager().getAnswersToProcess() == null) { // sometimes accessing getAnswersToProcess() throws a mysterious null pointer exception. Wait until it can't anymore
try { Thread.sleep(1); } catch (InterruptedException e) { e.printStackTrace(); } }
try { Thread.sleep(1); } catch (InterruptedException e) { logStackTrace(e); } }

while(getProtocolManager().getAnswersToProcess().size() > 0) {
SBProtocolMessage answer = getProtocolManager().getAnswersToProcess().poll();
Expand Down
2 changes: 1 addition & 1 deletion src/client/display/GameCanvas.java
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ else if(getPitchMouseLogic().getHoveringPlayerOnBench() != null)
}
} catch(NullPointerException e) {
getClient().log(Level.WARNING, "Received nullpointer in PitchCanvas but continuing anyway.");
e.printStackTrace();
getGameFrame().getClient().logStackTrace(e);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/client/display/GameFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ public void blitzOrBlock(DrawingPath path, PitchField destination, Player actor)
}
} catch (NullPointerException e) {
getClient().log(Level.WARNING, "Catched nullpointer while blitzing! (But continuing)");
e.printStackTrace();
getClient().logStackTrace(e);
}
}
}
Expand All @@ -323,7 +323,7 @@ public void throwBall(PitchField throwDestination, Player thrower) {
getClient().sendGameMessage(new SBProtocolMessage(getClient().getUID(), SBProtocolCommand.ACTIO, params));
} catch (NullPointerException e) {
getClient().log(Level.WARNING, "Catched nullpointer while throwing! (But continuing)");
e.printStackTrace();
getClient().logStackTrace(e);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/client/display/LoginPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ private void sendLoginForm(String name, String password) {
md.update(password.getBytes("UTF-8"));
digest = md.digest(password.getBytes("UTF-8"));
} catch (Exception e) {
e.printStackTrace();
parent.getClient().logStackTrace(e);
}
password = DatatypeConverter.printHexBinary(digest).toLowerCase();
// submit form
Expand Down
6 changes: 3 additions & 3 deletions src/client/logic/ClientMatch.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public void processMessage(SBProtocolMessage message) {
break;
}
}catch(IndexOutOfBoundsException e){
e.printStackTrace();
getClient().logStackTrace(e);
returnFailureMessage(message, SBProtocolMessage.FAILD_PARAMANIA_HAS_TAKEN_OVER);
}
}
Expand Down Expand Up @@ -414,7 +414,7 @@ private void processAnswerFAI(SBProtocolMessage answer, SBProtocolMessage messag
try {
Thread.sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
getClient().logStackTrace(e);
}
}
}
Expand Down Expand Up @@ -623,7 +623,7 @@ private void adjustPlayer(SBProtocolMessage message){
teams[actingUserIndex].getPlayers().get(playerIndex).invokeAdjustPosition(getPitch().getFields()[playerPosX][playerPosY]);
}
}catch(NullPointerException e){
e.printStackTrace();
getClient().logStackTrace(e);
}
teams[actingUserIndex].getPlayers().get(playerIndex).getPosition().adjustPlayer(teams[actingUserIndex].getPlayers().get(playerIndex));
teams[actingUserIndex].getPlayers().get(playerIndex).invokeSetIsHoldingBall(Boolean.parseBoolean(message.getParameterContent(12)));
Expand Down
4 changes: 2 additions & 2 deletions src/client/logic/PitchMouseLogic.java
Original file line number Diff line number Diff line change
Expand Up @@ -395,9 +395,9 @@ void calculate(MouseEvent e) {
}

} catch(IndexOutOfBoundsException ex) {
ex.printStackTrace();
getGameCanvas().getClient().logStackTrace(ex);
} catch(NullPointerException ex) {
ex.printStackTrace();
getGameCanvas().getClient().logStackTrace(ex);
}
}

Expand Down
16 changes: 8 additions & 8 deletions src/gameLogic/TeamManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,15 @@ public TeamManager(SBApplication parent, URL teamsURL) {
try {
teamsStream = new DataInputStream(teamsURL.openStream());
} catch (IOException e) {
e.printStackTrace();
getParent().logStackTrace(e);
}

if(teamsStream != null) { // stream was successfully opened
try {
tempFile.delete(); // delete old temp file
Files.copy(teamsStream, Paths.get(tempFile.toURI()));
} catch (IOException e) {
e.printStackTrace();
getParent().logStackTrace(e);
}
}
}
Expand Down Expand Up @@ -164,12 +164,12 @@ private void setUp(File teamsDir) {
}

} catch (FileNotFoundException e) {
e.printStackTrace();
getParent().logStackTrace(e);
} catch (NullPointerException e) {
e.printStackTrace();
getParent().logStackTrace(e);
} catch (ScriptException e) {
getParent().log(Level.SEVERE, "Exception in script " + filename + ".");
e.printStackTrace();
getParent().logStackTrace(e);
System.exit(-1);
}

Expand Down Expand Up @@ -204,14 +204,14 @@ public Object invokeFunction(String functionName, Player actor, Object... params
for(Object param : params)
getParent().log(Level.SEVERE, param.toString());
}
e.printStackTrace();
getParent().logStackTrace(e);
System.exit(-1);
} catch (NoSuchMethodException ignored) { // script didn't contain method
// Removed warnings to prevent overflowing the logs
// getParent().log(Level.WARNING, "Script of " + actor.getName() + " didn't contain method " + functionName + ".");
// e.printStackTrace();
// getParent().logStackTrace(e);
} catch (NullPointerException e) { // invocable didn't exist
e.printStackTrace();
getParent().logStackTrace(e);
}
return null;
}
Expand Down
2 changes: 1 addition & 1 deletion src/gameLogic/rules/RuleMove.java
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ protected boolean moveOneField(SBProtocolMessage message, int i, PitchField... p
try{
Thread.sleep(300);
}catch(InterruptedException e){
e.printStackTrace();
getMatch().getParent().logStackTrace(e);
}
}
//is the field next to the player?
Expand Down
2 changes: 1 addition & 1 deletion src/network/SBSocket.java
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ public void run() {
}
try { // sleep for a bit after each received message (prevents null from flooding the logs)
Thread.sleep(10);
} catch (InterruptedException e) { e.printStackTrace(); }
} catch (InterruptedException e) { getSocketManager().getParent().logStackTrace(e); }
} else {
break;
}
Expand Down
8 changes: 4 additions & 4 deletions src/server/logic/ServerMatch.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public void processMessage(SBProtocolMessage message) {
returnFailureMessage(message, SBProtocolMessage.FAILD_NOT_YOUR_TURN);
}
}catch(IndexOutOfBoundsException e){
e.printStackTrace();
getParent().logStackTrace(e);
returnFailureMessage(message, SBProtocolMessage.FAILD_PARAMANIA_HAS_TAKEN_OVER);
}
}
Expand Down Expand Up @@ -181,7 +181,7 @@ private boolean processAnswerSUC(SBProtocolMessage answer, SBProtocolMessage mes
return false;
}
}catch(IndexOutOfBoundsException e){
e.printStackTrace();
getParent().logStackTrace(e);
returnFailureMessage(message, SBProtocolMessage.FAILD_PARAMANIA_HAS_TAKEN_OVER);
return false;
}
Expand Down Expand Up @@ -285,7 +285,7 @@ private boolean processAnswerFAI(SBProtocolMessage answer, SBProtocolMessage mes
try {
Thread.sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
getParent().logStackTrace(e);
}
}
}
Expand Down Expand Up @@ -550,7 +550,7 @@ private void move(SBProtocolMessage message){
returnFailureMessage(message, SBProtocolMessage.FAILD_GIMME_AN_INT);
return;
} catch(ArrayIndexOutOfBoundsException e) {
e.printStackTrace();
getParent().logStackTrace(e);
return;
}
PitchField[] path = new PitchField[x.length];
Expand Down
2 changes: 1 addition & 1 deletion src/server/logic/ServerMessageProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public void processAnswer(SBProtocolMessage answer) {
}
} catch(ConcurrentModificationException e) {
getServer().log(Level.SEVERE, "Catched concurrent modification exception! But continuing anyway.");
e.printStackTrace();
getServer().logStackTrace(e);
}
}
getProtocolManager().removeUnansweredMessage(message);
Expand Down
11 changes: 10 additions & 1 deletion src/util/SBApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public void loadAvailableTeams(String host, String file) {
teamsURL = new URL("http", host, 80, file);
} catch (MalformedURLException e) {
log(Level.SEVERE, "Could not load available teams. Make sure you are connected to the Internet and the URL is correct.");
e.printStackTrace();
logStackTrace(e);
}
teamManager = new TeamManager(this, teamsURL);
}
Expand Down Expand Up @@ -142,4 +142,13 @@ public UUID getUID() {
public abstract boolean checkIfUserExists(String name);

public abstract void log(Level level, String message);

/**
* Log all elements of a stack trace.
* @param e An Exception whose stack trace to print.
*/
public void logStackTrace(Exception e) {
for(StackTraceElement element: e.getStackTrace())
log(Level.SEVERE, element.toString());
}
}

0 comments on commit 7669b88

Please sign in to comment.