Jump to content
  • 0

NullPointer AITask.java L2JRoboto


vRouxy

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
Link to comment
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`
Link to comment
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.

Link to comment
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

Link to comment
Share on other sites

  • 0
On 2/10/2019 at 12:19 AM, vRouxy said:

as I am not very experienced

 

qllapgB.png
Mark Zuckerberg have not programming experience?

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...