[SPIGOT-5650] setPage(int) causes a NullPointerException although getPage() works fine. Created: 31/Mar/20  Updated: 01/Apr/20  Resolved: 31/Mar/20

Status: Resolved
Project: Spigot
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Minor
Reporter: Alexis Evelyn Assignee: Unassigned
Resolution: Fixed Votes: 0
Labels: BlockState, Lectern, Spigot, getPage()
Environment:

➜ Minecraft-Test-Server env
STY=923.minecraft
TERM=screen
TERMCAP=SC|screen|VT 100/ANSI X3.64 virtual terminal:\
:DO=\E[%dB:LE=\E[%dD:RI=\E[%dC:UP=\E[%dA:bs:bt=\E[Z:\
:cd=\E[J:ce=\E[K:cl=\E[H\E[J:cm=\E[%i%d;%dH:ct=\E[3g:\
:do=^J:nd=\E[C:pt:rc=\E8:rs=\Ec:sc=\E7:st=\EH:up=\EM:\
:le=^H:bl=^G:cr=^M:it#8:ho=\E[H:nw=\EE:ta=^I:is=\E)0:\
:li#25:co#80:am:xn:xv:LP:sr=\EM:al=\E[L:AL=\E[%dL:\
:cs=\E[%i%d;%dr:dl=\E[M:DL=\E[%dM:dc=\E[P:DC=\E[%dP:\
:im=\E[4h:ei=\E[4l:mi:IC=\E[%d@:ks=\E[?1h\E=:\
:ke=\E[?1l\E>:vi=\E[?25l:ve=\E[34h\E[?25h:vs=\E[34l:\
:ti=\E[?1049h:te=\E[?1049l:us=\E[4m:ue=\E[24m:so=\E[3m:\
:se=\E[23m:mb=\E[5m:md=\E[1m:mr=\E[7m:me=\E[m:ms:\
:Co#8:pa#64:AF=\E[3%dm:AB=\E[4%dm:op=\E[39;49m:AX:\
:vb=\Eg:G0:as=\E(0:ae=\E(B:\
:ac=\140\140aaffggjjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~..--++,,hhII00:\
:po=\E[5i:pf=\E[4i:k0=\E[10~:k1=\EOP:k2=\EOQ:k3=\EOR:\
:k4=\EOS:k5=\E[15~:k6=\E[17~:k7=\E[18~:k8=\E[19~:\
:k9=\E[20~:k;=\E[21~:F1=\E[23~:F2=\E[24~:F3=\E[1;2P:\
:F4=\E[1;2Q:F5=\E[1;2R:F6=\E[1;2S:F7=\E[15;2~:\
:F8=\E[17;2~:F9=\E[18;2~:FA=\E[19;2~:kb=^H:K2=\EOE:\
:kB=\E[Z:kF=\E[1;2B:kR=\E[1;2A:*4=\E[3;2~:*7=\E[1;2F:\
:#2=\E[1;2H:#3=\E[2;2~:#4=\E[1;2D:%c=\E[6;2~:%e=\E[5;2~:\
:%i=\E[1;2C:kh=\E[1~:@1=\E[1~:kH=\E[4~:@7=\E[4~:\
:kN=\E[6~:kP=\E[5~:kI=\E[2~:kD=\E[3~:ku=\EOA:kd=\EOB:\
:kr=\EOC:kl=\EOD:km:
WINDOW=0
SHELL=/bin/zsh
TERM_SESSION_ID=w0t0p0:EAF1D253-40B6-4FBC-991E-7D62FDD1F444
SSH_AUTH_SOCK=/private/tmp/com.apple.launchd.ceOhEVkuWq/Listeners
LC_TERMINAL_VERSION=3.3.9
DEVKITPPC=/opt/devkitpro/devkitPPC
Apple_PubSub_Socket_Render=/private/tmp/com.apple.launchd.lAJYtu1rP8/Render
COLORFGBG=7;0
ITERM_PROFILE=Default
XPC_FLAGS=0x0
LANG=en_US.UTF-8
PWD=/Users/alexis/minecraft/Minecraft-Test-Server
DEVKITPRO=/opt/devkitpro
TERM_PROGRAM_VERSION=3.3.9
TERM_PROGRAM=iTerm.app
PATH=/Users/alexis/perl5/bin:/Users/alexis/Documents/minecraft/development/graalvm/graalvm-ce/Contents/Home/bin:/Users/alexis/Godot/Android/platform-tools:/Users/alexis/bin:/usr/local/bin:/Users/alexis/perl5/bin:/Users/alexis/Documents/minecraft/development/graalvm/graalvm-ce/Contents/Home/bin:/Users/alexis/Godot/Android/platform-tools:/Users/alexis/bin:/usr/local/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/share/dotnet:~/.dotnet/tools:/Library/Frameworks/Mono.framework/Versions/Current/Commands:/Applications/Wireshark.app/Contents/MacOS:/Users/alexis/.platformio/penv/bin:/Users/alexis/scripts/:/Users/alexis/.platformio/penv/bin:/Users/alexis/scripts/
LC_TERMINAL=iTerm2
COLORTERM=truecolor
HOME=/Users/alexis
TMPDIR=/var/folders/1c/xhs3nq7x4mz5snx_qbkyghpw0000gq/T/
DEVKITARM=/opt/devkitpro/devkitARM
USER=alexis
LOGNAME=alexis
XPC_SERVICE_NAME=0
__CF_USER_TEXT_ENCODING=0x0:0:0
ITERM_SESSION_ID=w0t0p0:EAF1D253-40B6-4FBC-991E-7D62FDD1F444
SHLVL=2
OLDPWD=/Users/alexis/minecraft
JAVA_HOME=/Users/alexis/Documents/minecraft/development/graalvm/graalvm-ce/Contents/Home
ANDROID_SDK_ROOT=/usr/local/share/android-sdk
ANDROID_NDK_HOME=/usr/local/share/android-ndk
ANDROID_NDK_ROOT=/usr/local/share/android-ndk
ANDROID_HOME=/usr/local/share/android-sdk
Qt5_DIR=/usr/local/opt/qt5
ZSH=/Users/alexis/.oh-my-zsh
PAGER=less
LESS=-R
LC_CTYPE=en_US.UTF-8
LSCOLORS=Gxfxcxdxbxegedabagacad
PERL5LIB=/Users/alexis/perl5/lib/perl5:/Users/alexis/perl5/lib/perl5
PERL_LOCAL_LIB_ROOT=/Users/alexis/perl5:/Users/alexis/perl5
PERL_MB_OPT=--install_base "/Users/alexis/perl5"
PERL_MM_OPT=INSTALL_BASE=/Users/alexis/perl5
_=/usr/bin/env
➜ Minecraft-Test-Server

 


Attachments: PNG File Screen Shot 2020-03-31 at 12.06.07 PM.png     PNG File Screen Shot 2020-03-31 at 12.08.17 PM.png     PNG File image-2020-03-31-12-01-39-675.png     PNG File image-2020-03-31-12-11-29-339.png    
Version: git-Spigot-a03b1fd-95bd423 (MC: 1.15.2) (Implementing API version 1.15.2-R0.1-SNAPSHOT)
Plugin: Internet Redstone
Guidelines Read: Yes

 Description   

I originally was asking for help with this issue on: https://www.spigotmc.org/threads/attempting-lectern-setpage-int-results-in-a-nullpointerexception-getpage-works-fine.426628/

 

However, Warren1001, pointed out that this could be a Spigot bug. I tested this on the latest version of Spigot I just built with Buildtools and the exception still occurs.

 

Basically, the issue is, when using a BlockState that is an instance of org.bukkit.block.Lectern, I can use lectern.getPage() and get the current page as an integer, however, using lectern.setPage(int), I get a NullPointerException.

 

The exception looks like this on the latest version of Spigot:

 

The exception looks like this (and is colored) on the latest version of PaperSpigot:

"Screen Shot 2020-03-31 at 12.06.07 PM.png"

 

The stack trace printed with exception.printStackTrace();

 

[12:07:58 WARN]: java.lang.NullPointerException
[12:07:58 WARN]: at net.minecraft.server.v1_15_R1.TileEntity.getBlock(TileEntity.java:160)
[12:07:58 WARN]: at net.minecraft.server.v1_15_R1.TileEntityLectern.setPage(TileEntityLectern.java:200)
[12:07:58 WARN]: at org.bukkit.craftbukkit.v1_15_R1.block.CraftLectern.setPage(CraftLectern.java:27)
[12:07:58 WARN]: at me.alexisevelyn.internetredstone.utilities.LecternTracker$1.run(LecternTracker.java:215)
[12:07:58 WARN]: at org.bukkit.craftbukkit.v1_15_R1.scheduler.CraftTask.run(CraftTask.java:84)
[12:07:58 WARN]: at org.bukkit.craftbukkit.v1_15_R1.scheduler.CraftScheduler.mainThreadHeartbeat(CraftScheduler.java:452)
[12:07:58 WARN]: at net.minecraft.server.v1_15_R1.MinecraftServer.b(MinecraftServer.java:1185)
[12:07:58 WARN]: at net.minecraft.server.v1_15_R1.DedicatedServer.b(DedicatedServer.java:430)
[12:07:58 WARN]: at net.minecraft.server.v1_15_R1.MinecraftServer.a(MinecraftServer.java:1112)
[12:07:58 WARN]: at net.minecraft.server.v1_15_R1.MinecraftServer.run(MinecraftServer.java:934)
[12:07:58 WARN]: at java.base/java.lang.Thread.run(Thread.java:834)

 

Screenshot For printStackTrace();

"Screen Shot 2020-03-31 at 12.08.17 PM.png"

 

The Source Code to the Java file and method that's causing the issue can be found at: https://github.com/alexis-evelyn/InternetRedstone/blob/lectern/src/main/java/me/alexisevelyn/internetredstone/utilities/LecternTracker.java#L185-L229

 

As for the minimal reproduction project, should I create one more simplified than this? If so, I'll see how to simplify it as much as possible.

 

Edit: Here's the minimal reproduction project: https://github.com/alexis-evelyn/BugReport-5650



 Comments   
Comment by Alexis Evelyn [ 01/Apr/20 ]

Thanks! The fix works wonderfully! 

Comment by md_5 [ 31/Mar/20 ]

You can see the fix here https://hub.spigotmc.org/stash/projects/SPIGOT/repos/craftbukkit/commits/bbe3d58efc489ce7905d4334dba82426e36610b8

Comment by Alexis Evelyn [ 31/Mar/20 ]

Digging into the NMS code (While following the stack trace), it appears the NullPointerException comes from TileEntity.java/getBlock(). I don't know how you would handle that, but I would love to know so I can learn how to fix NMS issues myself too!

Generated at Tue Mar 18 21:01:41 UTC 2025 using Jira 10.3.3#10030003-sha1:d220e3fefc8dfc6d47f522d3b9a20c1455e12b7b.