summaryrefslogtreecommitdiffstats
path: root/src/main/java
diff options
context:
space:
mode:
authorNathan Adams <dinnerbone@dinnerbone.com>2011-10-26 06:56:36 +0100
committerNathan Adams <dinnerbone@dinnerbone.com>2011-10-26 06:56:36 +0100
commitbfa45985c524ee79cc672531682ebee0664cacea (patch)
tree59d8d5bd8359d07dfcd64f541f815daae6b54aeb /src/main/java
parenteefcef54802c2313bbd2123d88f3ffa469622635 (diff)
downloadbukkit-bfa45985c524ee79cc672531682ebee0664cacea.tar
bukkit-bfa45985c524ee79cc672531682ebee0664cacea.tar.gz
bukkit-bfa45985c524ee79cc672531682ebee0664cacea.tar.lz
bukkit-bfa45985c524ee79cc672531682ebee0664cacea.tar.xz
bukkit-bfa45985c524ee79cc672531682ebee0664cacea.zip
Fixed issues with loading YamlConfigurations with typed keys
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/org/bukkit/configuration/file/YamlConfiguration.java30
1 files changed, 18 insertions, 12 deletions
diff --git a/src/main/java/org/bukkit/configuration/file/YamlConfiguration.java b/src/main/java/org/bukkit/configuration/file/YamlConfiguration.java
index f9523b39..aaf8ce7f 100644
--- a/src/main/java/org/bukkit/configuration/file/YamlConfiguration.java
+++ b/src/main/java/org/bukkit/configuration/file/YamlConfiguration.java
@@ -4,6 +4,7 @@ import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
+import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.logging.Level;
@@ -55,11 +56,14 @@ public class YamlConfiguration extends FileConfiguration {
throw new IllegalArgumentException("Contents cannot be null");
}
- Map<String, Object> input;
- try {
- input = (Map<String, Object>)yaml.load(contents);
- } catch (Throwable ex) {
- throw new InvalidConfigurationException("Specified contents is not a valid Configuration", ex);
+ Map<Object, Object> input = (Map<Object, Object>)yaml.load(contents);
+ int size = (input == null) ? 0 : input.size();
+ Map<String, Object> result = new LinkedHashMap<String, Object>(size);
+
+ if (size > 0) {
+ for (Map.Entry<Object, Object> entry : input.entrySet()) {
+ result.put(entry.getKey().toString(), entry.getValue());
+ }
}
String header = parseHeader(contents);
@@ -68,7 +72,7 @@ public class YamlConfiguration extends FileConfiguration {
options().header(header);
}
- deserializeValues(input, this);
+ deserializeValues(result, this);
}
protected void deserializeValues(Map<String, Object> input, ConfigurationSection section) throws InvalidConfigurationException {
@@ -80,12 +84,14 @@ public class YamlConfiguration extends FileConfiguration {
Object value = entry.getValue();
if (value instanceof Map) {
- Map<String, Object> subvalues;
-
- try {
- subvalues = (Map<String, Object>) value;
- } catch (ClassCastException ex) {
- throw new InvalidConfigurationException("Map found where type is not <String, Object>", ex);
+ Map<Object, Object> subinput = (Map<Object, Object>)value;
+ int size = (subinput == null) ? 0 : subinput.size();
+ Map<String, Object> subvalues = new LinkedHashMap<String, Object>(size);
+
+ if (size > 0) {
+ for (Map.Entry<Object, Object> subentry : subinput.entrySet()) {
+ subvalues.put(subentry.getKey().toString(), subentry.getValue());
+ }
}
if (subvalues.containsKey(ConfigurationSerialization.SERIALIZED_TYPE_KEY)) {