PokeGOAPI-Java icon indicating copy to clipboard operation
PokeGOAPI-Java copied to clipboard

NullPointerException during login

Open davidgwking opened this issue 8 years ago • 4 comments

Description:

I am receiving a NullPointerException when attempting to login. Any help would be appreciated.

Steps to reproduce:

This exception occurs when invoking login on an instance of PokemonGo. I had this very same issue a couple of weeks ago, but it appeared transient at the time.

I am using the GoogleAutoCredentialProvider.

@Bean("cred")
public CredentialProvider makeCredentialProvider(@Value("${google.username}") String u, @Value("${google.password}") String p)
		throws InvalidCredentialsException, LoginFailedException {
	return new GoogleAutoCredentialProvider(new OkHttpClient(), u, p);
}

@Bean("hash")
public HashProvider makeHashProvider(@Value("${hashkey}") String k) {
	return new PokeHashProvider(PokeHashKey.from(k), false);
}

@Autowired
@Bean("client")
public PokemonGo makePokemonGoClient(CredentialProvider cred, HashProvider hash) throws RequestFailedException {
	PokemonGo client = new PokemonGo(new OkHttpClient());
	client.login(cred, hash);
    return client;
}

Expected behavior: No exception.

Actual behavior: NullPointerException

Stacktrace (If it's a crash):

Caused by: java.lang.NullPointerException: null
	at com.pokegoapi.api.pokemon.Evolution.<init>(Evolution.java:46) ~[PokeGOAPI-library-all-0.4.1.jar:na]
	at com.pokegoapi.api.pokemon.Evolutions.addEvolution(Evolutions.java:58) ~[PokeGOAPI-library-all-0.4.1.jar:na]
	at com.pokegoapi.api.pokemon.Evolutions.addEvolution(Evolutions.java:61) ~[PokeGOAPI-library-all-0.4.1.jar:na]
	at com.pokegoapi.api.pokemon.Evolutions.addEvolution(Evolutions.java:61) ~[PokeGOAPI-library-all-0.4.1.jar:na]
	at com.pokegoapi.api.pokemon.Evolutions.<init>(Evolutions.java:45) ~[PokeGOAPI-library-all-0.4.1.jar:na]
	at com.pokegoapi.api.settings.templates.ItemTemplates.reloadTemplates(ItemTemplates.java:166) ~[PokeGOAPI-library-all-0.4.1.jar:na]
	at com.pokegoapi.api.settings.templates.ItemTemplates.<init>(ItemTemplates.java:75) ~[PokeGOAPI-library-all-0.4.1.jar:na]
	at com.pokegoapi.api.PokemonGo.login(PokemonGo.java:218) ~[PokeGOAPI-library-all-0.4.1.jar:na]
	at com.davidgwking.PgathenaApplication.makePokemonGoClient(PgathenaApplication.java:40) [main/:na]
	at com.davidgwking.PgathenaApplication$$EnhancerBySpringCGLIB$$a15d3327.CGLIB$makePokemonGoClient$2(<generated>) ~[main/:na]
	at com.davidgwking.PgathenaApplication$$EnhancerBySpringCGLIB$$a15d3327$$FastClassBySpringCGLIB$$d9506fc7.invoke(<generated>) ~[main/:na]
	at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228) ~[spring-core-4.3.8.RELEASE.jar:4.3.8.RELEASE]
	at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:358) ~[spring-context-4.3.8.RELEASE.jar:4.3.8.RELEASE]
	at com.davidgwking.PgathenaApplication$$EnhancerBySpringCGLIB$$a15d3327.makePokemonGoClient(<generated>) ~[main/:na]
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_91]
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_91]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_91]
	at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_91]
	at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:162) ~[spring-beans-4.3.8.RELEASE.jar:4.3.8.RELEASE]

Version: Development branch HEAD

davidgwking avatar May 24 '17 00:05 davidgwking

Somehow the PokemonSettings for a pokemon don't exist when populating the evolution branches. Try reset the item_templates file in your temp directory.

Gegy avatar May 24 '17 05:05 Gegy

Thank you; cleaning up those temp dirs temporarily fixes this issue.

davidgwking avatar May 24 '17 12:05 davidgwking

Seems this problem is related to the update of the item templates

Gegy avatar May 24 '17 12:05 Gegy

This exact same issue occurs for some users of BPGM on first start of the program and so far in every case where a user experienced this, the item_templates file appeared to be an incorrect (?) size. After deleting this file and having it redownloaded, the correct size appears to be 220Kb (224.900 bytes) at which point the error no longer occurred.

If the filesize is something that can be predicted or if there is another way to verify the file is valid then the solution would be to implement some form of validity check and retry if that fails.

just-Addict avatar May 25 '17 00:05 just-Addict