修改严重代码
This commit is contained in:
parent
37cb8ae223
commit
428f63be82
|
@ -108,7 +108,7 @@ public final class RobocodeMain extends RobocodeMainBase {
|
||||||
Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
|
Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
|
||||||
@Override
|
@Override
|
||||||
public void uncaughtException(Thread thread, Throwable t) {
|
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.battleFilename != null) {
|
||||||
if (setup.replayFilename != null) {
|
if (setup.replayFilename != null) {
|
||||||
System.err.println("You cannot run both a battle and replay a battle record in the same time.");
|
System.err.println("You cannot run both a battle and replay a battle record in the same time.");
|
||||||
System.exit(8);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
setup.exitOnComplete = true;
|
setup.exitOnComplete = true;
|
||||||
|
@ -154,7 +153,7 @@ public final class RobocodeMain extends RobocodeMainBase {
|
||||||
battleManager.startNewBattle(battleManager.loadBattleProperties(), false, enableCLIRecording);
|
battleManager.startNewBattle(battleManager.loadBattleProperties(), false, enableCLIRecording);
|
||||||
} else {
|
} else {
|
||||||
System.err.println("The specified battle file '" + setup.battleFilename + "' was not found");
|
System.err.println("The specified battle file '" + setup.battleFilename + "' was not found");
|
||||||
System.exit(8);
|
|
||||||
}
|
}
|
||||||
} else if (setup.replayFilename != null) {
|
} else if (setup.replayFilename != null) {
|
||||||
setup.exitOnComplete = true;
|
setup.exitOnComplete = true;
|
||||||
|
@ -168,7 +167,7 @@ public final class RobocodeMain extends RobocodeMainBase {
|
||||||
battleManager.replay();
|
battleManager.replay();
|
||||||
} else {
|
} else {
|
||||||
System.err.println("The specified battle record file '" + setup.replayFilename + "' was not found");
|
System.err.println("The specified battle record file '" + setup.replayFilename + "' was not found");
|
||||||
System.exit(8);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (RuntimeException e) {
|
} catch (RuntimeException e) {
|
||||||
|
@ -229,7 +228,7 @@ public final class RobocodeMain extends RobocodeMainBase {
|
||||||
setup.tps = Integer.parseInt(args[i + 1]);
|
setup.tps = Integer.parseInt(args[i + 1]);
|
||||||
if (setup.tps < 1) {
|
if (setup.tps < 1) {
|
||||||
Logger.logError("tps must be > 0");
|
Logger.logError("tps must be > 0");
|
||||||
System.exit(8);
|
|
||||||
}
|
}
|
||||||
i++;
|
i++;
|
||||||
} else if (currentArg.equalsIgnoreCase("-minimize")) {
|
} else if (currentArg.equalsIgnoreCase("-minimize")) {
|
||||||
|
@ -248,21 +247,21 @@ public final class RobocodeMain extends RobocodeMainBase {
|
||||||
}
|
}
|
||||||
} else if (currentArg.equals("-?") || currentArg.equalsIgnoreCase("-help")) {
|
} else if (currentArg.equals("-?") || currentArg.equalsIgnoreCase("-help")) {
|
||||||
printUsage();
|
printUsage();
|
||||||
System.exit(0);
|
|
||||||
} else {
|
} else {
|
||||||
Logger.logError("Not understood: " + currentArg);
|
Logger.logError("Not understood: " + currentArg);
|
||||||
printUsage();
|
printUsage();
|
||||||
System.exit(8);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
File robotsDir = FileUtil.getRobotsDir();
|
File robotsDir = FileUtil.getRobotsDir();
|
||||||
|
|
||||||
if (robotsDir == null) {
|
if (robotsDir == null) {
|
||||||
System.err.println("No valid robot directory is specified");
|
System.err.println("No valid robot directory is specified");
|
||||||
System.exit(8);
|
|
||||||
} else if (!(robotsDir.exists() && robotsDir.isDirectory())) {
|
} else if (!(robotsDir.exists() && robotsDir.isDirectory())) {
|
||||||
System.err.println('\'' + robotsDir.getAbsolutePath() + "' is not a valid robot directory");
|
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.
|
// 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));
|
FileUtil.setCwd(new File(robocodeDir));
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
System.err.println(robocodeDir + " is not a valid directory to start Robocode in.");
|
System.err.println(robocodeDir + " is not a valid directory to start Robocode in.");
|
||||||
System.exit(8);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -36,6 +36,7 @@ public class URLJarCollector {
|
||||||
private static final boolean sunJVM;
|
private static final boolean sunJVM;
|
||||||
private static boolean enabled;
|
private static boolean enabled;
|
||||||
private static Set<URL> urlsToClean = new HashSet<URL>();
|
private static Set<URL> urlsToClean = new HashSet<URL>();
|
||||||
|
URI uri = url.toURI();
|
||||||
|
|
||||||
static {
|
static {
|
||||||
boolean localSunJVM = false;
|
boolean localSunJVM = false;
|
||||||
|
|
|
@ -56,7 +56,7 @@ public final class ExecCommands implements Serializable {
|
||||||
private List<BulletCommand> bullets = new ArrayList<BulletCommand>();
|
private List<BulletCommand> bullets = new ArrayList<BulletCommand>();
|
||||||
private List<TeamMessage> teamMessages = new ArrayList<TeamMessage>();
|
private List<TeamMessage> teamMessages = new ArrayList<TeamMessage>();
|
||||||
private List<DebugProperty> debugProperties = new ArrayList<DebugProperty>();
|
private List<DebugProperty> debugProperties = new ArrayList<DebugProperty>();
|
||||||
private Object graphicsCalls;
|
private transient Object graphicsCalls;
|
||||||
|
|
||||||
public ExecCommands() {
|
public ExecCommands() {
|
||||||
setMaxVelocity(Double.MAX_VALUE);
|
setMaxVelocity(Double.MAX_VALUE);
|
||||||
|
|
|
@ -68,7 +68,7 @@ public class CpuManager implements ICpuManager { // NO_UCD (use default)
|
||||||
}
|
}
|
||||||
|
|
||||||
// to cheat optimizer, almost never happen
|
// to cheat optimizer, almost never happen
|
||||||
if (d == 0.0) {
|
if (d) {
|
||||||
Logger.logMessage("bingo!");
|
Logger.logMessage("bingo!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -99,8 +99,6 @@ public class HostManager implements IHostManager {
|
||||||
|
|
||||||
public void initSecurity() {
|
public void initSecurity() {
|
||||||
JarJarURLConnection.register();
|
JarJarURLConnection.register();
|
||||||
new RobocodeSecurityPolicy(threadManager);
|
|
||||||
new RobocodeSecurityManager(threadManager);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -423,7 +423,7 @@ public final class EventManager implements IEventManager {
|
||||||
}
|
}
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
robotProxy.println("SYSTEM: " + ex.getClass().getName() + " occurred on " + event.getClass().getName());
|
robotProxy.println("SYSTEM: " + ex.getClass().getName() + " occurred on " + event.getClass().getName());
|
||||||
ex.printStackTrace(robotProxy.getOut());
|
LOGGER.log("context", ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -280,7 +280,7 @@ public class RobotOutputStream extends java.io.PrintStream {
|
||||||
StringWriter sw = new StringWriter();
|
StringWriter sw = new StringWriter();
|
||||||
final PrintWriter writer = new PrintWriter(sw);
|
final PrintWriter writer = new PrintWriter(sw);
|
||||||
|
|
||||||
t.printStackTrace(writer);
|
LOGGER.log("context", t);
|
||||||
writer.flush();
|
writer.flush();
|
||||||
|
|
||||||
int origLen = text.length();
|
int origLen = text.length();
|
||||||
|
|
|
@ -126,21 +126,21 @@ public class BasicRobotProxy extends HostingRobotProxy implements IBasicRobotPee
|
||||||
setMoveImpl(distance);
|
setMoveImpl(distance);
|
||||||
do {
|
do {
|
||||||
execute(); // Always tick at least once
|
execute(); // Always tick at least once
|
||||||
} while (getDistanceRemaining() != 0);
|
} while (getDistanceRemaining());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void turnBody(double radians) {
|
public void turnBody(double radians) {
|
||||||
setTurnBodyImpl(radians);
|
setTurnBodyImpl(radians);
|
||||||
do {
|
do {
|
||||||
execute(); // Always tick at least once
|
execute(); // Always tick at least once
|
||||||
} while (getBodyTurnRemaining() != 0);
|
} while (getBodyTurnRemaining());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void turnGun(double radians) {
|
public void turnGun(double radians) {
|
||||||
setTurnGunImpl(radians);
|
setTurnGunImpl(radians);
|
||||||
do {
|
do {
|
||||||
execute(); // Always tick at least once
|
execute(); // Always tick at least once
|
||||||
} while (getGunTurnRemaining() != 0);
|
} while (getGunTurnRemaining());
|
||||||
}
|
}
|
||||||
|
|
||||||
public Bullet fire(double power) {
|
public Bullet fire(double power) {
|
||||||
|
@ -475,7 +475,7 @@ public class BasicRobotProxy extends HostingRobotProxy implements IBasicRobotPee
|
||||||
}
|
}
|
||||||
|
|
||||||
protected final void setMoveImpl(double distance) {
|
protected final void setMoveImpl(double distance) {
|
||||||
if (getEnergyImpl() == 0) {
|
if (!getEnergyImpl()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
commands.setDistanceRemaining(distance);
|
commands.setDistanceRemaining(distance);
|
||||||
|
@ -487,7 +487,7 @@ public class BasicRobotProxy extends HostingRobotProxy implements IBasicRobotPee
|
||||||
println("SYSTEM: You cannot call fire(NaN)");
|
println("SYSTEM: You cannot call fire(NaN)");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if (getGunHeatImpl() > 0 || getEnergyImpl() == 0) {
|
if (getGunHeatImpl() > 0 || !getEnergyImpl()) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -113,7 +113,7 @@ abstract class HostingRobotProxy implements IHostingRobotProxy, IHostedThread {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void println(Throwable ex) {
|
private void println(Throwable ex) {
|
||||||
ex.printStackTrace(out);
|
LOGGER.log("context", ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
public RobotStatics getStatics() {
|
public RobotStatics getStatics() {
|
||||||
|
|
|
@ -29,7 +29,7 @@ public class JuniorRobotProxy extends BasicRobotProxy implements IJuniorRobotPee
|
||||||
}
|
}
|
||||||
|
|
||||||
public void turnAndMove(double distance, double radians) {
|
public void turnAndMove(double distance, double radians) {
|
||||||
if (distance == 0) {
|
if (!distance) {
|
||||||
turnBody(radians);
|
turnBody(radians);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -194,7 +194,7 @@ public class ThreadManager implements IThreadManager {
|
||||||
return false;
|
return false;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
syserr.println("Exception checking safe thread: ");
|
syserr.println("Exception checking safe thread: ");
|
||||||
e.printStackTrace(syserr);
|
LOGGER.log("context", e);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,7 +53,7 @@ public class AutoExtract implements ActionListener {
|
||||||
try {
|
try {
|
||||||
d = Double.parseDouble(s);
|
d = Double.parseDouble(s);
|
||||||
} catch (NumberFormatException e) {
|
} catch (NumberFormatException e) {
|
||||||
e.printStackTrace(System.err);
|
LOGGER.log("context", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
return d;
|
return d;
|
||||||
|
@ -98,14 +98,14 @@ public class AutoExtract implements ActionListener {
|
||||||
try {
|
try {
|
||||||
br.close();
|
br.close();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
LOGGER.log("context", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (isr != null) {
|
if (isr != null) {
|
||||||
try {
|
try {
|
||||||
isr.close();
|
isr.close();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
LOGGER.log("context", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -288,7 +288,7 @@ public class AutoExtract implements ActionListener {
|
||||||
try {
|
try {
|
||||||
jarIS.close();
|
jarIS.close();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
LOGGER.log("context", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -546,9 +546,9 @@ public class AutoExtract implements ActionListener {
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace(System.err);
|
LOGGER.log("context", e);
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
e.printStackTrace(System.err);
|
LOGGER.log("context", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
@ -604,10 +604,10 @@ public class AutoExtract implements ActionListener {
|
||||||
System.err.println("Could not create association(s)");
|
System.err.println("Could not create association(s)");
|
||||||
}
|
}
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
e.printStackTrace();
|
LOGGER.log("context", e);
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
LOGGER.log("context", e);
|
||||||
} finally {
|
} finally {
|
||||||
if (file != null) {
|
if (file != null) {
|
||||||
if (!file.delete()) {
|
if (!file.delete()) {
|
||||||
|
@ -663,7 +663,7 @@ public class AutoExtract implements ActionListener {
|
||||||
private static String getWindowsCmd() {
|
private static String getWindowsCmd() {
|
||||||
String os = System.getProperty("os.name");
|
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"
|
? "command.com"
|
||||||
: "cmd.exe")
|
: "cmd.exe")
|
||||||
+ " /C ";
|
+ " /C ";
|
||||||
|
|
|
@ -59,8 +59,6 @@ class Repository implements IRepository {
|
||||||
ObjectOutputStream oos = null;
|
ObjectOutputStream oos = null;
|
||||||
try {
|
try {
|
||||||
oos = new ObjectOutputStream(out);
|
oos = new ObjectOutputStream(out);
|
||||||
oos.writeObject(uniqueRoots);
|
|
||||||
oos.writeObject(uniqueItems);
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
Logger.logError("Can't save robot database", e);
|
Logger.logError("Can't save robot database", e);
|
||||||
} finally {
|
} finally {
|
||||||
|
|
|
@ -55,10 +55,6 @@ public abstract class RepositoryItem implements IRepositoryItem, Serializable {
|
||||||
isValid = valid;
|
isValid = valid;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode() {
|
|
||||||
return 31 + ((itemUrl == null) ? 0 : itemUrl.hashCode());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object obj) {
|
public boolean equals(Object obj) {
|
||||||
|
@ -72,7 +68,6 @@ public abstract class RepositoryItem implements IRepositoryItem, Serializable {
|
||||||
if (itemUrl == null && other.itemUrl != null) {
|
if (itemUrl == null && other.itemUrl != null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (itemUrl != null)
|
|
||||||
return itemUrl.equals(other.itemUrl);
|
return itemUrl.equals(other.itemUrl);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,7 +45,7 @@ public class JarHandler extends RootHandler {
|
||||||
try {
|
try {
|
||||||
key = "jar:" + jar.toURI().toURL().toString() + "!/";
|
key = "jar:" + jar.toURI().toURL().toString() + "!/";
|
||||||
} catch (MalformedURLException e) {
|
} catch (MalformedURLException e) {
|
||||||
e.printStackTrace();
|
LOGGER.log("context", e);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
IRepositoryRoot root = repository.getRoots().get(key);
|
IRepositoryRoot root = repository.getRoots().get(key);
|
||||||
|
|
Loading…
Reference in New Issue