Sponge: Optional.get() cannot be called on an absent value.

Created on 19 May 2015  路  3Comments  路  Source: SpongePowered/Sponge

[01:38:47] [Server thread/INFO] [STDERR]: [java.lang.Throwable$WrappedPrintStream:println:-1]: java.lang.IllegalStateException: Optional.get() cannot be called on an absent value
[01:38:47] [Server thread/INFO] [STDERR]: [java.lang.Throwable$WrappedPrintStream:println:-1]:  at com.google.common.base.Absent.get(Absent.java:47)
[01:38:47] [Server thread/INFO] [STDERR]: [java.lang.Throwable$WrappedPrintStream:println:-1]:  at me.nikosgram.oglofus.sponge.OglofusHelp.execute(OglofusHelp.java:32)
[01:38:47] [Server thread/INFO] [STDERR]: [java.lang.Throwable$WrappedPrintStream:println:-1]:  at org.spongepowered.api.util.command.spec.CommandSpec.process(CommandSpec.java:330)
[01:38:47] [Server thread/INFO] [STDERR]: [java.lang.Throwable$WrappedPrintStream:println:-1]:  at org.spongepowered.api.util.command.dispatcher.SimpleDispatcher.process(SimpleDispatcher.java:342)
[01:38:47] [Server thread/INFO] [STDERR]: [java.lang.Throwable$WrappedPrintStream:println:-1]:  at org.spongepowered.api.service.command.SimpleCommandService.process(SimpleCommandService.java:231)
[01:38:47] [Server thread/INFO] [STDERR]: [java.lang.Throwable$WrappedPrintStream:println:-1]:  at net.minecraft.command.ServerCommandManager.func_71556_a(SourceFile:85)
[01:38:47] [Server thread/INFO] [STDERR]: [java.lang.Throwable$WrappedPrintStream:println:-1]:  at net.minecraft.network.NetHandlerPlayServer.func_147361_d(NetHandlerPlayServer.java:812)
[01:38:47] [Server thread/INFO] [STDERR]: [java.lang.Throwable$WrappedPrintStream:println:-1]:  at net.minecraft.network.NetHandlerPlayServer.func_147354_a(NetHandlerPlayServer.java:791)
[01:38:47] [Server thread/INFO] [STDERR]: [java.lang.Throwable$WrappedPrintStream:println:-1]:  at net.minecraft.network.play.client.C01PacketChatMessage.func_180757_a(SourceFile:37)
[01:38:47] [Server thread/INFO] [STDERR]: [java.lang.Throwable$WrappedPrintStream:println:-1]:  at net.minecraft.network.play.client.C01PacketChatMessage.func_148833_a(SourceFile:9)
[01:38:47] [Server thread/INFO] [STDERR]: [java.lang.Throwable$WrappedPrintStream:println:-1]:  at net.minecraft.network.PacketThreadUtil$1.run(SourceFile:13)
[01:38:47] [Server thread/INFO] [STDERR]: [java.lang.Throwable$WrappedPrintStream:println:-1]:  at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
[01:38:47] [Server thread/INFO] [STDERR]: [java.lang.Throwable$WrappedPrintStream:println:-1]:  at java.util.concurrent.FutureTask.run(Unknown Source)
[01:38:47] [Server thread/INFO] [STDERR]: [java.lang.Throwable$WrappedPrintStream:println:-1]:  at net.minecraftforge.fml.common.FMLCommonHandler.callFuture(FMLCommonHandler.java:709)
[01:38:47] [Server thread/INFO] [STDERR]: [java.lang.Throwable$WrappedPrintStream:println:-1]:  at net.minecraft.server.MinecraftServer.func_71190_q(MinecraftServer.java:655)
[01:38:47] [Server thread/INFO] [STDERR]: [java.lang.Throwable$WrappedPrintStream:println:-1]:  at net.minecraft.server.dedicated.DedicatedServer.func_71190_q(DedicatedServer.java:364)
[01:38:47] [Server thread/INFO] [STDERR]: [java.lang.Throwable$WrappedPrintStream:println:-1]:  at net.minecraft.server.MinecraftServer.func_71217_p(MinecraftServer.java:598)
[01:38:47] [Server thread/INFO] [STDERR]: [java.lang.Throwable$WrappedPrintStream:println:-1]:  at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:478)
[01:38:47] [Server thread/INFO] [STDERR]: [java.lang.Throwable$WrappedPrintStream:println:-1]:  at java.lang.Thread.run(Unknown Source)

Java Version: 1.8
Minecraft Version: 1.8.4
Sponge Version: 1.8-1371-2.1DEV-449
Forge Version: 1.8-11.14.1.1404-universal

My code:

@Override
public CommandResult execute( CommandSource sender, CommandContext context ) throws CommandException
{
    for ( CommandMapping mapping : plugin.getGame().getCommandDispatcher().getAll().values() )
    {
        if ( !mapping.getCallable().testPermission( sender ) )
        {
            continue;
        }
        String command = mapping.getPrimaryAlias() + " ";
        Text usage = mapping.getCallable().getUsage( sender );
        Text description = mapping.getCallable().getShortDescription( sender ).get(); //LINE 32
        sender.sendMessage( Texts.builder( command ).append( usage ).append( Texts.of( " | " ) ).append( description ).build() );
    }
    return CommandResult.success();
}
invalid

Most helpful comment

Optional.get() throws an exception when called on Absent, you are using it incorrectly.

You need to do:

if (opt.isPresent() {
  val = opt.get()
  ...
}

This is why optionals exist, to make "null checks" more explicit and needed.

All 3 comments

Optional.get() throws an exception when called on Absent, you are using it incorrectly.

You need to do:

if (opt.isPresent() {
  val = opt.get()
  ...
}

This is why optionals exist, to make "null checks" more explicit and needed.

I never understand the Optional's methods.

Was this page helpful?
0 / 5 - 0 ratings