The bug
When no key determining the text to display is present, the game shows an error message, however this error message is incomplete.
How to reproduce
Perform this command:
/tellraw @p {}
The error message is:
Invalid json:
The correct error message would be:
Invalid json: Don't know how to turn {} into a Component
The reason
The following is based on decompiled version of Minecraft 1.8 using MCP. All method and class names are the names used in the decompiled version.
The reason for this bug is that the public void processCommand(ICommandSender sender, String[] args) throws CommandException
method of the net.minecraft.command.server.CommandMessageRaw
(command /tellraw
) and the net.minecraft.command.CommandTitle
(command /title
) class display any exception that occurs when the Json string is parsed using Throwable org.apache.commons.lang3.exception.ExceptionUtils.getRootCause(Throwable throwable)
. As there are however exceptions that are not thrown by the Json parser but by the net.minecraft.util.IChatComponent.Serializer
class itself. The root cause is null
. Instead it should just print the message of the exception.
The following shows how this could by done for the net.minecraft.command.server.CommandMessageRaw
class.
public void processCommand(ICommandSender sender, String[] args) throws CommandException
{
if (args.length < 2)
{
throw new WrongUsageException("commands.tellraw.usage", new Object[0]);
}
else
{
EntityPlayerMP var3 = getPlayer(sender, args[0]);
String var4 = func_180529_a(args, 1);
try
{
IChatComponent var5 = IChatComponent.Serializer.jsonToComponent(var4);
var3.addChatMessage(ChatComponentProcessor.func_179985_a(sender, var5, var3));
}
catch (JsonParseException var7)
{
// Changed this
//Throwable var6 = ExceptionUtils.getRootCause(var7);
//throw new SyntaxErrorException("commands.tellraw.jsonException", new Object[] {var6 == null ? "" : var6.getMessage()});
throw new SyntaxErrorException("commands.tellraw.jsonException", new Object[] {var7.getMessage()});
}
}
}
Linked issues
Comments 5
That is because the key was missing quotes around it, I changed the description now, please reopen this report
Don't see a bug here. The JSON text
{}
is simply an empty container of zero bytes, so the JSON parser spits out
Invalid json:<ZERO_BYTE_LONG_STRING>
Fixed in some 1.9 snapshot.
Output now is