[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:
Bukkit/Spigot
2012-02-29 08:32:25 -06:00
parent e7c9a43100
commit 5906da7948
14 changed files with 174 additions and 183 deletions

View File

@@ -42,16 +42,15 @@ public class YamlConfiguration extends FileConfiguration {
return header + dump;
}
@SuppressWarnings("unchecked")
@Override
public void loadFromString(String contents) throws InvalidConfigurationException {
if (contents == null) {
throw new IllegalArgumentException("Contents cannot be null");
}
Map<Object, Object> input;
Map<?, ?> input;
try {
input = (Map<Object, Object>) yaml.load(contents);
input = (Map<?, ?>) yaml.load(contents);
} catch (YAMLException e) {
throw new InvalidConfigurationException(e);
} catch (ClassCastException e) {
@@ -68,14 +67,13 @@ public class YamlConfiguration extends FileConfiguration {
}
}
@SuppressWarnings("unchecked")
protected void convertMapsToSections(Map<Object, Object> input, ConfigurationSection section) {
for (Map.Entry<Object, Object> entry : input.entrySet()) {
protected void convertMapsToSections(Map<?, ?> input, ConfigurationSection section) {
for (Map.Entry<?, ?> entry : input.entrySet()) {
String key = entry.getKey().toString();
Object value = entry.getValue();
if (value instanceof Map<?, ?>) {
convertMapsToSections((Map<Object, Object>) value, section.createSection(key));
if (value instanceof Map) {
convertMapsToSections((Map<?, ?>) value, section.createSection(key));
} else {
section.set(key, value);
}

View File

@@ -23,12 +23,11 @@ public class YamlConstructor extends SafeConstructor {
throw new YAMLException("Unexpected referential mapping structure. Node: " + node);
}
@SuppressWarnings("unchecked")
Map<Object, Object> raw = (Map<Object, Object>) super.construct(node);
Map<?, ?> raw = (Map<?, ?>) super.construct(node);
if (raw.containsKey(ConfigurationSerialization.SERIALIZED_TYPE_KEY)) {
Map<String, Object> typed = new LinkedHashMap<String, Object>(raw.size());
for (Map.Entry<Object, Object> entry : raw.entrySet()) {
for (Map.Entry<?, ?> entry : raw.entrySet()) {
typed.put(entry.getKey().toString(), entry.getValue());
}