Skip to content
This repository has been archived by the owner on Feb 8, 2023. It is now read-only.

JSON get does not handle missing cookie #16

Closed
literakl opened this issue Jun 27, 2018 · 3 comments
Closed

JSON get does not handle missing cookie #16

literakl opened this issue Jun 27, 2018 · 3 comments

Comments

@literakl
Copy link

public synchronized String get(String name) returns null when cookie is not present. The JSON variant does not checks returned value and passes null to object mapper where NPE is thrown.

public T get(String name, Class dataType) throws CookieParseException {
String value = this.get(name);
try {
return this.mapper.readValue(value, dataType);
} catch (IOException var5) {
throw new CookieParseException(var5);
}
}

@tholu
Copy link
Contributor

tholu commented Feb 25, 2019

@literakl What do you expect if the cookie is missing? You can also wrap this with Optional.ofNullable() yourself to handle it properly.

@literakl
Copy link
Author

Please read the attached code. There is a bug because there is no null check. It should be:

String value = this.get(name);
if (value == null) return null;
try {
return this.mapper.readValue(value, dataType);
} catch (IOException var5) {
throw new CookieParseException(var5);
}

@tholu
Copy link
Contributor

tholu commented Feb 26, 2019

@literakl Sorry, I missed that. It helps when you format your code 😉 As I‘m currently fixing some stuff here, I‘ll try to fix this as well.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

No branches or pull requests

2 participants