KatsuteDev / Mal4J

Java wrapper for the official MyAnimeList API
https://katsute.dev/product/mal4j
GNU General Public License v2.0
36 stars 4 forks source link

Various optimizations for nullity checks #362

Closed Katsute closed 1 year ago

Katsute commented 1 year ago

https://github.com/KatsuteDev/Mal4J/blob/bf3dcd641afbba5ec5c4937d20c4ffd808c3c00e/src/main/java/dev/katsute/mal4j/Json.java#L276-L299

Return null instead of throwing a NPE.

Use .valueOf rather than .parse, try catch on NFE.

https://github.com/KatsuteDev/Mal4J/blob/bf3dcd641afbba5ec5c4937d20c4ffd808c3c00e/src/main/java/dev/katsute/mal4j/Json.java#L301-L303

Return an empty JsonObject if null, this will protect against chained nulls.

https://github.com/KatsuteDev/Mal4J/blob/bf3dcd641afbba5ec5c4937d20c4ffd808c3c00e/src/main/java/dev/katsute/mal4j/Json.java#L313-L319

Return an empty array if null, this will protect against null loops.

Various as methods need to be rewritten to return null if null object.

These changes should remove the need for requireNonNull.

Katsute commented 1 year ago

@mashiro-san create a branch optimization

ghost commented 1 year ago

@Katsute I have created a new branch optimization@bf3dcd6