-
-
Notifications
You must be signed in to change notification settings - Fork 37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
java.lang.NullPointerException from TileEntity#func_145838_q #95
Comments
Seems like the func_145838_q's deobfuscated name is getBlockType: EntityCulling/EntityCulling-Shared/src/main/java/dev/tr7zw/entityculling/CullTask.java Line 71 in ce0cf0c
On Line 67 a bit just above this, there is this block: EntityCulling/EntityCulling-Shared/src/main/java/dev/tr7zw/entityculling/CullTask.java Line 67 in ce0cf0c
Maybe this method call can be put inside the catch as well to ignore the exception. This of course won't prevent the exception to be created (creating stack traces is not free in terms of performance, but shouldn't be that high of a cost with JIT), but it can at least prevent the error from being printed to logs, reducing some I/O, because sometimes this error repeats itself a lot (fortunately there's a -XX:+OmitStackTraceInFastThrow setting, but it will still print catching java.lang.NullPointerException, without a stack trace, which is even more confusing, but I guess more performant.) |
Uh honestly didn't know that anyone actively uses the 1.8 version. This does seems to be an exception inside the |
I agree, was just curious if it was intented to be ignored like the other code in the catch block above. I don't have much experience in client development, my experience is mostly in server-side where there's a lot of abstractions to not have to call Minecraft code directly (you even have to use reflection to call direct Minecraft code which prevents developers from calling Minecraft code directly most of the time), so I might be wrong, but after looking at some source code, seems like either worldObj or the return value from getBlockState call in the getBlockType method is null, wouldve known what exactly is null if we could use Java 14+ somehow with -XX:+CodeDetailsInExceptionMessages, but obviously can't use anything above Java 8 in MC 1.8. Looking at getBlockState it has a check like if (!isValid(pos)) and it returns state of the AIR block, so I think it can't return null. Probably worldObj being null, maybe this method is being called before the variable initializes? Or it is some race condition, because sometimes this error never happens, sometimes it happens 1 time after startup then stops, and sometimes it repeats a lot, then it stops. After looking a bit more I noticed a method called hasWorldObj in the TileEntity class that checks if worldObj is null or not, so that suggests this variable can be null indeed. Probably have to make a change like this: if(entry.hasWorldObj() && unCullable.contains(entry.getBlockType().getUnlocalizedName())) { And if instead return of the getBlockState method is null, then probably need a check like this: if(entry.hasWorldObj() && entry.getWorld().getBlockState(entry.getPos()) != null && unCullable.contains(entry.getBlockType().getUnlocalizedName())) { Of course I don't know the code base of this mod and I didn't really check all the source code, I've only looked at the lines where stack trace pointed me to, so I don't know how adding those conditions would interfere with the mechanics of the mod, but since the current behaviour of getting an exception makes the control flow stop going after the line exception happens, and this changed version would make all the code after the if (which acts a else condition even if there's no else) I think it can introduce other issues if the change is applied by someone that doesn't really know the codebase of the mod nor has much experience in the Forge development, but I might still give this a try later on when I have time, and post the results whether this fixes the error or introduces any other issues (that is assuming I am able to build the project though, I've had bad experience trying to build forge mods from source generally, getting errors from missing dependencies like asbyth/ForgeGradle repo being deleted, and so on). |
Check out my other "small" project from when I was mostly a Spigot dev: https://github.com/tr7zw/Item-NBT-API it's all about breaking that part down, automating reflections into NMS from 1.8-1.19 for NBT.
The Stacktrace states, that the exception happens inside the method
At least last time(feb 2022), it just built using |
Yes I know you can make a common interface and implement the methods per each NMS version, then determine which implementation to use from server version in runtime, but this still hacky and repetitive coding, and it promotes adding that functionality to Bukkit/Spigot itself as an abstraction API instead of having to do this, was what I meant.
I was referring to the fact that getBlockType method calls getBlockState on worldObj, then calls getBlock on the return value of getBlockState. So there's 2 things that can NPE: worldObj being null, or getBlockState returning null. Then I said since getBlockState code should return AIR's block state if the position argument is invalid, it shouldn't return null.
Unfortunately what I predicted was correct. Tried right now and got this error (on a fresh git clone and git checkout 1.8 repo):
I've found backup GitHub repositories like https://github.com/hax0r31337/ForgeGradle, and I know I can use with JitPack, but what I don't understand is how to replace asbyth's repo with hax0r31337's one, because the build.gradle file contains no mention of asbyth, it just has a listing to depend on a plugin with id "net.minecraftforge.gradle.forge'", so I don't know where asbyth comes from. Seems like asbyth removed everything from the internet related to them (found a thread about it with a simple search: https://hypixel.net/threads/what-happened-to-asbyth.5099794/), I found the backup repo i mentioned from going to the asbyth's ForgeGradle repo in WebArchive then clicking on the Forks, then going to one of the forks that is not deleted in GitHub. |
Aaaaa this will suck. 1.8/1.12 are such horrible versions to work with even in 2021. The tooling is so dated, it just doesn't work anymore(be it modern gradle, modern java or just repos containing old but important dependencies vanishing). Last time it took me multiple days and help to get the 1.8 stuff building correctly with mixins at all. Kinda one of the reasons, I stopped backporting/updating any mods for 1.8/1.12 after the initial 3. I'll look at it at some later point when I get to 1.12/1.8 with my https://github.com/tr7zw/ModComposeTemplate project, where the build system gets generated dynamically right before the build time. |
I am not sure if this is related, but I just got a similar error which disconnected me from the server I was on: [19:35:30] [CullThread/INFO]: [STDERR]: java.lang.NullPointerException: Cannot invoke "net.minecraft.class_638.method_8497(int, int)" because "this.client.field_1687" is null
[19:35:30] [CullThread/INFO]: [STDERR]: at dev.tr7zw.entityculling.CullTask.cullBlockEntities(CullTask.java:141)
[19:35:30] [CullThread/INFO]: [STDERR]: at dev.tr7zw.entityculling.CullTask.run(CullTask.java:69)
[19:35:30] [CullThread/INFO]: [STDERR]: at java.base/java.lang.Thread.run(Thread.java:1583) This was on Fabric 1.21.1 with mod version 1.7.0 I am not sure what exactly caused this, and was unable to reproduce it unfortunately. |
This error happens randomly and sometimes repeats itself a lot before stopping happening, while playing on Hypixel (Skyblock). I don't know the actual or root cause of it because the head of the stack trace is a obfuscated vanilla function and the only clue is that EntityCulling mod calls this function.
Using OpenJDK 1.8.0_362 on Ubuntu 22.10. Minecraft 1.8.9, EntityCulling 1.5.0-1.8, Forge 11.15.1.2318 1.8.9
The text was updated successfully, but these errors were encountered: