0

Method:

    public Auction getAuction(UUID id) {
        System.out.println("count: " + auctions.size());
        if (!doesAuctionExist(id))
            return null;
        UUID owner = UUID.fromString(Main.getAuctionsFile().getConfiguration().getString("auctions."+id.toString()+".owner"));
        Bukkit.getPlayer("NoneTaken").sendMessage("owner "+owner);
        long price = Main.getAuctionsFile().getConfiguration().getLong("auctions." + id.toString() + ".price");
        boolean useTokens = Main.getAuctionsFile().getConfiguration().getBoolean("auctions." + id.toString() + ".useTokens");
        long timeCreated = Main.getAuctionsFile().getConfiguration().getLong("auctions." + id.toString() + ".timeCreated");
        ItemStack item = (ItemStack) Main.getAuctionsFile().getConfiguration().get("auctions." + id.toString() + ".item");
        Bukkit.getPlayer("NoneTaken").sendMessage("null: " + (owner == null));
        return new Auction(
                owner,
                item,
                price,
                useTokens,
                id,
                timeCreated);
    }

Constructor:

    public Auction(UUID owner, ItemStack item, long price, boolean useTokens, UUID identifier, long timeCreated) {
        this.owner = owner;
        this.item = item;
        this.price = price;
        this.useTokens = useTokens;
        this.identifier = identifier;
        this.timeCreated = timeCreated;
        Main.getAuctionManager().registerAuction(this);
    }

Error:

18.10 17:12:12 [Server] ERROR Error occurred while enabling BanditAH v1.0 (Is it up to date?)
18.10 17:12:12 [Server] INFO java.lang.NullPointerException
18.10 17:12:12 [Server] INFO at me.nonetaken.banditah.managers.Auction.<init>(Auction.java:28) ~[?:?]
18.10 17:12:12 [Server] INFO at me.nonetaken.banditah.managers.AuctionManager.getAuction(AuctionManager.java:86) ~[?:?]
18.10 17:12:12 [Server] INFO at me.nonetaken.banditah.managers.AuctionManager.<init>(AuctionManager.java:28) ~[?:?]

Line 86 in AuctionManager.java is the owner, line in the constructor in the first block of code. The message sending "null: true/false" always returns false, thus the object can't be null but an NPE is being thrown in the error on that line.

Any help is appreciated :)

NoneTaken
  • 9
  • 1
  • What is line 28 in Auction.java? – Abion47 Oct 18 '19 at 21:19
  • 1
    The last line of your `Auction` constructor is a code smell because you are letting `this` escape - see [this question](https://stackoverflow.com/questions/20474521/allowing-the-this-reference-to-escape) for an explanation. Fixing that may fix your problem. I don't think it's possible for the code posted to generate the error. Is it possible the code you are executing is not the source you have posted? Try a complete rebuild of your code. – Bohemian Oct 18 '19 at 21:25
  • Can't really follow your stack trace when we don't have the line numbers. You didn't post the whole file, so we can't even count. – Andrew Koster Oct 18 '19 at 21:28
  • Main.getAictionManager() returned null; that's the only option. – Erwin Bolwidt Oct 18 '19 at 21:30
  • You have a recursive dependency, i.e. the `AuctionManager` constructor calls the `Auction` constructor, which in turn calls `Main.getAuctionManager()`, but since the `AuctionManager` constructor hasn't returned yet, there is no manager registered with `Main`, so **`getAuctionManager()` returns null**. Fix your dependencies. – Andreas Oct 18 '19 at 21:32

2 Answers2

0

Please check this line

Main.getAuctionManager().registerAuction(this);

Main.getAuctionManager() is static method? if not then Main or return value from getAuctionManager() could be null

and if yes then return value from getAuctionManager() could be null

Please share registerAuction(), that may be throwing a NPE

Ajinkyad
  • 37
  • 5
0

Found the issue..

Turns out the constructor calling registerAuction() was the issue. It was then calling saveAuction() which overrode the file in the same location the auction was trying to be read from. Thank you Ajinkyad for that.

NoneTaken
  • 9
  • 1