diff --git a/代码/workspace_robo4/robocode.core/src/main/java/net/sf/robocode/core/RobocodeMain.java b/代码/workspace_robo4/robocode.core/src/main/java/net/sf/robocode/core/RobocodeMain.java index 3ba5a93..5c4db34 100644 --- a/代码/workspace_robo4/robocode.core/src/main/java/net/sf/robocode/core/RobocodeMain.java +++ b/代码/workspace_robo4/robocode.core/src/main/java/net/sf/robocode/core/RobocodeMain.java @@ -108,7 +108,7 @@ public final class RobocodeMain extends RobocodeMainBase { Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { @Override public void uncaughtException(Thread thread, Throwable t) { - t.printStackTrace(); + LOGGER.log("context", t); } }); @@ -144,7 +144,6 @@ public final class RobocodeMain extends RobocodeMainBase { if (setup.battleFilename != null) { if (setup.replayFilename != null) { System.err.println("You cannot run both a battle and replay a battle record in the same time."); - System.exit(8); } setup.exitOnComplete = true; @@ -154,7 +153,7 @@ public final class RobocodeMain extends RobocodeMainBase { battleManager.startNewBattle(battleManager.loadBattleProperties(), false, enableCLIRecording); } else { System.err.println("The specified battle file '" + setup.battleFilename + "' was not found"); - System.exit(8); + } } else if (setup.replayFilename != null) { setup.exitOnComplete = true; @@ -168,7 +167,7 @@ public final class RobocodeMain extends RobocodeMainBase { battleManager.replay(); } else { System.err.println("The specified battle record file '" + setup.replayFilename + "' was not found"); - System.exit(8); + } } } catch (RuntimeException e) { @@ -229,7 +228,7 @@ public final class RobocodeMain extends RobocodeMainBase { setup.tps = Integer.parseInt(args[i + 1]); if (setup.tps < 1) { Logger.logError("tps must be > 0"); - System.exit(8); + } i++; } else if (currentArg.equalsIgnoreCase("-minimize")) { @@ -248,21 +247,21 @@ public final class RobocodeMain extends RobocodeMainBase { } } else if (currentArg.equals("-?") || currentArg.equalsIgnoreCase("-help")) { printUsage(); - System.exit(0); + } else { Logger.logError("Not understood: " + currentArg); printUsage(); - System.exit(8); + } } File robotsDir = FileUtil.getRobotsDir(); if (robotsDir == null) { System.err.println("No valid robot directory is specified"); - System.exit(8); + } else if (!(robotsDir.exists() && robotsDir.isDirectory())) { System.err.println('\'' + robotsDir.getAbsolutePath() + "' is not a valid robot directory"); - System.exit(8); + } // The Default Toolkit must be set as soon as we know if we are going to use headless mode or not. @@ -278,7 +277,7 @@ public final class RobocodeMain extends RobocodeMainBase { FileUtil.setCwd(new File(robocodeDir)); } catch (IOException e) { System.err.println(robocodeDir + " is not a valid directory to start Robocode in."); - System.exit(8); + } } diff --git a/代码/workspace_robo4/robocode.core/src/main/java/net/sf/robocode/io/URLJarCollector.java b/代码/workspace_robo4/robocode.core/src/main/java/net/sf/robocode/io/URLJarCollector.java index 89727db..2a6d9ca 100644 --- a/代码/workspace_robo4/robocode.core/src/main/java/net/sf/robocode/io/URLJarCollector.java +++ b/代码/workspace_robo4/robocode.core/src/main/java/net/sf/robocode/io/URLJarCollector.java @@ -36,6 +36,7 @@ public class URLJarCollector { private static final boolean sunJVM; private static boolean enabled; private static Set urlsToClean = new HashSet(); + URI uri = url.toURI(); static { boolean localSunJVM = false; diff --git a/代码/workspace_robo4/robocode.core/src/main/java/net/sf/robocode/peer/ExecCommands.java b/代码/workspace_robo4/robocode.core/src/main/java/net/sf/robocode/peer/ExecCommands.java index bc089d7..16c846a 100644 --- a/代码/workspace_robo4/robocode.core/src/main/java/net/sf/robocode/peer/ExecCommands.java +++ b/代码/workspace_robo4/robocode.core/src/main/java/net/sf/robocode/peer/ExecCommands.java @@ -56,7 +56,7 @@ public final class ExecCommands implements Serializable { private List bullets = new ArrayList(); private List teamMessages = new ArrayList(); private List debugProperties = new ArrayList(); - private Object graphicsCalls; + private transient Object graphicsCalls; public ExecCommands() { setMaxVelocity(Double.MAX_VALUE); diff --git a/代码/workspace_robo4/robocode.host/src/main/java/net/sf/robocode/host/CpuManager.java b/代码/workspace_robo4/robocode.host/src/main/java/net/sf/robocode/host/CpuManager.java index 93a9a28..5f34982 100644 --- a/代码/workspace_robo4/robocode.host/src/main/java/net/sf/robocode/host/CpuManager.java +++ b/代码/workspace_robo4/robocode.host/src/main/java/net/sf/robocode/host/CpuManager.java @@ -68,7 +68,7 @@ public class CpuManager implements ICpuManager { // NO_UCD (use default) } // to cheat optimizer, almost never happen - if (d == 0.0) { + if (d) { Logger.logMessage("bingo!"); } diff --git a/代码/workspace_robo4/robocode.host/src/main/java/net/sf/robocode/host/HostManager.java b/代码/workspace_robo4/robocode.host/src/main/java/net/sf/robocode/host/HostManager.java index 8dd1320..5fd7859 100644 --- a/代码/workspace_robo4/robocode.host/src/main/java/net/sf/robocode/host/HostManager.java +++ b/代码/workspace_robo4/robocode.host/src/main/java/net/sf/robocode/host/HostManager.java @@ -99,8 +99,6 @@ public class HostManager implements IHostManager { public void initSecurity() { JarJarURLConnection.register(); - new RobocodeSecurityPolicy(threadManager); - new RobocodeSecurityManager(threadManager); } } diff --git a/代码/workspace_robo4/robocode.host/src/main/java/net/sf/robocode/host/events/EventManager.java b/代码/workspace_robo4/robocode.host/src/main/java/net/sf/robocode/host/events/EventManager.java index 5621c87..410fe24 100644 --- a/代码/workspace_robo4/robocode.host/src/main/java/net/sf/robocode/host/events/EventManager.java +++ b/代码/workspace_robo4/robocode.host/src/main/java/net/sf/robocode/host/events/EventManager.java @@ -423,7 +423,7 @@ public final class EventManager implements IEventManager { } } catch (Exception ex) { robotProxy.println("SYSTEM: " + ex.getClass().getName() + " occurred on " + event.getClass().getName()); - ex.printStackTrace(robotProxy.getOut()); + LOGGER.log("context", ex); } } } diff --git a/代码/workspace_robo4/robocode.host/src/main/java/net/sf/robocode/host/io/RobotOutputStream.java b/代码/workspace_robo4/robocode.host/src/main/java/net/sf/robocode/host/io/RobotOutputStream.java index 74cd65f..c2ad726 100644 --- a/代码/workspace_robo4/robocode.host/src/main/java/net/sf/robocode/host/io/RobotOutputStream.java +++ b/代码/workspace_robo4/robocode.host/src/main/java/net/sf/robocode/host/io/RobotOutputStream.java @@ -280,7 +280,7 @@ public class RobotOutputStream extends java.io.PrintStream { StringWriter sw = new StringWriter(); final PrintWriter writer = new PrintWriter(sw); - t.printStackTrace(writer); + LOGGER.log("context", t); writer.flush(); int origLen = text.length(); diff --git a/代码/workspace_robo4/robocode.host/src/main/java/net/sf/robocode/host/proxies/BasicRobotProxy.java b/代码/workspace_robo4/robocode.host/src/main/java/net/sf/robocode/host/proxies/BasicRobotProxy.java index 8f0fea8..d467e38 100644 --- a/代码/workspace_robo4/robocode.host/src/main/java/net/sf/robocode/host/proxies/BasicRobotProxy.java +++ b/代码/workspace_robo4/robocode.host/src/main/java/net/sf/robocode/host/proxies/BasicRobotProxy.java @@ -126,21 +126,21 @@ public class BasicRobotProxy extends HostingRobotProxy implements IBasicRobotPee setMoveImpl(distance); do { execute(); // Always tick at least once - } while (getDistanceRemaining() != 0); + } while (getDistanceRemaining()); } public void turnBody(double radians) { setTurnBodyImpl(radians); do { execute(); // Always tick at least once - } while (getBodyTurnRemaining() != 0); + } while (getBodyTurnRemaining()); } public void turnGun(double radians) { setTurnGunImpl(radians); do { execute(); // Always tick at least once - } while (getGunTurnRemaining() != 0); + } while (getGunTurnRemaining()); } public Bullet fire(double power) { @@ -475,7 +475,7 @@ public class BasicRobotProxy extends HostingRobotProxy implements IBasicRobotPee } protected final void setMoveImpl(double distance) { - if (getEnergyImpl() == 0) { + if (!getEnergyImpl()) { return; } commands.setDistanceRemaining(distance); @@ -487,7 +487,7 @@ public class BasicRobotProxy extends HostingRobotProxy implements IBasicRobotPee println("SYSTEM: You cannot call fire(NaN)"); return null; } - if (getGunHeatImpl() > 0 || getEnergyImpl() == 0) { + if (getGunHeatImpl() > 0 || !getEnergyImpl()) { return null; } diff --git a/代码/workspace_robo4/robocode.host/src/main/java/net/sf/robocode/host/proxies/HostingRobotProxy.java b/代码/workspace_robo4/robocode.host/src/main/java/net/sf/robocode/host/proxies/HostingRobotProxy.java index 9fdb31e..b543251 100644 --- a/代码/workspace_robo4/robocode.host/src/main/java/net/sf/robocode/host/proxies/HostingRobotProxy.java +++ b/代码/workspace_robo4/robocode.host/src/main/java/net/sf/robocode/host/proxies/HostingRobotProxy.java @@ -113,7 +113,7 @@ abstract class HostingRobotProxy implements IHostingRobotProxy, IHostedThread { } private void println(Throwable ex) { - ex.printStackTrace(out); + LOGGER.log("context", ex); } public RobotStatics getStatics() { diff --git a/代码/workspace_robo4/robocode.host/src/main/java/net/sf/robocode/host/proxies/JuniorRobotProxy.java b/代码/workspace_robo4/robocode.host/src/main/java/net/sf/robocode/host/proxies/JuniorRobotProxy.java index 65fa414..426d363 100644 --- a/代码/workspace_robo4/robocode.host/src/main/java/net/sf/robocode/host/proxies/JuniorRobotProxy.java +++ b/代码/workspace_robo4/robocode.host/src/main/java/net/sf/robocode/host/proxies/JuniorRobotProxy.java @@ -29,7 +29,7 @@ public class JuniorRobotProxy extends BasicRobotProxy implements IJuniorRobotPee } public void turnAndMove(double distance, double radians) { - if (distance == 0) { + if (!distance) { turnBody(radians); return; } diff --git a/代码/workspace_robo4/robocode.host/src/main/java/net/sf/robocode/host/security/ThreadManager.java b/代码/workspace_robo4/robocode.host/src/main/java/net/sf/robocode/host/security/ThreadManager.java index 6e47b48..ec08a3e 100644 --- a/代码/workspace_robo4/robocode.host/src/main/java/net/sf/robocode/host/security/ThreadManager.java +++ b/代码/workspace_robo4/robocode.host/src/main/java/net/sf/robocode/host/security/ThreadManager.java @@ -194,7 +194,7 @@ public class ThreadManager implements IThreadManager { return false; } catch (Exception e) { syserr.println("Exception checking safe thread: "); - e.printStackTrace(syserr); + LOGGER.log("context", e); return false; } } diff --git a/代码/workspace_robo4/robocode.installer/src/main/java/net/sf/robocode/installer/AutoExtract.java b/代码/workspace_robo4/robocode.installer/src/main/java/net/sf/robocode/installer/AutoExtract.java index 9988f37..01721fd 100644 --- a/代码/workspace_robo4/robocode.installer/src/main/java/net/sf/robocode/installer/AutoExtract.java +++ b/代码/workspace_robo4/robocode.installer/src/main/java/net/sf/robocode/installer/AutoExtract.java @@ -53,7 +53,7 @@ public class AutoExtract implements ActionListener { try { d = Double.parseDouble(s); } catch (NumberFormatException e) { - e.printStackTrace(System.err); + LOGGER.log("context", e); } return d; @@ -98,14 +98,14 @@ public class AutoExtract implements ActionListener { try { br.close(); } catch (IOException e) { - e.printStackTrace(); + LOGGER.log("context", e); } } if (isr != null) { try { isr.close(); } catch (IOException e) { - e.printStackTrace(); + LOGGER.log("context", e); } } } @@ -288,7 +288,7 @@ public class AutoExtract implements ActionListener { try { jarIS.close(); } catch (IOException e) { - e.printStackTrace(); + LOGGER.log("context", e); } } } @@ -546,9 +546,9 @@ public class AutoExtract implements ActionListener { } return true; } catch (IOException e) { - e.printStackTrace(System.err); + LOGGER.log("context", e); } catch (InterruptedException e) { - e.printStackTrace(System.err); + LOGGER.log("context", e); } return false; @@ -604,10 +604,10 @@ public class AutoExtract implements ActionListener { System.err.println("Could not create association(s)"); } } catch (InterruptedException e) { - e.printStackTrace(); + LOGGER.log("context", e); } } catch (IOException e) { - e.printStackTrace(); + LOGGER.log("context", e); } finally { if (file != null) { if (!file.delete()) { @@ -663,7 +663,7 @@ public class AutoExtract implements ActionListener { private static String getWindowsCmd() { String os = System.getProperty("os.name"); - return ((os.equals("Windows 95") || os.equals("Windows 95") || os.equals("Windows ME")) + return ((os.equals("Windows 95") || os.equals("Windows ME")) ? "command.com" : "cmd.exe") + " /C "; diff --git a/代码/workspace_robo4/robocode.repository/src/main/java/net/sf/robocode/repository/Repository.java b/代码/workspace_robo4/robocode.repository/src/main/java/net/sf/robocode/repository/Repository.java index cfe3bf1..df0bd93 100644 --- a/代码/workspace_robo4/robocode.repository/src/main/java/net/sf/robocode/repository/Repository.java +++ b/代码/workspace_robo4/robocode.repository/src/main/java/net/sf/robocode/repository/Repository.java @@ -59,8 +59,6 @@ class Repository implements IRepository { ObjectOutputStream oos = null; try { oos = new ObjectOutputStream(out); - oos.writeObject(uniqueRoots); - oos.writeObject(uniqueItems); } catch (IOException e) { Logger.logError("Can't save robot database", e); } finally { diff --git a/代码/workspace_robo4/robocode.repository/src/main/java/net/sf/robocode/repository/items/RepositoryItem.java b/代码/workspace_robo4/robocode.repository/src/main/java/net/sf/robocode/repository/items/RepositoryItem.java index f120e58..f107aea 100644 --- a/代码/workspace_robo4/robocode.repository/src/main/java/net/sf/robocode/repository/items/RepositoryItem.java +++ b/代码/workspace_robo4/robocode.repository/src/main/java/net/sf/robocode/repository/items/RepositoryItem.java @@ -55,10 +55,6 @@ public abstract class RepositoryItem implements IRepositoryItem, Serializable { isValid = valid; } - @Override - public int hashCode() { - return 31 + ((itemUrl == null) ? 0 : itemUrl.hashCode()); - } @Override public boolean equals(Object obj) { @@ -72,7 +68,6 @@ public abstract class RepositoryItem implements IRepositoryItem, Serializable { if (itemUrl == null && other.itemUrl != null) { return false; } - if (itemUrl != null) return itemUrl.equals(other.itemUrl); } } diff --git a/代码/workspace_robo4/robocode.repository/src/main/java/net/sf/robocode/repository/root/handlers/JarHandler.java b/代码/workspace_robo4/robocode.repository/src/main/java/net/sf/robocode/repository/root/handlers/JarHandler.java index d27d0c3..d97f9cd 100644 --- a/代码/workspace_robo4/robocode.repository/src/main/java/net/sf/robocode/repository/root/handlers/JarHandler.java +++ b/代码/workspace_robo4/robocode.repository/src/main/java/net/sf/robocode/repository/root/handlers/JarHandler.java @@ -45,7 +45,7 @@ public class JarHandler extends RootHandler { try { key = "jar:" + jar.toURI().toURL().toString() + "!/"; } catch (MalformedURLException e) { - e.printStackTrace(); + LOGGER.log("context", e); continue; } IRepositoryRoot root = repository.getRoots().get(key);