NPE Can't seem to find the cause

Discussion in 'Plugin Development' started by Kermit_23, Jun 12, 2017.

Thread Status:
Not open for further replies.
  1. Offline

    Kermit_23

    Hello bukkit, yesterday i saw an error in the console and KPOW it was a freaking NPE! I printed out every list to see if it gets null but no luck (excuse me if i don't see the NPE)..
    Here is the error log:
    Code:
    org.bukkit.event.EventException: null
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:306) ~[spigot-1.12-R0.1-SNAPSHOT-b1307.jar:git-Spigot-87496df-ed8c725]
        at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[spigot-1.12-R0.1-SNAPSHOT-b1307.jar:git-Spigot-87496df-ed8c725]
        at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:499) [spigot-1.12-R0.1-SNAPSHOT-b1307.jar:git-Spigot-87496df-ed8c725]
        at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:484) [spigot-1.12-R0.1-SNAPSHOT-b1307.jar:git-Spigot-87496df-ed8c725]
        at net.minecraft.server.v1_12_R1.PlayerList.attemptLogin(PlayerList.java:519) [spigot-1.12-R0.1-SNAPSHOT-b1307.jar:git-Spigot-87496df-ed8c725]
        at net.minecraft.server.v1_12_R1.LoginListener.b(LoginListener.java:133) [spigot-1.12-R0.1-SNAPSHOT-b1307.jar:git-Spigot-87496df-ed8c725]
        at net.minecraft.server.v1_12_R1.LoginListener.e(LoginListener.java:57) [spigot-1.12-R0.1-SNAPSHOT-b1307.jar:git-Spigot-87496df-ed8c725]
        at net.minecraft.server.v1_12_R1.NetworkManager.a(NetworkManager.java:233) [spigot-1.12-R0.1-SNAPSHOT-b1307.jar:git-Spigot-87496df-ed8c725]
        at net.minecraft.server.v1_12_R1.ServerConnection.c(ServerConnection.java:140) [spigot-1.12-R0.1-SNAPSHOT-b1307.jar:git-Spigot-87496df-ed8c725]
        at net.minecraft.server.v1_12_R1.MinecraftServer.D(MinecraftServer.java:842) [spigot-1.12-R0.1-SNAPSHOT-b1307.jar:git-Spigot-87496df-ed8c725]
        at net.minecraft.server.v1_12_R1.DedicatedServer.D(DedicatedServer.java:405) [spigot-1.12-R0.1-SNAPSHOT-b1307.jar:git-Spigot-87496df-ed8c725]
        at net.minecraft.server.v1_12_R1.MinecraftServer.C(MinecraftServer.java:678) [spigot-1.12-R0.1-SNAPSHOT-b1307.jar:git-Spigot-87496df-ed8c725]
        at net.minecraft.server.v1_12_R1.MinecraftServer.run(MinecraftServer.java:576) [spigot-1.12-R0.1-SNAPSHOT-b1307.jar:git-Spigot-87496df-ed8c725]
        at java.lang.Thread.run(Unknown Source) [?:1.8.0_131]
    Caused by: java.lang.NullPointerException
        at ro.aname.antibot.event.ProxyEvent.onPlayerLoginEvent(ProxyEvent.java:18) ~[?:?]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_131]
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_131]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_131]
        at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_131]
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:302) ~[spigot-1.12-R0.1-SNAPSHOT-b1307.jar:git-Spigot-87496df-ed8c725]
        ... 13 more
    Here is my onEnable (where i create the 'new proxy();'):
    Code:
    this.blacklists = new HashMap<String, Object>();
    this.blacklists =
    this.config.getConfig().getConfigurationSection("Proxy.lists").getValues(false);
    this.proxy = new Proxy();
    Here is my PlayerLoginEvent class:
    Code:
            if (AntiBot.getInstance().config.getConfig().getBoolean("Proxy.enabled")) {
                if (AntiBot.getInstance().proxy.isProxy(event.getPlayer().getAddress().getAddress().getHostAddress()) // <-- NPE
                        && !player.hasPermission("antibot.skipcheck")) {
                    event.disallow(Result.KICK_OTHER, ChatColor.translateAlternateColorCodes('&',
                            AntiBot.getInstance().config.getConfig().getString("Proxy.messages.proxy-kick")));
                    AntiBot.getInstance().proxy.proxiedPlayers.add(player.getUniqueId().toString());
                }
            }
        }
    Here is my Proxy class:
    Code:
        public boolean isProxy(String address) {
            if (address.equalsIgnoreCase("127.0.0.1") || address.equalsIgnoreCase("localhost")) {
                return false;
            }
            if (AntiBot.getInstance().downloadedProxies.contains(address)) {
                return true;
            }
            for (String s : AntiBot.getInstance().blacklists.keySet()) {
                try (Scanner scanner = new Scanner(new URL(s.replace(",", ".") + address).openStream())) {
                    StringBuilder result = new StringBuilder();
                    while (scanner.hasNextLine()) {
                        result.append(scanner.nextLine()).toString();
                    }
                    String[] args = ((String) AntiBot.getInstance().blacklists.get(s)).split(",");
                    for (String arg : args) {
                        if (result.toString().contains(arg)) {
                            return true;
                        }
                    }
                } catch (MalformedURLException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
        }
     
    Last edited: Jun 12, 2017
  2. @Kermit_23
    Just find line 18, print out every single value on it and see which one it is.
     
  3. Offline

    Kermit_23

    @AlvinB Tried to print the value of it and i got the exact same NPE
     
  4. Offline

    timtower Administrator Administrator Moderator

  5. Offline

    Kermit_23

    It works fine when running a tick later, what could be the issue?
    @timtower
     
  6. Offline

    timtower Administrator Administrator Moderator

  7. Offline

    Kermit_23

    @timtower Ok, is there any way to fix this? can't we fix this using player join event?
    EDIT: It looks like i was joining using localhost thats why it bypassed me but when i try with a normal ip address i get the same error but with .lambda$0 before the (ProxyEvent.java:20)
     
    Last edited: Jun 12, 2017
  8. Offline

    Zombie_Striker

    @Kermit_23
    1. Is the proxy null? Null check this first
    2. Then, is the player null?
    3. Is their address null?
    4. After checking the first address, check if the second one is null.
    5. Is the host address returning a null value?
    6. Is the 'player' variable null?
    And remember to try printing each variable individually on separate lines. Doing this should show you the exact variable that is null.
     
  9. @Kermit_23
    Player.getAddress() isn't available when PlayerLoginEvent is fired. Just use the PlayerLoginEvent.getAddress() instead.
     
    Zombie_Striker likes this.
  10. Offline

    Kermit_23

    @Zombie_Striker
    Code:
            System.out.println("Player hoststring " + player.getAddress().getHostString());
            System.out.println("Player hostname " + player.getAddress().getHostName());
            System.out.println("Player port " + player.getAddress().getPort());
    did throw a NPE! But the instance of the player didn't! This means that the address is somehow null

    @AlvinB tried your way but i get
    Code:
    Cannot make a static reference to the non-static method getAddress() from the type PlayerLoginEvent
    in eclipse.
     
    Last edited: Jun 13, 2017
  11. @Kermit_23
    I meant on the event instance, not as a static method.
     
Thread Status:
Not open for further replies.

Share This Page