From 8c09e83b629fc1dee1807d0141eeece0424902cf Mon Sep 17 00:00:00 2001 From: marc0olo Date: Sun, 23 Aug 2026 05:20:55 +0200 Subject: [PATCH] fix: roundTo returns null for a null value instead of throwing #7 made usd values null when the token has no exchange rate. roundTo unboxes its argument, so every caller that hands it a usd value directly started throwing a NullPointerException rather than rendering nothing: java.lang.NullPointerException at BaseMapper.roundTo(BaseMapper.java:124) at BaseMapper.roundTo(BaseMapper.java:128) at NFTService.getNFTDetail(NFTService.java:662) That is a live 500 on the nft detail page, for any nft whose template has a floor listing priced in FOOBAR, RDM or EASY - the page shows "Something went wrong". Rounding an unknown value yields an unknown value, so the guard belongs here rather than at each caller: there are more than twenty of them across several repositories and every one wants the same answer. The audit behind #7 covered buildPriceInfo and stopped there. It should have covered every caller of roundTo, since making a value nullable is only safe once everything that consumes it can take a null. Refs #7 Co-Authored-By: Claude Opus 5 --- .../java/com/kryptokrauts/shared/BaseMapper.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/main/java/com/kryptokrauts/shared/BaseMapper.java b/src/main/java/com/kryptokrauts/shared/BaseMapper.java index 5edaa29..8400784 100644 --- a/src/main/java/com/kryptokrauts/shared/BaseMapper.java +++ b/src/main/java/com/kryptokrauts/shared/BaseMapper.java @@ -120,7 +120,21 @@ public static _PriceInfo buildPriceInfo( return null; } + /** + * rounding an unknown value yields an unknown value. + * + *

This used to unbox its argument and throw. That was harmless while every usd value was a + * number, but #7 made them null when no exchange rate exists for the token, and the callers that + * hand a usd value straight to this method started returning 500 instead - NFTService#getNFTDetail + * on any nft whose template has a floor listing priced in such a token, for one. + * + *

Guarding here rather than at each of the callers: there are more than twenty of them, they + * are spread over several repositories, and every one of them wants the same answer. + */ public static Double roundTo(Double value, int decimals) { + if (value == null) { + return null; + } return Math.round(value * Math.pow(10, decimals)) / Double.valueOf(Math.pow(10, decimals)); }