YAML Configurate java.nio.charset.MalformedInputException: Input length = 1

Using my custom module system I’m trying to load a yaml file that could either be on an http server or in the config directory (if the url is an empty string).

Here is the module load function excluding the part after the yaml file has been loaded. ConfigurationNode config is a node within the main config file (hocon).

@Override
protected void load(ConfigurationNode config) {
    YAMLConfigurationLoader.Builder builder;
    try {
        String urlString = config.getNode("url").getString();
        
        if (urlString.isEmpty()) {
            File configFile = new File(plugin.getConfigDirectory().toFile(), "rules.yml");
            builder = YAMLConfigurationLoader.builder().setFile(configFile);
        } else {
            builder = YAMLConfigurationLoader.builder().setURL(new URL(urlString));
        }
    } catch (MalformedURLException ex) {
        throw new ModuleLoadingException(RulesModule.class, config, ex);
    }
    
    YAMLConfigurationLoader loader = builder
            .setDefaultOptions(ConfigurationOptions.defaults().setMapFactory(MapFactories.<ConfigurationNode>insertionOrdered()))
            .build();
    ConfigurationNode rulesConf;
    try {
        rulesConf = loader.load();
    } catch (IOException ex) {
        throw new ModuleLoadingException(RulesModule.class, config, ex);
    }
    
    // Redacted
}

Here is the error message that has been thrown by loader.load(), caught, and rethrown within a ModuleLoadingException.

[17:47:26 ERROR] [Sponge]: Could not pass GameStartedServerEvent$Impl to Plugin{id=zephyr-core, name=ZephyrRealms Core, version=1.0, description=ZephyrRealms Core, source=mods\ZephyrCore-1.0-SNAPSHOT.jar}
me.zephlon.core.api.exceptions.ModuleLoadingException: Could not load module RulesModule
        at me.zephlon.core.plugin.rules.RulesModule.load(RulesModule.java:71) ~[RulesModule.class:?]
        at me.zephlon.core.api.ZPlugin.loadModule(ZPlugin.java:174) ~[ZPlugin.class:?]
        at me.zephlon.core.api.ZPlugin.loadModule(ZPlugin.java:166) ~[ZPlugin.class:?]
        at me.zephlon.core.api.ZPlugin.loadModule(ZPlugin.java:162) ~[ZPlugin.class:?]
        at me.zephlon.core.plugin.ZephyrCore.onServerStart(ZephyrCore.java:62) ~[ZephyrCore.class:?]
        at org.spongepowered.common.event.listener.GameStartedServerEventListener_ZephyrCore_onServerStart12.handle(Unknown Source) ~[?:?]
        at org.spongepowered.common.event.RegisteredListener.handle(RegisteredListener.java:95) ~[RegisteredListener.class:1.10.2-5.1.0-BETA-355]
        at org.spongepowered.common.event.SpongeEventManager.post(SpongeEventManager.java:305) [SpongeEventManager.class:1.10.2-5.1.0-BETA-355]
        at org.spongepowered.common.event.SpongeEventManager.post(SpongeEventManager.java:320) [SpongeEventManager.class:1.10.2-5.1.0-BETA-355]
        at org.spongepowered.common.event.SpongeEventManager.post(SpongeEventManager.java:324) [SpongeEventManager.class:1.10.2-5.1.0-BETA-355]
        at org.spongepowered.common.SpongeImpl.postState(SpongeImpl.java:196) [SpongeImpl.class:1.10.2-5.1.0-BETA-355]
        at org.spongepowered.server.SpongeVanilla.onServerStarting(SpongeVanilla.java:217) [SpongeVanilla.class:1.10.2-5.1.0-BETA-355]
        at net.minecraft.server.dedicated.DedicatedServer.handler$callServerStarting$znb000(SourceFile:85) [ld.class:?]
        at net.minecraft.server.dedicated.DedicatedServer.func_71197_b(SourceFile:228) [ld.class:?]
        at net.minecraft.server.MinecraftServer.run(SourceFile:428) [MinecraftServer.class:?]
        at java.lang.Thread.run(Unknown Source) [?:1.8.0_101]
Caused by: java.nio.charset.MalformedInputException: Input length = 1
        at java.nio.charset.CoderResult.throwException(Unknown Source) ~[?:1.8.0_101]
        at sun.nio.cs.StreamDecoder.implRead(Unknown Source) ~[?:1.8.0_101]
        at sun.nio.cs.StreamDecoder.read(Unknown Source) ~[?:1.8.0_101]
        at java.io.InputStreamReader.read(Unknown Source) ~[?:1.8.0_101]
        at java.io.BufferedReader.fill(Unknown Source) ~[?:1.8.0_101]
        at java.io.BufferedReader.readLine(Unknown Source) ~[?:1.8.0_101]
        at java.io.BufferedReader.readLine(Unknown Source) ~[?:1.8.0_101]
        at ninja.leaping.configurate.loader.CommentHandlers.extractHeader(CommentHandlers.java:124) ~[spongevanilla-1.10.2-5.1.0-BETA-355.jar:1.10.2-5.1.0-BETA-355]
        at ninja.leaping.configurate.loader.CommentHandlers.extractComment(CommentHandlers.java:160) ~[spongevanilla-1.10.2-5.1.0-BETA-355.jar:1.10.2-5.1.0-BETA-355]
        at ninja.leaping.configurate.loader.AbstractConfigurationLoader.load(AbstractConfigurationLoader.java:157) ~[spongevanilla-1.10.2-5.1.0-BETA-355.jar:1.10.2-5.1.0-BETA-355]
        at ninja.leaping.configurate.loader.ConfigurationLoader.load(ConfigurationLoader.java:42) ~[spongevanilla-1.10.2-5.1.0-BETA-355.jar:1.10.2-5.1.0-BETA-355]
        at me.zephlon.core.plugin.rules.RulesModule.load(RulesModule.java:69) ~[RulesModule.class:?]
        ... 15 more

Does anyone know how to fix this?

Oh, wow. I don’t know why I didn’t think of this before. The rules.yml file contained a bullet “•” character. I replaced this with a dash, and the error message is gone.

I’ll leave this thread here for anyone who gets a similar error message in the future.

2 Likes