I see. So actually your check above (isInfinite and isNan) are making this case impossible.
Maybe add a comment before the throw new RuntimeException(e) saying something like:

```java
  // This should only happen if we pass an invalid float value to JSONArray.put,
  // but we are already checking for that so this should actually never happen.
  throw new RuntimeException(e);
```

alternatively, you can remove that check above and return null here, which should be equivalent actually.