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

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.



×