user12453494
user12453494

Reputation:

Why is Java saying "recource is never closed"? (FabricMC)

I'm developing a mod that uses mixins to reimplement existing methods in Minecraft. Most of these reimplemented methods start with something like the following:

PlayerEntity self = (PlayerEntity)(Object)this;

This works fine in every case EXCEPT at the top of one of the client methods (code below for reference).

public class MinecraftClientMixin {
    @SuppressWarnings("unused")
    private boolean doAttack() {
        MinecraftClient self = (MinecraftClient)(Object)this;
/* ... */

This bit gives me the warning Resource leak: 'self' is never closed. If I were to close it, it would close the object casted into it, crashing the game. In addition, the warning isn't given for any other time this is done, and in none of the other instances do I close self. Why is it given here, why only here, and how should I fix it?

Edit: I am using VSCode v1.91.1.

Upvotes: 0

Views: 142

Answers (0)

Related Questions