diff options
author | Edmond Poon <sagaciouszzzz@gmail.com> | 2013-03-18 23:32:10 -0600 |
---|---|---|
committer | Nate Mortensen <nate.richard.mortensen@gmail.com> | 2013-03-18 23:40:10 -0600 |
commit | e639690e45cc1eeb2d7ad709ddebe67301da35ab (patch) | |
tree | bbe707869281a027a9e0034182bc13f02253ac28 /src/main | |
parent | abee2151eaf79f908e94e5dabd85fcdf9c1c49e7 (diff) | |
download | craftbukkit-e639690e45cc1eeb2d7ad709ddebe67301da35ab.tar craftbukkit-e639690e45cc1eeb2d7ad709ddebe67301da35ab.tar.gz craftbukkit-e639690e45cc1eeb2d7ad709ddebe67301da35ab.tar.lz craftbukkit-e639690e45cc1eeb2d7ad709ddebe67301da35ab.tar.xz craftbukkit-e639690e45cc1eeb2d7ad709ddebe67301da35ab.zip |
Validate Server method input. Addresses BUKKIT-3687
CraftServer methods that implement the Server interface will throw an
IllegalArgumentException if a method cannot operate on a null input
and given a null pointer.
This causes methods to fail early and identify that a plugin is
responsible for passing in an invalid argument. This will only
change the exception thrown, if there originally was a thrown
exception. This helps with hunting down legitimate problems
with CraftBukkit.
Diffstat (limited to 'src/main')
-rw-r--r-- | src/main/java/org/bukkit/craftbukkit/CraftServer.java | 29 |
1 files changed, 23 insertions, 6 deletions
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java index 37750226..6b3b9fec 100644 --- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java +++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java @@ -320,6 +320,8 @@ public final class CraftServer implements Server { } public Player getPlayer(final String name) { + Validate.notNull(name, "Name cannot be null"); + Player[] players = getOnlinePlayers(); Player found = null; @@ -339,6 +341,8 @@ public final class CraftServer implements Server { } public Player getPlayerExact(String name) { + Validate.notNull(name, "Name cannot be null"); + String lname = name.toLowerCase(); for (Player player : getOnlinePlayers()) { @@ -359,6 +363,8 @@ public final class CraftServer implements Server { } public List<Player> matchPlayer(String partialName) { + Validate.notNull(partialName, "PartialName cannot be null"); + List<Player> matchedPlayers = new ArrayList<Player>(); for (Player iterPlayer : this.getOnlinePlayers()) { @@ -511,6 +517,9 @@ public final class CraftServer implements Server { } public boolean dispatchCommand(CommandSender sender, String commandLine) { + Validate.notNull(sender, "Sender cannot be null"); + Validate.notNull(commandLine, "CommandLine cannot be null"); + if (commandMap.dispatch(sender, commandLine)) { return true; } @@ -665,9 +674,7 @@ public final class CraftServer implements Server { } public World createWorld(WorldCreator creator) { - if (creator == null) { - throw new IllegalArgumentException("Creator may not be null"); - } + Validate.notNull(creator, "Creator may not be null"); String name = creator.name(); ChunkGenerator generator = creator.generator(); @@ -808,6 +815,8 @@ public final class CraftServer implements Server { } public World getWorld(String name) { + Validate.notNull(name, "Name cannot be null"); + return worlds.get(name.toLowerCase()); } @@ -852,6 +861,8 @@ public final class CraftServer implements Server { } public void configureDbConfig(ServerConfig config) { + Validate.notNull(config, "Config cannot be null"); + DataSourceConfig ds = new DataSourceConfig(); ds.setDriver(configuration.getString("database.driver")); ds.setUrl(configuration.getString("database.url")); @@ -888,6 +899,8 @@ public final class CraftServer implements Server { } public List<Recipe> getRecipesFor(ItemStack result) { + Validate.notNull(result, "Result cannot be null"); + List<Recipe> results = new ArrayList<Recipe>(); Iterator<Recipe> iter = recipeIterator(); while (iter.hasNext()) { @@ -1015,6 +1028,8 @@ public final class CraftServer implements Server { } public CraftMapView createMap(World world) { + Validate.notNull(world, "World cannot be null"); + net.minecraft.server.ItemStack stack = new net.minecraft.server.ItemStack(Item.MAP, 1, -1); WorldMap worldmap = Item.MAP.getSavedMap(stack, ((CraftWorld) world).getHandle()); return worldmap.mapView; @@ -1044,6 +1059,8 @@ public final class CraftServer implements Server { } public OfflinePlayer getOfflinePlayer(String name, boolean search) { + Validate.notNull(name, "Name cannot be null"); + OfflinePlayer result = getPlayerExact(name); String lname = name.toLowerCase(); @@ -1078,6 +1095,8 @@ public final class CraftServer implements Server { } public void banIP(String address) { + Validate.notNull(address, "Address cannot be null."); + BanEntry entry = new BanEntry(address); playerList.getIPBans().add(entry); playerList.getIPBans().save(); @@ -1135,9 +1154,7 @@ public final class CraftServer implements Server { } public void setDefaultGameMode(GameMode mode) { - if (mode == null) { - throw new IllegalArgumentException("Mode cannot be null"); - } + Validate.notNull(mode, "Mode cannot be null"); for (World world : getWorlds()) { ((CraftWorld) world).getHandle().worldData.setGameType(EnumGamemode.a(mode.getValue())); |