java.lang.IllegalArgumentException:边界必须为正(java.util.concurrent.ThreadLocalRandom.nextInt(未知来源)~[?:1.8.0_301])

java.lang.IllegalArgumentException: bound must be positive(java.util.concurrent.ThreadLocalRandom.nextInt(Unknown Source) ~[?:1.8.0_301])

收到一条错误消息,指出我的界限必须为正。错误来自这一行 :
return mapNames[ThreadLocalRandom.current().nextInt(mapNames.length)];

我设置mapNames的地方在这里:
String[] mapNames = mapsConfiguration.getKeys(false).toArray(new String[]{});

我设置mapsConfiguration的地方在这里:
private ConfigurationSection mapsConfiguration;

这是我的方法 :

public String randomMapName()
{
    String[] mapNames = mapsConfiguration.getKeys(false).toArray(new String[]{});
    return mapNames[ThreadLocalRandom.current().nextInt(mapNames.length)];
}

我得到这个堆栈跟踪 :

        java.lang.IllegalArgumentException: bound must be positive
        at java.util.concurrent.ThreadLocalRandom.nextInt(Unknown Source) ~[?:1.8.0_301]
        at com.proboxinjet.ashguardall.minigame.bedwars.config.ConfigurationManager.randomMapName(ConfigurationManager.java:47) ~[?:?]
        at com.proboxinjet.ashguardall.minigame.bedwars.gamemanager.GameManager.<init>(GameManager.java:37) ~[?:?]
        at com.proboxinjet.ashguardall.AshGuardAll.onEnable(AshGuardAll.java:23) ~[?:?]
        at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:263) ~[spigot.jar:3096-Spigot-9fb885e-296df56]
        at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:342) ~[spigot.jar:3096-Spigot-9fb885e-296df56]
        at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:480) ~[spigot.jar:3096-Spigot-9fb885e-296df56]
        at org.bukkit.craftbukkit.v1_16_R3.CraftServer.enablePlugin(CraftServer.java:492) ~[spigot.jar:3096-Spigot-9fb885e-296df56]
        at org.bukkit.craftbukkit.v1_16_R3.CraftServer.enablePlugins(CraftServer.java:406) ~[spigot.jar:3096-Spigot-9fb885e-296df56]
        at net.minecraft.server.v1_16_R3.MinecraftServer.loadWorld(MinecraftServer.java:554) ~[spigot.jar:3096-Spigot-9fb885e-296df56]
        at net.minecraft.server.v1_16_R3.DedicatedServer.init(DedicatedServer.java:257) ~[spigot.jar:3096-Spigot-9fb885e-296df56]
        at net.minecraft.server.v1_16_R3.MinecraftServer.w(MinecraftServer.java:928) ~[spigot.jar:3096-Spigot-9fb885e-296df56]
        at net.minecraft.server.v1_16_R3.MinecraftServer.lambda[=14=](MinecraftServer.java:273) ~[spigot.jar:3096-Spigot-9fb885e-296df56]
        at java.lang.Thread.run(Unknown Source) [?:1.8.0_301]```

ThreadLocalRandom.nextInt(int bound) 的文档说:

bound the upper bound (exclusive). Must be positive.

方法的第一行是:

if (bound <= 0)
    throw new IllegalArgumentException(BAD_BOUND);

虽然我会说你的 mapNames 数组是空的并且你将 0 传递给 nextInt 然后导致 IllegalArgumentException