diff options
author | Wesley Wolfe <weswolf@aol.com> | 2013-02-03 04:08:10 -0600 |
---|---|---|
committer | Wesley Wolfe <weswolf@aol.com> | 2013-02-03 04:08:10 -0600 |
commit | 76e82dddd95cd020b55ccd0661e7d2bf49b5ed6e (patch) | |
tree | f1a089a32c1e462fbcac781e2ab40b7bb9f202bf /src/main | |
parent | 81555c0c25c0156239ecc59c02e98d4152ae1664 (diff) | |
download | bukkit-76e82dddd95cd020b55ccd0661e7d2bf49b5ed6e.tar bukkit-76e82dddd95cd020b55ccd0661e7d2bf49b5ed6e.tar.gz bukkit-76e82dddd95cd020b55ccd0661e7d2bf49b5ed6e.tar.lz bukkit-76e82dddd95cd020b55ccd0661e7d2bf49b5ed6e.tar.xz bukkit-76e82dddd95cd020b55ccd0661e7d2bf49b5ed6e.zip |
Fix ClassCastException for malformed plugin.yml. Fixes BUKKIT-3563
If the plugin.yml gets loaded but wasn't in the form of a map, the
server would crash. This safely checks to see if it can be cast,
throwing invalid description if it cannot.
Diffstat (limited to 'src/main')
-rw-r--r-- | src/main/java/org/bukkit/plugin/PluginDescriptionFile.java | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/src/main/java/org/bukkit/plugin/PluginDescriptionFile.java b/src/main/java/org/bukkit/plugin/PluginDescriptionFile.java index 3975f38d..3a5f4e00 100644 --- a/src/main/java/org/bukkit/plugin/PluginDescriptionFile.java +++ b/src/main/java/org/bukkit/plugin/PluginDescriptionFile.java @@ -39,7 +39,7 @@ public final class PluginDescriptionFile { private PermissionDefault defaultPerm = PermissionDefault.OP; public PluginDescriptionFile(final InputStream stream) throws InvalidDescriptionException { - loadMap((Map<?, ?>) yaml.load(stream)); + loadMap(asMap(yaml.load(stream))); } /** @@ -49,7 +49,7 @@ public final class PluginDescriptionFile { * @throws InvalidDescriptionException If the PluginDescriptionFile is invalid */ public PluginDescriptionFile(final Reader reader) throws InvalidDescriptionException { - loadMap((Map<?, ?>) yaml.load(reader)); + loadMap(asMap(yaml.load(reader))); } /** @@ -400,4 +400,11 @@ public final class PluginDescriptionFile { return map; } + + private Map<?,?> asMap(Object object) throws InvalidDescriptionException { + if (object instanceof Map) { + return (Map<?,?>) object; + } + throw new InvalidDescriptionException(object + " is not properly structured."); + } } |