Jump to content
  • 0
vRouxy

Help NullPointer AITask.java L2JRoboto

Question

Quote

java.lang.NullPointerException
    at com.dev.phantomEngine.task.AITask.run(AITask.java:29)
    at com.l2jmobius.gameserver.ThreadPoolManager$RunnableWrapper.run(ThreadPoolManager.java:89)
    at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
    at java.base/java.util.concurrent.FutureTask.run(Unknown Source)
    at java.base/java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(Unknown Source)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.base/java.lang.Thread.run(Unknown Source)

What can be null here?

 

code:

package com.dev.phantomEngine.task;

import java.util.List;

import com.dev.phantomEngine.PhantomPlayer;
import com.dev.phantomEngine.PhantomPlayerManager;

public class AITask implements Runnable
{
	private final int _from;
	private int _to;
	
	public AITask(int from, int to)
	{
		_from = from;
		_to = to;
	}
	
	@Override
	public void run()
	{
		adjustPotentialIndexOutOfBounds();
		List<PhantomPlayer> fakePlayers = PhantomPlayerManager.INSTANCE.getFakePlayers().subList(_from, _to);
		try
		{
			// fakePlayers.stream().filter(x -> !x.getFakeAi().isBusyThinking()).forEach(x -> x.getFakeAi().thinkAndAct());
			for (PhantomPlayer p : fakePlayers)
			{
				if (!p.getFakeAi().isBusyThinking()) <- Here->
				{
					p.getFakeAi().thinkAndAct(); <- Here->
				}
			}
		}
		catch (Exception ex)
		{
			ex.printStackTrace();
		}
		
	}
	
	private void adjustPotentialIndexOutOfBounds()
	{
		if (_to > PhantomPlayerManager.INSTANCE.getFakePlayersCount())
		{
			_to = PhantomPlayerManager.INSTANCE.getFakePlayersCount();
		}
	}
}

print stack trace points to these lines

Edited by vRouxy

Share this post


Link to post
Share on other sites

5 answers to this question

Recommended Posts

  • 0

If i'm correct regarding line the 29 is the:

if (!p.getFakeAi().isBusyThinking())

The object P cannot be null (unless modified intentionaly). The null here is the getFakeAI(),

check that method.

 

Also from what i see u removed the lambda expression which mean you use shitty java 7. Pointless. You can download java 8 at least, add it on eclipse update libs and done

Edited by Kara`

Share this post


Link to post
Share on other sites
  • 1
getFakeAi()

  is probably out of synchronized block, or can be set null in one or another place.

 

If it can be null, than you have to put null checks everywhere.

 

If it's out of synchronized blocks, it means the time the AI is set / tested, it can be actually null.

Share this post


Link to post
Share on other sites
  • 0

 

 

 

yes, you are correct, thank you very much for your answer and no, I am not using java 7, I just removed the lambda to get a better view of the null pointer, as I am not very experienced

Share this post


Link to post
Share on other sites
  • 0
9 hours ago, StinkyMadness said:

 

qllapgB.png
Mark Zuckerberg have not programming experience?

Not really :D

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.



  • Posts

    • Grand Opening 1st of March
      19:00 UTC +2 [Europe] 
      13:00 UTC -3 [Brazil] 
      13:00 UTC -3 [Argentina] Website: http://l2flector.com/   Why you should play on our servers:         Unique custom Java platform.  Best defenses against DDOS attacks.  Protection from bots. SGuard  Game wthout wipe more than 6 months!  Comfortable game without freezes and delays.                                            

      Xp/Sp - 3000x
      Aden/Drop - 300x
      Rate Party Xp/Sp -1.5x
      OLYMPIAD
      Retail olympiad game.
      Olympiad Starts: 18:00 [+2GMT]
      Olympiad Ends: 24:00 [+2GMT]
      Hero Changes: Every Friday 14:00 [+2GMT]
      Period: 1 week


      Simple / Blessed Max Enchant (Weapon / Armor): +15 | (Jewelery): +15
      Crystal Max Enchant (Weapon / Armor): +20 | (Jewelery):+20
      Safe Enchant: +4
      Blessed: 90% | Crystal: 100%




      Mid Skill Chance: 5% | High: 10% | Top: 15%
      Max 1 active and 1 passive Augment at a time
      CASTLE SIEGE TIME
      Aden, Dion, 
      Giran, Goddard

                                                                                    Main town - Giran. Unique monsters. Unique pvp system. Unique aden balance. Unique farming areas. Unique L2Flector tattoos. Wedding system. Npc skill enchanter. Auto learn skills A grade items - free. Shops till top S grade. Full npc buffer with auto buff and scheme. 64 Buff Slots. Buff Time 3 hours. Max subclasses - 5. Free class change. Free sub class. Free nobless status. Stackable scrolls/ls/bog. No weight limit. No grade limit. Pvp/pk show on title. Top 20 pvp/pk in game. Offline trade system. Interlude retail skills. Perfect class balance. More then 18 active raid bosses. Without custom items. Server is secured with Sguard. SERVER COMMANDS .menu - Personal config. .siege - Sieges Info. .online - How many players online. .join .leave - Join or leave tvt event. .repair - Repair your char if you been stucked             Grand Opening 1st of March
      19:00 UTC +2 [Europe] 
      13:00 UTC -3 [Brazil] 
      13:00 UTC -3 [Argentina] Website: http://l2flector.com/
  • Topics

×