[Bleeding] Cleaned up unsafe casts. Addresses BUKKIT-844
Removed internal collection leaks from PluginDescriptionFile BREAKING: PluginDescriptionFile.getAuthors() now returns List instead of ArrayList Various places with unsafe generics, notably List<Object> getList() in Configurations are now referenced as <?>. This is nonbreaking, but sourcecode will need to be revised when compiled. By: Wesley Wolfe <weswolf@aol.com>
This commit is contained in:
@@ -6,6 +6,8 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
|
||||
@@ -204,12 +206,12 @@ public class Permission {
|
||||
* @param def Default permission value to use if missing
|
||||
* @return Permission object
|
||||
*/
|
||||
public static List<Permission> loadPermissions(Map<String, Map<String, Object>> data, String error, PermissionDefault def) {
|
||||
public static List<Permission> loadPermissions(Map<?, ?> data, String error, PermissionDefault def) {
|
||||
List<Permission> result = new ArrayList<Permission>();
|
||||
|
||||
for (Map.Entry<String, Map<String, Object>> entry : data.entrySet()) {
|
||||
for (Map.Entry<?, ?> entry : data.entrySet()) {
|
||||
try {
|
||||
result.add(Permission.loadPermission(entry.getKey(), entry.getValue(), def, result));
|
||||
result.add(Permission.loadPermission(entry.getKey().toString(), (Map<?, ?>) entry.getValue(), def, result));
|
||||
} catch (Throwable ex) {
|
||||
Bukkit.getServer().getLogger().log(Level.SEVERE, String.format(error, entry.getKey()), ex);
|
||||
}
|
||||
@@ -248,13 +250,10 @@ public class Permission {
|
||||
* @param output A list to append any created child-Permissions to, may be null
|
||||
* @return Permission object
|
||||
*/
|
||||
public static Permission loadPermission(String name, Map<String, Object> data, PermissionDefault def, List<Permission> output) {
|
||||
if (name == null) {
|
||||
throw new IllegalArgumentException("Name cannot be null");
|
||||
}
|
||||
if (data == null) {
|
||||
throw new IllegalArgumentException("Data cannot be null");
|
||||
}
|
||||
public static Permission loadPermission(String name, Map<?, ?> data, PermissionDefault def, List<Permission> output) {
|
||||
Validate.notNull(name, "Name cannot be null");
|
||||
Validate.notNull(data, "Data cannot be null");
|
||||
|
||||
String desc = null;
|
||||
Map<String, Boolean> children = null;
|
||||
|
||||
@@ -280,11 +279,7 @@ public class Permission {
|
||||
}
|
||||
|
||||
if (data.containsKey("description")) {
|
||||
try {
|
||||
desc = (String) data.get("description");
|
||||
} catch (ClassCastException ex) {
|
||||
throw new IllegalArgumentException("'description' key is of wrong type", ex);
|
||||
}
|
||||
desc = data.get("description").toString();
|
||||
}
|
||||
|
||||
Permission result = new Permission(name, desc, def, children);
|
||||
@@ -304,31 +299,30 @@ public class Permission {
|
||||
return result;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private static Map<String, Boolean> extractChildren(Map<String, Object> data, String name, PermissionDefault def, List<Permission> output) {
|
||||
Map<String, Object> input = (Map<String, Object>) data.get("children");
|
||||
private static Map<String, Boolean> extractChildren(Map<?, ?> data, String name, PermissionDefault def, List<Permission> output) {
|
||||
Map<?, ?> input = (Map<?, ?>) data.get("children");
|
||||
Map<String, Boolean> children = new LinkedHashMap<String, Boolean>();
|
||||
|
||||
for (Map.Entry<String, Object> entry : input.entrySet()) {
|
||||
for (Map.Entry<?, ?> entry : input.entrySet()) {
|
||||
if ((entry.getValue() instanceof Boolean)) {
|
||||
children.put(entry.getKey(), (Boolean) entry.getValue());
|
||||
children.put(entry.getKey().toString(), (Boolean) entry.getValue());
|
||||
} else if ((entry.getValue() instanceof Map)) {
|
||||
try {
|
||||
try {
|
||||
Permission perm = loadPermission((String) entry.getKey(), (Map<String, Object>) entry.getValue(), def, output);
|
||||
Permission perm = loadPermission(entry.getKey().toString(), (Map<?, ?>) entry.getValue(), def, output);
|
||||
children.put(perm.getName(), Boolean.valueOf(true));
|
||||
|
||||
if (output != null) {
|
||||
output.add(perm);
|
||||
}
|
||||
} catch (Throwable ex) {
|
||||
Bukkit.getServer().getLogger().log(Level.SEVERE, "Permission node '" + (String) entry.getKey() + "' in child of " + name + " is invalid", ex);
|
||||
Bukkit.getServer().getLogger().log(Level.SEVERE, "Permission node '" + entry.getKey().toString() + "' in child of " + name + " is invalid", ex);
|
||||
}
|
||||
} catch (ClassCastException ex) {
|
||||
throw new IllegalArgumentException("Child '" + (String) entry.getKey() + "' contains invalid map type");
|
||||
throw new IllegalArgumentException("Child '" + entry.getKey().toString() + "' contains invalid map type");
|
||||
}
|
||||
} else {
|
||||
throw new IllegalArgumentException("Child '" + (String) entry.getKey() + "' contains invalid value");
|
||||
throw new IllegalArgumentException("Child '" + entry.getKey().toString() + "' contains invalid value");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user