CommandHelper

CommandHelper

46.5k Downloads

NullPointerException with SQL Queries

LadyCailinBot opened this issue ยท 4 comments

commented

CMDHELPER-3155 - Reported by Murreey

Encountered an error in Core when running an SQL query (shown in the error);

[12:35:03 ERROR]: Uh oh! You've found an error in Core.
This is an error caused while running your code, so you may be able to find a workaround, but is ultimately an error in Core itself.
The line of code that caused the error was this:
@profile = {database: {db}, host: {host}, password: {password}, type: mysql, username: {username}}
@uuid = 'fa93a819-4b23-4c06-89ba-cc60721808ed'
query(@profile, 'SELECT * FROM PlayerStats LEFT JOIN Minigames ON PlayerStats.minigame_id = Minigames.minigame_id WHERE Minigames.name = ? AND PlayerStats.player_id = ? AND stat = \'time_min\'', 'Race_5', @uuid)
on or around D:\Server\plugins\CommandHelper\config.txt:1276.
Please report this error to the developers, and be sure to include the version numbers:
Server version: 1.12-R0.1-SNAPSHOT;
CommandHelper version: 3.3.2-SNAPSHOT.3216-;
Loaded extensions and versions:
CHHTTPd (version 0.0.2);
${project.name} (version 2.1.0);
SKCompat (version 2.1.0);
Core (version 3.3.2);
CHVirtualChests (version 1.0.5);
CHIRC (version 0.0.1);
CHWorldGuard (version 1.1.0);
CHNaughty (version 3.4.3);
CHSpigot (version 1.5.1);
Here's the stacktrace:
java.lang.NullPointerException
        at com.laytonsmith.core.functions.SQL$query.exec(SQL.java:251)
        at com.laytonsmith.core.Script.eval(Script.java:375)
        at com.laytonsmith.core.Script.eval(Script.java:344)
        at com.laytonsmith.core.Script.eval(Script.java:344)
        at com.laytonsmith.core.MethodScriptCompiler.execute(MethodScriptCompiler.java:2001)
        at com.laytonsmith.core.MethodScriptCompiler.execute(MethodScriptCompiler.java:1958)
        at com.laytonsmith.core.Script.run(Script.java:207)
        at com.laytonsmith.core.AliasCore.alias(AliasCore.java:153)
        at com.laytonsmith.commandhelper.CommandHelperListener.runAlias(CommandHelperListener.java:80)
        at com.laytonsmith.commandhelper.CommandHelperListener.onPlayerCommandPreprocess(CommandHelperListener.java:112)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:302)
        at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62)
        at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:499)
        at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:484)
        at net.minecraft.server.v1_12_R1.PlayerConnection.handleCommand(PlayerConnection.java:1377)
        at net.minecraft.server.v1_12_R1.PlayerConnection.a(PlayerConnection.java:1220)
        at net.minecraft.server.v1_12_R1.PacketPlayInChat.a(PacketPlayInChat.java:45)
        at net.minecraft.server.v1_12_R1.PacketPlayInChat.a(PacketPlayInChat.java:1)
        at net.minecraft.server.v1_12_R1.PlayerConnectionUtils$1.run(SourceFile:13)
        at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
        at java.util.concurrent.FutureTask.run(Unknown Source)
        at net.minecraft.server.v1_12_R1.SystemUtils.a(SourceFile:46)
        at net.minecraft.server.v1_12_R1.MinecraftServer.D(MinecraftServer.java:747)
        at net.minecraft.server.v1_12_R1.DedicatedServer.D(DedicatedServer.java:405)
        at net.minecraft.server.v1_12_R1.MinecraftServer.C(MinecraftServer.java:678)
        at net.minecraft.server.v1_12_R1.MinecraftServer.run(MinecraftServer.java:576)
        at java.lang.Thread.run(Unknown Source)

The query works fine when run through another method. The table has a 'datetime' column and a 'timestamp' column which are both null in most of the rows, which I believe is what's causing the issue.

commented

Comment by LadyCailin

I have pushed what I believe is a fix, can you test it out? If it works, close this issue.

Thanks for the report!

commented

Comment by PseudoKnight

This isn't my area, but why is it checking if(rs.wasNull()){ AFTER it checks the type and assigns the value.

commented

Comment by LadyCailin

Because it will be java null in all the cases (except for the case I fixed, where it would NPE), so we need to change that to mscript null. rs.wasNull is the technically correct way to check if it was null though, so we use that as the ultimate check at the end.

commented

Comment by Murreey

Works great. Thank you!